diff --git a/src/libs/osmos.js b/src/libs/osmos.js index c0094085..3b19c790 100644 --- a/src/libs/osmos.js +++ b/src/libs/osmos.js @@ -3,7 +3,7 @@ * @Autor: dingyiming * @Date: 2021-11-22 21:20:10 * @LastEditors: dingyiming - * @LastEditTime: 2021-11-23 10:25:41 + * @LastEditTime: 2021-11-23 11:19:51 */ import fetch from 'node-fetch' import { getLocalChains } from './data/data' @@ -22,14 +22,15 @@ export default class OsmosAPI { async getOHCL4Pairs(from, to) { this.exe_time = '' return 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())], + [fetch(`https://api.coingecko.com/api/v3/coins/${from}/ohlc?vs_currency=usd&days=1`).then(res => res.json()), + fetch(`https://api.coingecko.com/api/v3/coins/${to}/ohlc?vs_currency=usd&days=1`).then(res => res.json())], ).then(ohlc => { + console.log(ohlc) const output = [] ohlc[0].forEach((e, i) => { const price = [e[0]] for (let j = 1; j <= 4; j += 1) { - price.push(e[j] / ohlc[1][i][j]) + price.push(e[j] / ohlc?.[1]?.[i]?.[j]) } output.push(price) }) @@ -39,9 +40,13 @@ export default class OsmosAPI { result.push({ time: itemArr[0], volume: 0, + open: itemArr[1], + high: itemArr[2], + low: itemArr[3], + close: itemArr[4], }) } - return output + return result }) } diff --git a/src/views/OsmosisTrade.vue b/src/views/OsmosisTrade.vue index 6ecf6eaf..f6c6a09e 100644 --- a/src/views/OsmosisTrade.vue +++ b/src/views/OsmosisTrade.vue @@ -129,8 +129,8 @@ export default { this.init(base, target) // 所有方法添加到 $http.osmosis this.$http.osmosis.getOHCL4Pairs( - this.$http.osmosis.getCoinGeckoId(this.base), - this.$http.osmosis.getCoinGeckoId(this.target), + this.$http.osmosis.getCoinGeckoId(base), + this.$http.osmosis.getCoinGeckoId(target), ) .then(data => { this.klineData = data diff --git a/src/views/components/kline/index.vue b/src/views/components/kline/index.vue index d09797dc..856db4c3 100644 --- a/src/views/components/kline/index.vue +++ b/src/views/components/kline/index.vue @@ -58,21 +58,21 @@ export default { }) } console.log(this.list); - store.onDataCallback(datas, { noData: !datas.length }) + store.onDataCallback(this.list, { noData: !this.list.length }) } - if (res.tick) { - const data = res.tick + // if (res.tick) { + // const data = res.tick - store.onRealTimeCallback({ - time: data.id * 1000, - volume: data.amount, - close: data.close, - open: data.open, - high: data.high, - low: data.low, - }) - } + // store.onRealTimeCallback({ + // time: data.id * 1000, + // volume: data.amount, + // close: data.close, + // open: data.open, + // high: data.high, + // low: data.low, + // }) + // } } reader.readAsArrayBuffer(e.data)