KLineChart icon indicating copy to clipboard operation
KLineChart copied to clipboard

How to add real time price

Open mwadudjar opened this issue 4 years ago • 4 comments

I made a chart in js. I can pull the OHLC prices from my API. Now I would like to add the real-time price that gets updated every second from my API. Where and how do I add this?

EDIT: I think I can figure it out with only updating the close price every second. Will try tomorrow.

EDIT 2: how do I use the updateData function? This doesn’t work: let testData = { close: latestPrice[0][1], open: kLineDataList.sort().reverse()[0][1], high: kLineDataList.sort().reverse()[0][2], low: kLineDataList.sort().reverse()[0][3], volume: Math.ceil(+data[5]), timestamp: kLineDataList.sort().reverse()[0][0], } chart.updateData(testData)

I had to reverse the order because the data from my api goes from old to new.

mwadudjar avatar Oct 16 '21 02:10 mwadudjar

That's how it works mate, check that the timestamp is the same of the latest candle and the price has changed, and you got it ✌️

DanielMartini avatar Oct 16 '21 20:10 DanielMartini

hi!

still have the same problem, ok for the updateData my last candle change with new prices BUT when a new candle is needed i don t know how to do ?

what s the algo ?

let say i m on a 5 min timeframe, i have the timestamp of the last candle and can check if this timestamp is more than 5 minutes to create the next one ? but how ? :)

thanks

smolleyes avatar Nov 24 '21 16:11 smolleyes

Guys if you are looking to update your charts tick by tick in real time, check out my PR which do exactly that: https://github.com/liihuu/KLineChart/pull/168

Julien-R44 avatar Nov 24 '21 16:11 Julien-R44

Have a complete exemple ? 😅

smolleyes avatar Nov 26 '21 09:11 smolleyes