Tradovate API

Keep the Tradovate WebSocket Alive With Heartbeats

A Tradovate WebSocket isn't set-and-forget. Go quiet for a few seconds and the server cuts the line. The cure is a heartbeat, a tiny frame you send every 2.5 seconds to prove you're still listening.

Geprüft vom PickMyTrade Trading Systems Team Zuletzt aktualisiert
· 7 min read
Browser DevTools Network panel showing an open Tradovate WebSocket and the server's initial o open frame

A Tradovate WebSocket is the fast lane for quotes, fills, and DOM updates, one open connection instead of hammering the REST API for every tick. But it isn't set-and-forget. Go quiet for a few seconds and the server assumes your client wandered off, so it cuts the line. The cure is a heartbeat: a tiny frame you send every 2.5 seconds to prove you're still listening. Here's the full handshake, plus how to keep the socket up for hours without babysitting it.

How the Tradovate Socket Talks

Every message on the socket is a frame, a single prefix character followed by an array of JSON. You only need to recognize four of them:

Prefix Frame What it means
oOpenSent once, right after the socket opens. This is your cue to authorize.
hHeartbeatThe server's own keep-alive. It skips these while it's actively streaming data to you.
aArrayThe real payload: quotes, fills, and position and order events as JSON.
cCloseThe connection is shutting down, run your cleanup and reconnect logic.

Your job: react to o by authorizing, read the a frames, and keep a steady heartbeat going so the server never thinks you've gone dark.

Keep the WebSocket Alive: Step-by-Step

1

Open the Socket and Wait for the "o" Frame

Connect to the right endpoint first. The trading socket lives at wss://demo.tradovateapi.com/v1/websocket in the demo environment and wss://live.tradovateapi.com/v1/websocket for a funded account. Market data rides its own socket, wss://md.tradovateapi.com/v1/websocket for the live feed, or the md-demo host for the simulated one. The instant the connection opens, the server sends a lone o. Don't send anything before you see it.

2

Authorize the Session

As soon as that o lands, send your access token as the very first frame. The format is the request name, a request id, a blank query line, then the token as the body: authorize\n0\n\n{yourAccessToken}. A 200 back means you're authenticated and the data can start flowing. Need a token? Grab one first through Tradovate API access, and if it expires mid-session, renew it before it lapses.

3

Send a [] Heartbeat Every 2.5 Seconds

This is the whole ballgame. Every 2.5 seconds, send a frame whose text is exactly [], an empty array, nothing more. As long as those heartbeats keep landing, the server holds the socket open. Let the gap stretch and it drops you. One thing that throws people: the server stops sending its own h frames while it's actively pushing data at you. That's normal, silence from the server side is no reason to stop your own heartbeats.

4

Don't Trust setInterval in a Browser Tab

Here's the trap that bites most browser apps. Background the tab and Chrome throttles setInterval and setTimeout to save power. Your clean 2.5-second beat stretches to ten, thirty, even sixty seconds, and the socket quietly dies while you're reading email in another tab. Move the timer off the main thread: run the heartbeat inside a Web Worker, which doesn't get throttled the same way when the tab loses focus. Running the connection in a Node.js process avoids it entirely, there's no inactive tab to throttle. A lighter trick is to fire heartbeats off incoming traffic, sending one whenever more than 2.5 seconds have passed since the last, but that only holds up while data keeps flowing.

5

Detect a Dead Socket and Reconnect

Even a flawless heartbeat won't survive dropped Wi-Fi or a server restart. Listen for the socket's close event, and treat a long stretch of silence from the server as a dead line too. When either fires, reconnect and re-authorize from scratch. Back off between attempts instead of hammering, start around one second and double the wait up to a cap near a minute, so a reconnect storm doesn't trip Tradovate's rate limits while you're already down. Once you're back, resubscribe to the quotes and events you were watching; the fresh socket starts blank.

Tradovate WebSocket messages panel showing the outgoing authorize frame with an access token and a 200 responseTradovate WebSocket messages showing repeated outgoing empty-array heartbeat frames about every 2.5 secondsHeartbeat timer running inside a Web Worker so a backgrounded browser tab does not throttle itConsole log showing a closed Tradovate WebSocket reconnecting with exponential backoff and re-authorizing

The Authorize Frame and Heartbeat Frame

// First frame after the "o" open frame:
authorize
0

{yourAccessToken}

// Sent every 2.5 seconds while connected:
[]

Three Habits That Keep It Boring

Boring is the goal with a market-data feed. Keep the heartbeat on its own reliable timer, log every close code so you can tell a network blip from an auth failure, and always resubscribe after a reconnect. Get those three right and the socket will run through a full session without you thinking about it.

Automate This with PickMyTrade

Don't want to build heartbeats, workers, and reconnect logic yourself? Let PickMyTrade keep the live connection to Tradovate up while it routes your TradingView alerts straight to your account.

Skip the Heartbeat Plumbing

Let PickMyTrade keep the live connection to Tradovate up while it routes your TradingView alerts straight to your account.

Start Your Free 5-Day Trial

Frequently Asked Questions

Every 2.5 seconds. Send a frame whose text is [] on that cadence and the server keeps the connection open; let the gap grow and it closes the socket.

Nothing but an empty JSON array as text. It carries no data, its only job is to tell the server your client is still alive.

Browsers throttle setInterval and setTimeout in background tabs, so your heartbeat falls behind and the server times you out. Run the timer in a Web Worker or a Node.js process to avoid it.

This guide is for educational and informational purposes only and is not financial, investment, or trading advice. Trading futures and other leveraged products carries a substantial risk of loss and is not suitable for every investor. PickMyTrade is an independent third-party automation platform and is not affiliated with, endorsed by, or sponsored by Tradovate, Inc. "Tradovate" and all related names, logos, and trademarks are the property of their respective owners. Platform features and steps change over time, so always confirm the current process in the official Tradovate platform and documentation before acting.