Skip to content

Instantly share code, notes, and snippets.

@earthchie
Created March 9, 2021 10:58
Show Gist options
  • Save earthchie/eb4cb63099e9891fa1f23395f9d6eec3 to your computer and use it in GitHub Desktop.
Save earthchie/eb4cb63099e9891fa1f23395f9d6eec3 to your computer and use it in GitHub Desktop.
get Satang and Bitkub Exchange rate
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]
}
});
}
@earthchie
Copy link
Author

earthchie commented Apr 26, 2021

sample usage

console.log(await getExchangeRate('jfin_thb', new Date('2021-01-01'), new Date()));

@earthchie
Copy link
Author

O = Open
H = Highest
L = Lowest
C = Close
V = Volume

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment