tradingview / charting-library-tutorial

This tutorial explains step by step how to connect your data to the Charting Library
MIT License
435 stars 317 forks source link

How to update the last bar realtime in TradingView Charting Library in real-time when first loaded? #118

Open vanhauhuynh17 opened 4 months ago

vanhauhuynh17 commented 4 months ago

0

/* Charting Library calls this function when it wants to receive real-time updates for a symbol. The Library assumes that you will call the callback provided by the onTick parameter every time you want to update the most recent bar or to add a new one. @param symbolInfo A SymbolInfo object @param resolution Resolution of the symbol @param onTick Callback function returning a Bar object @param listenerGuid @param onResetCacheNeededCallback Function to be executed when bar data has changed / subscribeBars(symbolInfo: LibrarySymbolInfo, resolution: ResolutionString, onTick: SubscribeBarsCallback, listenerGuid: string, onResetCacheNeededCallback: () => void): void; /**

I am implementing the realtime udpate bar part of tradingview's charting library. I have successfully implemented the realtime update and realized the key is that the subscribeBars function must run and save onSubscribeBarCallBack to update, the library will automatically call the subscribeBar function in datafeed api when the symbol changes. or resolution changes and will now save onSubscribeBarCallBack. This means that when entering the chart page, the library will not call the subscribeBar function, so the first time the chart is loaded, there will be no way to realtime update the last bar. I've searched and read the charting library's documentation over and over again but haven't found anything about this issue, i also try to call subscribeBars manually and not success . Can anyone help me, thank you very much.

Link document about charting librabry: (https://www.tradingview.com/charting-library-docs/latest/connecting_data/Datafeed-API/)

i want to subscribeBar is called and realtime update last bar in the first load in datafeed api