No results for ""
Lifecycle Hooks
The TrueData Sheets runtime calls three hook functions on your script at well-defined moments. Define onStart and onStop as async functions on the TD namespace — the runtime discovers them by name, no registration needed.
TD.onStart Called once on StartRuns immediately when the user clicks Start. Use this to subscribe to symbols, fetch initial historical/analytics/option chain data, and write sheet headers. Always wrap the body in try/catch and check response.success before using symbollist.
TD.onStart = async () => {
try {
const response = await TD.Feed.addSymbols(["NIFTY", "RELIANCE"]);
if (!response.success) {
TD.log("Subscribe failed: " + response.message);
return;
}
await TD.Sheet.setCellRange("A1", ["Symbol", "LTP", "Change%"]);
TD.log("Script started and symbols subscribed.");
} catch (err) {
TD.log("Start error: " + err.message);
}
};
TD.onStop Called once on StopRuns when the user clicks Stop, or when the platform shuts down the script. Always remove every symbol subscribed in onStart here to prevent WebSocket memory leaks (Rule 8).
TD.onStop = async () => {
await TD.Feed.removeSymbols(["NIFTY", "RELIANCE"]);
TD.log("Subscriptions cleared. Script stopped cleanly.");
};
TD.onError Called on runtime errorCalled whenever an unhandled error is thrown inside a hook or event handler. Receives the Error object. Use it to log errors via TD.log(). If not defined, errors are silently discarded.
TD.onError = (err) => {
TD.log("[ERROR] " + err.message);
};
TD.on() registrations (top level) → onStart → live events (tick / bar1min / bar5min / bidAsk / greeks) → onStop. Events are queued and will not fire until onStart fully resolves.Empowering traders and analysts with high-performance real-time market data directly within their spreadsheets.
Resources
Support
© 2026 TrueData Market Data Services LLP. All rights reserved.