Skip to main content

WebSocket overview

The OnlyTrade WebSocket channel streams live market ticks and account events (orders, positions, deals, balance changes) — the same realtime data the trading terminal uses. REST is request/response; the WebSocket is how you stay in sync without polling.

Endpoint

wss://api.onlytradeplatform.com/ws/v1/?session_id=<session_id>

Handshake & auth

  1. Log in over REST (see Authentication) and keep the session_id from the response.
  2. Open the socket with that session_id as a query parameter. The server validates the session before upgrading the connection — an invalid or expired session is rejected.
  3. Send subscribe frames to start receiving events.

The connection is tuned for low latency (TCP_NODELAY, 1 MiB write buffer). Your permissions on the socket mirror your REST scope — a Trader session can only subscribe to its own account.

Frame format

Every frame — both directions — is a JSON object with a type and a payload:

{ "type": "account_subscribe", "payload": { "account_id": 26100003 } }
  • Client → server frames are actions (subscribe, start a feed, place/close over WS).
  • Server → client frames are events (a position opened, a tick, a balance change). See Events for the full catalogue.

Quick start

# 1. session_id comes from REST login
wscat -c "wss://api.onlytradeplatform.com/ws/v1/?session_id=<session_id>"

# 2. subscribe to your account
> { "type": "account_subscribe", "payload": { "account_id": 26100003 } }

# 3. stream live prices
> { "type": "start_market_feed", "payload": { "symbol_ids": [26100001] } }

Continue to Subscribing for every client→server action, then Events for what you receive.