diff --git a/src/libs/osmos.js b/src/libs/osmos.js index 64549e15..5ba235c9 100644 --- a/src/libs/osmos.js +++ b/src/libs/osmos.js @@ -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') diff --git a/src/views/OsmosisTrade.vue b/src/views/OsmosisTrade.vue index e4706406..515da238 100644 --- a/src/views/OsmosisTrade.vue +++ b/src/views/OsmosisTrade.vue @@ -29,6 +29,15 @@ export default { Ticker, Place, }, + created() { + // 所有方法添加到 $http.osmosis + this.$http.osmosis.getOHCL4Pairs('cosmos', 'osmosis').then(data => { + console.log(data) + }) + // this.$http.osmosis.getPools().then(res => { + // this.pools = res + // }) + }, }