Created
March 9, 2021 10:58
-
-
Save earthchie/eb4cb63099e9891fa1f23395f9d6eec3 to your computer and use it in GitHub Desktop.
get Satang and Bitkub Exchange rate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function getExchangeRate(pair, start, end) { | |
return { | |
Satang: await getSatangExchangeRate(pair, start, end), | |
Bitkub: await getBitkubExchangeRate(pair, start, end) | |
} | |
} | |
async function getSatangExchangeRate(pair, start, end) { | |
start = start.getTime() - 86399999; | |
end = end.getTime() + 86400000; | |
let r = await fetch(`https://satangcorp.com/api/v3/klines?symbol=${pair.toUpperCase()}&interval=1d&startTime=${start}&endTime=${end}&limit=500`); | |
let list = await r.json(); | |
return list.map(i => { | |
return { | |
from: new Date(i[0]), | |
from_ms: i[0], | |
to: new Date(i[6]), | |
to_ms: i[6], | |
O: +i[1], | |
H: +i[2], | |
L: +i[3], | |
C: +i[4], | |
V: +i[5] | |
} | |
}); | |
} | |
async function getBitkubExchangeRate(pair, start, end) { | |
start = Math.floor(start.getTime() / 1000); | |
end = Math.floor(end.getTime() / 1000); | |
let r = await fetch(`https://tradingview.bitkub.com/tradingview/history?symbol=${pair.toUpperCase()}&resolution=1D&from=${start}&to=${end}`); | |
let list = await r.json(); | |
return list.t.map((d, i) => { | |
d = d * 1000; | |
return { | |
from: new Date(d), | |
from_ms: d, | |
to: new Date(d + 86399999), | |
to_ms: d + 86399999, | |
O: list.o[i], | |
H: list.h[i], | |
L: list.l[i], | |
C: list.c[i], | |
V: list.v[i] | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
O = Open
H = Highest
L = Lowest
C = Close
V = Volume