Public
Edited
Dec 29, 2022
Insert cell
kline5m = {
const data = []
let startTime = new Date("2022-12-01").getTime()

while (true) {
const response = await fetch(
'https://fapi.binance.com/fapi/v1/klines?symbol=BTCUSDT&interval=5m&limit=1000&startTime=' + startTime
).then((res) => res.json())

data.push(...response);

if (response.length < 1000) break;

startTime = response.at(-1)[6]
}

return data.map((v) => ({
startTime: new Date(v[0]),
open: Number(v[1]),
high: Number(v[2]),
low: Number(v[3]),
close: Number(v[4]),
volume: Number(v[5]),
endTime: new Date(v[6]),
}))
}
Insert cell
fetch(
'https://fapi.binance.com/futures/data/openInterestHist?symbol=BTCUSDT&period=5m&limit=500&startTime=' + new Date("2022-12-10").getTime()
).then((res) => res.json()).then(data => new Date(data.at(0).timestamp))
Insert cell
oi5m = {
const data = []
let startTime = new Date("2022-12-01").getTime()

while (true) {
const response = await fetch(
'https://fapi.binance.com/futures/data/openInterestHist?symbol=BTCUSDT&period=5m&limit=500&startTime=' + startTime
).then((res) => res.json())

data.push(...response);

if (response.length < 500) break;

startTime = response.at(-1).timestamp
}

return data.map((v) => ({
startTime: new Date(v.timestamp),
openInterest: Number(v.sumOpenInterest)
}))
}
Insert cell
Plot.plot({
marks: [
Plot.lineY(oi5m, {x: "startTime", y: "openInterest"}),
],
marginLeft: 50
})
Insert cell
Plot.plot({
marks: [
Plot.lineY(kline5m, {x: "startTime", y: "close"}),
Plot.ruleX(kline5m.filter(x => x.high - x.low > 100).map(x => x.startTime))
]
})
Insert cell
kline5m
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more