feat: kline data

This commit is contained in:
ding 2021-11-23 11:21:07 +08:00
parent c299a19c41
commit e2aef3912c
3 changed files with 24 additions and 19 deletions

View File

@ -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
})
}

View File

@ -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

View File

@ -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)