feat: kline data
This commit is contained in:
parent
c299a19c41
commit
e2aef3912c
@ -3,7 +3,7 @@
|
|||||||
* @Autor: dingyiming
|
* @Autor: dingyiming
|
||||||
* @Date: 2021-11-22 21:20:10
|
* @Date: 2021-11-22 21:20:10
|
||||||
* @LastEditors: dingyiming
|
* @LastEditors: dingyiming
|
||||||
* @LastEditTime: 2021-11-23 10:25:41
|
* @LastEditTime: 2021-11-23 11:19:51
|
||||||
*/
|
*/
|
||||||
import fetch from 'node-fetch'
|
import fetch from 'node-fetch'
|
||||||
import { getLocalChains } from './data/data'
|
import { getLocalChains } from './data/data'
|
||||||
@ -22,14 +22,15 @@ export default class OsmosAPI {
|
|||||||
async getOHCL4Pairs(from, to) {
|
async getOHCL4Pairs(from, to) {
|
||||||
this.exe_time = ''
|
this.exe_time = ''
|
||||||
return Promise.all(
|
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/${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=7`).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 => {
|
).then(ohlc => {
|
||||||
|
console.log(ohlc)
|
||||||
const output = []
|
const output = []
|
||||||
ohlc[0].forEach((e, i) => {
|
ohlc[0].forEach((e, i) => {
|
||||||
const price = [e[0]]
|
const price = [e[0]]
|
||||||
for (let j = 1; j <= 4; j += 1) {
|
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)
|
output.push(price)
|
||||||
})
|
})
|
||||||
@ -39,9 +40,13 @@ export default class OsmosAPI {
|
|||||||
result.push({
|
result.push({
|
||||||
time: itemArr[0],
|
time: itemArr[0],
|
||||||
volume: 0,
|
volume: 0,
|
||||||
|
open: itemArr[1],
|
||||||
|
high: itemArr[2],
|
||||||
|
low: itemArr[3],
|
||||||
|
close: itemArr[4],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return output
|
return result
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,8 +129,8 @@ export default {
|
|||||||
this.init(base, target)
|
this.init(base, target)
|
||||||
// 所有方法添加到 $http.osmosis
|
// 所有方法添加到 $http.osmosis
|
||||||
this.$http.osmosis.getOHCL4Pairs(
|
this.$http.osmosis.getOHCL4Pairs(
|
||||||
this.$http.osmosis.getCoinGeckoId(this.base),
|
this.$http.osmosis.getCoinGeckoId(base),
|
||||||
this.$http.osmosis.getCoinGeckoId(this.target),
|
this.$http.osmosis.getCoinGeckoId(target),
|
||||||
)
|
)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
this.klineData = data
|
this.klineData = data
|
||||||
|
@ -58,21 +58,21 @@ export default {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
console.log(this.list);
|
console.log(this.list);
|
||||||
store.onDataCallback(datas, { noData: !datas.length })
|
store.onDataCallback(this.list, { noData: !this.list.length })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res.tick) {
|
// if (res.tick) {
|
||||||
const data = res.tick
|
// const data = res.tick
|
||||||
|
|
||||||
store.onRealTimeCallback({
|
// store.onRealTimeCallback({
|
||||||
time: data.id * 1000,
|
// time: data.id * 1000,
|
||||||
volume: data.amount,
|
// volume: data.amount,
|
||||||
close: data.close,
|
// close: data.close,
|
||||||
open: data.open,
|
// open: data.open,
|
||||||
high: data.high,
|
// high: data.high,
|
||||||
low: data.low,
|
// low: data.low,
|
||||||
})
|
// })
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
reader.readAsArrayBuffer(e.data)
|
reader.readAsArrayBuffer(e.data)
|
||||||
|
Loading…
Reference in New Issue
Block a user