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
// 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
{ "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" }| Channel | Scope | Pushes |
|---|---|---|
account | accounts:read | snapshot, update (seq-numbered) |
ticks | accounts:read | tick (filtered to your symbols; 20 max per key) |
analytics | accounts:read | analytics_refresh |
copy | rooms:read | copy_event |
automation | automations:read | automation_event |
notifications | accounts:read | notification |
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
{ "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.
| Reply | Meaning |
|---|---|
command_result, success: true | Executed now |
command_result, replay: true | Your original result, replayed - nothing executed twice |
command_result, success: false | Broker rejected it; the token is freed, fix and retry |
error IDEMPOTENCY_KEY_REUSE | Same token, different order - use a new token |
error REQUEST_IN_PROGRESS | First attempt still running; retry shortly |
After a reconnect, resume your subscriptions but reconcile open positions before resending any trade command.
Resume and keepalive
{ "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
| Code | Reason | Action |
|---|---|---|
1008 | Auth failures, API_DISABLED, CONNECTION_LIMIT | Fix credentials or plan |
1008 | KEY_REVOKED / KEY_ROTATED | Do not reconnect with the same key |
4001 | RECONNECT (12h lifetime) | Reconnect and resume |
1011 | INTERNAL_ERROR | Retry with backoff |
Reconnect with exponential backoff (start 1s, cap 30s, jitter) and re-auth.
SSE mirror
For clients that cannot hold a socket:
curl -N https://api.tradewzrd.com/api/v1/stream/copy \ -H "Authorization: Bearer tw_live_..."| Channel | Scope |
|---|---|
trades | trades:read |
copy | rooms:read |
automation | automations:read |
notifications | accounts:read |
: pingcomment 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.







