Skip to main content
A live chart needs two things: history to draw, and updates to the bar that is still open. The OHLCV endpoint supplies the history; 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 same time, 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 previous close 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:
An empty candles list means you reached the start of the token’s history.

TradingView datafeeds

The OHLCV endpoint follows the TradingView datafeed contract. In getBars, 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 the subscriptionId from the ack, subscribe with the new values, and reload history.