add fetch ohlc

This commit is contained in:
liangping 2021-11-21 09:55:55 +08:00
parent 7e29fd9c14
commit 36b424cff2
2 changed files with 41 additions and 17 deletions

View File

@ -12,6 +12,25 @@ export default class OsmosAPI {
return fetch(`${this.host}${url}`).then(res => res.json())
}
async getOHCL4Pairs(from, to) {
this.exe_time = ''
const ohlc = await Promise.all(
[fetch(`https://api.coingecko.com/api/v3/coins/${from}/ohlc?vs_currency=usd&days=7`).then(res => res.json()),
fetch(`https://api.coingecko.com/api/v3/coins/${to}/ohlc?vs_currency=usd&days=7`).then(res => res.json())],
)
const output = []
ohlc[0].forEach((e, i) => {
console.log(e, i, ohlc[1][i])
const price = [e[0]]
for (let j = 1; j <= 4; j += 1) {
price.push(e[j] / ohlc[1][i][j])
}
output.push(price)
})
return output
}
// Custom Module
async getPools() {
return this.get('/osmosis/gamm/v1beta1/pools?pagination.limit=700')

View File

@ -3,27 +3,16 @@
-------
<b-row class="match-height">
<b-col
v-for="(data,index) in pools.pools"
:key="index"
md="4"
sm="6"
>
<router-link :to="data.id">
<router-link to="">
<b-card
v-if="data"
class="earnings-card text-left"
>
<b-row>
<b-col cols="8">
<b-card-title class="mb-1 text-uppercase">
#{{ data.id }} {{ formatDenom(data.poolAssets[0].token.denom) }} - {{ formatDenom(data.poolAssets[1].token.denom) }}<small class="font-small-2"> xx</small>
</b-card-title>
<div class="font-small-2">
Height
</div>
<h5 class="mb-1">
{{ data.address || '0' }}
</h5>
x
</b-col>
</b-row>
</b-card>
@ -35,7 +24,7 @@
<script>
import {
BCard, BCardTitle, VBTooltip, BRow, BCol,
BCard, VBTooltip, BRow, BCol,
} from 'bootstrap-vue'
import { formatTokenDenom } from '@/libs/data'
@ -44,22 +33,38 @@ export default {
BRow,
BCol,
BCard,
BCardTitle,
},
directives: {
'b-tooltip': VBTooltip,
},
data() {
return {
trade_pairs: [
{
from: {
denom: 'atom',
origin_denom: 'atom',
coingecko_id: 'cosmos',
},
to: {
denom: 'osmo',
origin_denom: 'osmos',
coingecko_id: 'osmosis',
},
},
],
pools: [],
ibcDenom: {},
}
},
created() {
// $http.osmosis
this.$http.osmosis.getPools().then(res => {
this.pools = res
this.$http.osmosis.getOHCL4Pairs('cosmos', 'osmosis').then(data => {
console.log(data)
})
// this.$http.osmosis.getPools().then(res => {
// this.pools = res
// })
},
beforeDestroy() {
this.islive = false