From 36b424cff234f36c779b41fdd9d5943fddd874b8 Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Sun, 21 Nov 2021 09:55:55 +0800 Subject: [PATCH] add fetch ohlc --- src/libs/osmos.js | 19 +++++++++++++++++++ src/views/OsmosisTrade.vue | 39 +++++++++++++++++++++----------------- 2 files changed, 41 insertions(+), 17 deletions(-) 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 b48032e3..deef01d4 100644 --- a/src/views/OsmosisTrade.vue +++ b/src/views/OsmosisTrade.vue @@ -3,27 +3,16 @@ ------- - + - - #{{ data.id }} {{ formatDenom(data.poolAssets[0].token.denom) }} - {{ formatDenom(data.poolAssets[1].token.denom) }} xx - -
- Height -
-
- {{ data.address || '0' }} -
+ x
@@ -35,7 +24,7 @@