spot.candles supplies the live updates.
Choose the series
Use the same three values for the history request and the subscription, or the stream updates will not line up with the bars you drew.
1. Subscribe, then load history
Subscribe first, and wait for the ack before you read history, so no update falls between the two.2. Update the open bar
Each stream update is the current state of one bucket. The open bucket arrives again and again as trades land. Replace the bar with the sametime, or append a new one:
Gaps are normal
A bucket with no trades is not sent, in history or on the stream. A quiet token has gaps between bars. Most charting libraries handle gaps; if yours needs a bar per 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 one you hold.to is exclusive, so the oldest bar is not repeated:
candles list means you reached the start of the token’s history.
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.
Switching series
To change timeframe or metric, unsubscribe using thesubscriptionId from the ack, subscribe with the new values, and reload history.