Public
Edited
Apr 6, 2024
1 star
Insert cell
Insert cell
Plot.plot({
marginLeft: 50,
x: {type: "time", domain: [now - messages.duration, now], label: null},
y: {type: "linear", label: "price", inset: 10},
marks: [Plot.lineY(messages, {x: "t", y: "p", curve: "step", clip: true})]
})
Insert cell
messages = {
const socket = new WebSocket("wss://ws.eodhistoricaldata.com/ws/crypto?api_token=demo");
invalidation.then(() => socket.close());
socket.addEventListener("open", () => socket.send(JSON.stringify({action: "subscribe", symbols: "BTC-USD"})));
return Generators.observe((change) => {
const messages = [];
const duration = messages.duration = 60_000;
const messaged = (event) => {
const m = JSON.parse(event.data);
const t = m.t;
if (t == null) return;
while ((t - messages[0]?.t) > duration) messages.shift();
messages.push(m);
change(messages);
};
socket.addEventListener("message", messaged);
return () => socket.removeEventListener("message", messaged);
});
}
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