Data Functions
Everything your script can pull in: live ticks, minute bars, option Greeks, bid/ask and market depth, historical OHLC and tick data, the option chain, and market-wide analytics and corporate financials.
Live Market Data
TD.Feed and TD.on - subscribe to symbols and listen for ticks, 1- and 5-minute bars, option Greeks, bid/ask, market depth and heartbeats
The chart's own symbol is subscribed automatically whenever you define TD.onChartBar. To receive data for other symbols, subscribe yourself.
TD.onStart = async () => { await TD.Feed.addSymbols(["RELIANCE", "HDFCBANK", "NIFTY-I"]); }; TD.onStop = async () => { await TD.Feed.removeSymbols(["RELIANCE", "HDFCBANK", "NIFTY-I"]); };
All subscriptions are also released automatically when the script stops.
Option symbol format. Write option symbols as underlying + expiry (YYMMDD) + strike + CE/PE, for example "NIFTY26100622600CE" (NIFTY, 06-10-2026, strike 22600, call). Any other format won't match a subscription, so no events arrive.
One listener receives events for all your subscribed symbols, so always check data.symbol.
TD.on("tick", (data) => { if (data.symbol === "RELIANCE" && data.ltp > 3000) { TD.log("RELIANCE above 3000: " + data.ltp); } });
"tick" Each trade update for a subscribed symbol. Also fires when Greeks or bid/ask change for the symbol. symbol, ltp, ltq, atp, volume, open, high, low, prevClose, oi, prevOi, turnover, bid, bidQty, ask, askQty, timestamp. Options also include iv, delta, theta, gamma, vega, rho."bar1min" When a 1-minute bar completes. symbol, timestamp, open, high, low, close, volume, oi."bar5min" When a 5-minute bar completes. Same fields as "bar1min"."greeks" When an option's Greeks update. Option symbols only. symbol, iv, delta, gamma, theta, vega, rho."bidAsk" When the top of book changes (NSE and MCX). symbol, bid, bidQty, ask, askQty."bidAskL2" When the 5-level market depth changes (BSE). symbol, depth, where depth is { totalBidQty, totalAskQty, bids[], asks[] } and each level is { orders, qty, price }, best price first."heartbeat" Periodically while connected. Carries a connection status payload (timestamp).A tick can contain only the fields that changed, so check a value before using it - if (data.ltp) .... Listeners also keep the script running until you click Stop.
"tick", "greeks", "bidAsk" and "bidAskL2" can fire many times a second. Keep listeners light, and throttle any logging or drawing (for example, at most once every 5 seconds per symbol). Events only arrive for symbols you have subscribed to with TD.Feed.addSymbols. See Example 6 for a complete script using every event.
Historical Data
TD.Historical - every function returns a Promise resolving to { status, records }, or { error } on failure
const res = await TD.Historical.getLastNBars({ symbol: "RELIANCE", nbars: 5, interval: "5min" }); if (res.error) { TD.log("Failed: " + res.error); return; } console.table(res.records);
getBars { symbol, from, to, interval }getLastNBars { symbol, nbars, interval }getTicks { symbol, from, to, bidask? }getLastNTicks { symbol, nticks, bidask? }getAllBars { timestamp, segment, interval } - all symbols in a segment at one timegetTopNGainersgetTopNLosersgetTopNVolumeGainers { segment, topn }, for example { segment:"NSEEQ", topn: 10 }Dates: "2026-09-15 09:15:00" in local time. Intervals: "1min", "5min", "15min", "30min", "60min", "EOD".
TD.onStart = async () => { const res = await TD.Historical.getBars({ symbol: "TCS", from: "2026-09-15 09:15:00", to: "2026-09-15 15:30:00", interval: "15min" }); TD.log("Bars received: " + (res.records ? res.records.length : 0)); };
Option Chain
TD.OptionChain - all parameters are optional, and the chain defaults to the chart's symbol and the nearest expiry
const chain = await TD.OptionChain.getOptionChain(); // chain.resolved → { symbol:"NIFTY", expiry:"25-09-2026", exchange:"NSE" } // chain.records → array of rows (each row is an array) // chain.columns → which position in a row holds each field // chain.expiries → list of available expiries
Read record fields through columns, never by hard-coded number. Column positions differ between BSE chains and the Greeks chain, and columns already accounts for that.
const c = chain.columns; for (const row of chain.records) { TD.log(row[c.strike], "CE OI", row[c.callOI], "PE OI", row[c.putOI]); }
getOptionChain(params?) symbol (e.g. "NIFTY" or "auto"), expiry ("28-04-2026", "2026-04-28", or a number where 0 is nearest and 1 is next), exchange ("NSE", "BSE", "MCX")getOptionChainWithGreeks(params?) Same parameters as getOptionChain.getExpiryList(params?) symbol, exchange. Returns records as ["2026-09-25", ...], nearest first.symbol, expiry, strike, callLTP, callVolume, callOI, callPrevOI, callBid, callBidQty, callAsk, callAskQty, callTimestamp, putLTP, putVolume, putOI, putPrevOI, putBid, putBidQty, putAsk, putAskQty, putTimestampcallPrevClose, putPrevClose, callDelta, callTheta, callVega, callGamma, callRho, callIV, and the same six Greeks for puts (put…).// Next week's BANKNIFTY chain, whatever the chart shows const bn = await TD.OptionChain.getOptionChain({ symbol: "BANKNIFTY", expiry: 1 });
Analytics
TD.Analytics - market-wide screens
getOIGainers / getOILosers { series:"CE"|"PE"|"XX", top }getIndexGainers / getIndexLosers { indexName:"NIFTY 50", segment:"EQ"|"FUT", top }getIndustryGainers / getIndustryLosers { industry:"Healthcare", segment, top }getMostActiveByTurnover / getMostActiveByVolume { indexName, segment, top }const g = await TD.Analytics.getIndexGainers({ indexName: "NIFTY 50", segment: "EQ", top: 5 }); console.table(g.records);
Corporate Data & Market Status
TD.Corporate - per-company financials, in two steps
First find the record id with getAllResults, then fetch the statement.
const list = await TD.Corporate.getAllResults({ symbol: "TCS", nature: "consolidated", period: "quarterly", type: "pl" }); console.table(list.records); // find the id of the result you want const pnl = await TD.Corporate.getPnL({ id: "<record id>", cumulative: false }); const status = await TD.getMarketStatus();
getBalancesheet({ id, cumulative }) and getCashflow({ id, cumulative }) work the same way.
Historical, option-chain, analytics and corporate calls are one-shot requests - fetch once in TD.onStart, or on a timer of a minute or more. Never call them from inside a "tick" listener.