Search documentation

Search every page of the Trade Wzrd docs

API

WebSockets & SSE

Realtime snapshots, ticks, copy events and trade commands over one socket - plus the SSE mirror.

wss://terminal.tradewzrd.com/ws - the same socket the web app uses. Credentials travel in the first frame (browsers cannot set WebSocket headers), which is why an API key works with no protocol change.

Handshake

json
// client{ "type": "auth", "token": "tw_live_ab12cd34_..." } // server{ "type": "auth_ok", "session_id": "b4f1c9e2-..." }

Auth must arrive within 10 seconds. Failure closes with 1008 and an error frame.

Subscriptions

json
{ "type": "subscribe", "channel": "account", "id": "<accountId>" }{ "type": "subscribe", "channel": "ticks", "account_id": "<accountId>", "symbols": ["EURUSD", "XAUUSD"] }{ "type": "subscribe", "channel": "copy" }{ "type": "subscribe", "channel": "automation" }{ "type": "subscribe", "channel": "notifications" }
ChannelScopePushes
accountaccounts:readsnapshot, update (seq-numbered)
ticksaccounts:readtick (filtered to your symbols; 20 max per key)
analyticsaccounts:readanalytics_refresh
copyrooms:readcopy_event
automationautomations:readautomation_event
notificationsaccounts:readnotification

Ownership is re-checked server-side per channel - you cannot subscribe to another user's account. Up to 50 subscriptions per socket, 50 messages/second, 5 commands/second.

Trade commands

json
{  "type": "command", "cmd_id": "c-1", "account_id": "<id>",  "action": "place_order",  "idempotency_key": "7c9e6679-7425-40de-944b-e07fc1f90ae7",  "data": { "symbol": "EURUSD", "direction": "BUY", "volume": 0.1,            "stop_loss": 1.08, "take_profit": 1.09 }}

Trade commands are deduplicated server-side on idempotency_key (falling back to cmd_id). Keep the same token when you resend, and prefer idempotency_key if your cmd_id changes per attempt.

ReplyMeaning
command_result, success: trueExecuted now
command_result, replay: trueYour original result, replayed - nothing executed twice
command_result, success: falseBroker rejected it; the token is freed, fix and retry
error IDEMPOTENCY_KEY_REUSESame token, different order - use a new token
error REQUEST_IN_PROGRESSFirst attempt still running; retry shortly

After a reconnect, resume your subscriptions but reconcile open positions before resending any trade command.

Resume and keepalive

json
{ "type": "resume", "session": "<session_id>", "seq": { "account:123": 5 } }

Sessions live 300 seconds. Resume restores subscriptions, not missed messages - re-subscribing triggers a fresh snapshot. Use REST for history. Send { "type": "ping" } to keep the socket alive; 60 seconds of silence closes it. Sockets live 12 hours, then close with 4001 RECONNECT.

Close codes

CodeReasonAction
1008Auth failures, API_DISABLED, CONNECTION_LIMITFix credentials or plan
1008KEY_REVOKED / KEY_ROTATEDDo not reconnect with the same key
4001RECONNECT (12h lifetime)Reconnect and resume
1011INTERNAL_ERRORRetry with backoff

Reconnect with exponential backoff (start 1s, cap 30s, jitter) and re-auth.

SSE mirror

For clients that cannot hold a socket:

bash
curl -N https://api.tradewzrd.com/api/v1/stream/copy \  -H "Authorization: Bearer tw_live_..."
ChannelScope
tradestrades:read
copyrooms:read
automationautomations:read
notificationsaccounts:read
  • : ping comment every 15 seconds - liveness only.
  • Max duration 5 minutes; reconnect after that.
  • No replay: history is not re-sent on reconnect. Use REST for backfill.
  • Slow consumers lose events (bounded queue) - never treat SSE as a queue.

Related