Data
Live ticks & bars
Three ways to keep the chart live — pick the one that matches your source.
1. ticks — you have a price stream (most common)
ticks: (symbol, onTick) => {
const unsubscribe = myBroker.onPrice(symbol, (p) => onTick({ price: p.bid, bid: p.bid, ask: p.ask, time: p.time }));
return unsubscribe;
},Candles of every interval are built from the ticks: the current bar's high, low, close and volume update, and a new bar starts when the period rolls over (UTC; weeks start Monday). The first tick continues the last historical bar. With bid / ask the chart can show Bid and Ask lines.
2. stream — you have a live bar feed
stream: ({ symbol, interval }, onBar) => {
const ws = new WebSocket(`wss://my.api/candles/${symbol}/${interval}`);
ws.onmessage = (e) => onBar(JSON.parse(e.data)); // the forming bar, repeated as it changes
return () => ws.close();
},3. poll — no push source
createDatafeed({ symbols, history, poll: 5000 }); // newest bars re-fetched every 5 sThe chart shares one subscription per symbol between the chart, alerts, the watchlist and the trading panel, and unsubscribes when nothing needs it any more.