Skip to content

Instantly share code, notes, and snippets.

@leeoniya
Last active May 11, 2020 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leeoniya/e24543c48199ee79221d2a98b857e2ba to your computer and use it in GitHub Desktop.
Save leeoniya/e24543c48199ee79221d2a98b857e2ba to your computer and use it in GitHub Desktop.
let u;
const ws = new WebSocket("ws://127.0.0.1:6789/");
ws.onmessage = function(event) {
const data = JSON.parse(event.data);
switch (data.type) {
case 'ohlc':
let ohlc = [data.ts, data.o, data.h, data.l, data.c];
if (u == null)
u = new uPlot(opts, ohlc, document.body);
else
u.setData(ohlc);
break;
case 'askbid':
break;
default:
console.error("unsupported event", data);
}
};
@pannet1
Copy link

pannet1 commented May 11, 2020

got even closer now. i prefer this scheme because i would not know the range of y scale before hand.

as a result of the above i am getting the following plot
edit:
image

when i checked the console, i get these errors / warnings. first i thought this is some rendering issue. i realised late that i am using a flat data for ohlc and not a realistic one. thats why i did not get a proper image.

image

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