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()) 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 // Custom Module
async getPools() { async getPools() {
return this.get('/osmosis/gamm/v1beta1/pools?pagination.limit=700') return this.get('/osmosis/gamm/v1beta1/pools?pagination.limit=700')

View File

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