WebSocket overview
Stream market data and send orders over a single WebSocket connection.
Connect to wss://streams.fast.onetrading.com. All channels are multiplexed over this connection: you select what you receive by sending messages, not by connecting to different URLs.
Connect
Open a WebSocket connection. No headers or query parameters are required.
Authenticate (private channels only)
Send AUTHENTICATE with your API key before subscribing to TRADING or ACCOUNT. Market data channels do not require authentication. If the token is rejected, the server replies with AUTH_ERROR or ACCOUNT_RESTRICTED and closes the connection with close code 3000.
{ "type": "AUTHENTICATE", "api_token": "eyJ..." }Subscribe
Send one SUBSCRIBE message per channel. The server confirms with SUBSCRIPTIONS and then starts streaming.
{
"type": "SUBSCRIBE",
"channels": [{ "name": "ORDER_BOOK", "instrument_codes": ["BTC_USD_P"] }]
}Subscribing again to the same channel adds instruments; it never removes any (except on MARK_PRICE, where it replaces the selection). To leave channels, send UNSUBSCRIBE with their names:
{ "type": "UNSUBSCRIBE", "channels": ["ORDER_BOOK"] }Channels
| Channel | Auth | instrument_codes | Streams |
|---|---|---|---|
ORDER_BOOK | No | Required | Book snapshot, then incremental updates |
PRICE_TICKS | No | Required | Up to 80 recent ticks, then one tick per executed trade |
BOOK_TICKER | No | Required | Current best bid and ask, then each change, per instrument |
MARK_PRICE | No | Optional | Futures mark and index prices every 5 seconds |
TRADING | Yes | Not used | Order entry, plus order, fill and margin events |
ACCOUNT | Yes | Not used | TP/SL (exotic order) lifecycle events |
Keeping an order book
Every ORDER_BOOK_SNAPSHOT and ORDER_BOOK_UPDATE carries two sequence numbers, unum_bids and unum_asks. The snapshot is always the first order book message you receive for an instrument, so you can build the book like this:
- Store the snapshot, with its
unum_bidsandunum_asks. Each level inbidsandasksis[price, amount]. - Apply an update only when its
unum_bidsandunum_asksare each exactly 1 more than the values you hold, then store the new values. - If an update skips ahead, you have missed one. Discard the book and send
SUBSCRIBEfor that instrument again: the server sends a fresh snapshot.
Connection behaviour
- Heartbeats: the server sends a
HEARTBEATevery 10 seconds and expects no reply. The connection has an idle timeout of 300 seconds, so send a native WebSocket ping on each heartbeat, and reconnect if no pong comes back. - Rate limits: order requests share one bucket per account: 600 a minute for retail accounts, 2,000 for institutional accounts and 15,360 for market makers. A request over the limit is answered with
RATE_LIMITED. - Order acknowledgements: an accepted
CREATE_ORDER,MOVE_ORDERorCANCEL_ORDERgets no direct reply. Its outcome arrives as events on theTRADINGchannel. - Errors: a message that is not valid JSON gets
INVALID_MESSAGE_FORMATand the connection is closed with code4000. A message with an unknowntypeis ignored. - Slow clients: a client that cannot keep up with the messages sent to it is disconnected with close code
1006. - Reconnecting: nothing is replayed. Authenticate and subscribe again on the new connection, and use the REST API to catch up on state.
Timestamps differ by channel
Market data and TRADING messages carry integer nanosecond timestamps. ACCOUNT messages use ISO 8601 strings. A time stamped by the WebSocket server itself, such as on SUBSCRIPTIONS and HEARTBEAT, may be up to 1 second out.