Skip to main content

Stream prices and account events

This recipe uses websocat, which can send an Authorization header and shows binary frames.

1. Get a token and session​

Get a token (see Authentication) and keep both data.access_token and data.session_id:

TOKEN="3d4d16824096e9c0…"
SESSION="f6a1c2d3-…"

2. Connect​

websocat -t "wss://api.onlytradeplatform.com/ws/v1/?session_id=$SESSION" \
-H "Authorization: Bearer $TOKEN"

If your tool can't send headers, put the token in the URL instead: …/ws/v1/?session_id=$SESSION&access_token=$TOKEN.

You're automatically subscribed to your own account, so nothing else is needed to get account events. Place an order in another terminal and watch:

{"type":"position_create","session_id":"f6a1c2d3-…","payload":{"id":260610016,"symbol_id":26100001,"side":0,"volume":0.1,"open_price":1.08234,"stop_loss":1.08022,"take_profit":1.08622,"comment":"recipe-1","status":0}}
{"type":"account_Summary","session_id":"f6a1c2d3-…","payload":{"ts":1781251234567,"account_id":26100003,"balance":100000,"credit":0,"equity":99998.8,"used_margin":108.23,"free_margin":99890.57,"margin_level":92390.1,"floating_profit":-1.2,"positions":[{"id":260610016,"profit":-1.2}]}}

3. Stream prices​

Send this once:

{"type":"start_market_feed","payload":{}}

Ticks for every symbol arrive as binary frames, one CSV line each:

26100001,1.08232,1.08244,1.08301,1.08012,1.08120,1.08232,0,1781251234567,1781251234570,1781251234571

The columns are symbol_id, bid, ask, high, low, open, close, volume, ts, … — see Instruments & prices. Keep the lines whose first column is a symbol you trade.

4. Stop​

{"type":"stop_market_feed","payload":{}}

Or just close the connection. See the WebSocket reference for everything you can send and receive.