Skip to main content

Stream a live account feed

The WebSocket channel pushes live market ticks and account events (orders, positions, deals, balance changes). This recipe connects and subscribes using wscat.

1. Get a session

Log in (see Authentication) and keep the session_id from the response.

2. Connect

The handshake authenticates with the session_id query param:

wscat -c "wss://api.onlytradeplatform.com/ws/v1/?session_id=<session_id>"

3. Subscribe to your account

Send a JSON frame with the subscribe event type:

{ "type": "account_subscribe", "payload": { "account_id": 26100003 } }

You'll now receive events for that account. Examples you may see:

{ "type": "account_summary", "payload": { "balance": 1000547.09, "equity": 1010647.99, "floating_profit": 0.90, "used_margin": 9.0, "margin_level": 11229422.11 } }
{ "type": "position_create", "payload": { "id": 260610016, "symbol_id": 26100001, "side": 0, "volume": 0.1, "open_price": 1.08234 } }
{ "type": "deal_create", "payload": { "id": 260610016, "direction": 1, "profit": 6.58, "close_price": 1.06721 } }

4. Stream live prices

To receive market ticks, start the market feed for the symbols you care about:

{ "type": "start_market_feed", "payload": { "symbol_ids": [26100001, 26100002] } }

Ticks arrive as market_feed frames with bid/ask/high/low.

5. Unsubscribe / stop

{ "type": "stop_market_feed", "payload": { "symbol_ids": [26100001] } }
{ "type": "account_unsubscribe", "payload": { "account_id": 26100003 } }

See WebSocket → Events for the full catalogue of event types and payload shapes.