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 next, older page with the series’ cursor. Send the same parameters as the first request.hasMore is false, you have 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.
Changing series
To change the timeframe or metric, unsubscribe using the storedsubscriptionId, subscribe with the new values, and reload history.
To chart one pool instead of the token across all its pools, send pool on the history request and list the pool in the subscription’s pools filter.