spot.candles stream provides the live updates.
Series parameters
Use the same three values for the history request and the subscription. Otherwise, the stream updates do not line up with the bars you drew.
1. Subscribe and load history
Subscribe first and wait for the ack before you read history, so that no update is missed between the two. See Initial snapshot.2. Update the open bar
Each stream update contains the current state of one bucket, and the open bucket is sent again each time a new trade executes. Replace the bar with the sametime, or append a new one.
Missing candles
Buckets with no trades are not sent, either in history or on the stream, so a quiet token has gaps between bars. Most charting libraries handle gaps. If yours needs a bar for every bucket, fill each gap with a flat bar at the previousclose and zero volume.
Load older history
When the user scrolls left, request the bars before the oldest bar you hold.to is exclusive, so the oldest bar is not repeated.
TradingView datafeeds
The OHLCV endpoint follows the TradingView datafeed contract. IngetBars, map periodParams.countBack to countBack and periodParams.to (seconds) to to in milliseconds. In subscribeBars, subscribe to spot.candles and pass each update to the onTick callback.
Changing series
To change the timeframe or metric, unsubscribe using thesubscriptionId from the ack, subscribe with the new values, and reload history.