Skip to Content

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

ChannelAuthinstrument_codesStreams
ORDER_BOOKNoRequiredBook snapshot, then incremental updates
PRICE_TICKSNoRequiredUp to 80 recent ticks, then one tick per executed trade
BOOK_TICKERNoRequiredCurrent best bid and ask, then each change, per instrument
MARK_PRICENoOptionalFutures mark and index prices every 5 seconds
TRADINGYesNot usedOrder entry, plus order, fill and margin events
ACCOUNTYesNot usedTP/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:

  1. Store the snapshot, with its unum_bids and unum_asks. Each level in bids and asks is [price, amount].
  2. Apply an update only when its unum_bids and unum_asks are each exactly 1 more than the values you hold, then store the new values.
  3. If an update skips ahead, you have missed one. Discard the book and send SUBSCRIBE for that instrument again: the server sends a fresh snapshot.

Connection behaviour

  • Heartbeats: the server sends a HEARTBEAT every 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_ORDER or CANCEL_ORDER gets no direct reply. Its outcome arrives as events on the TRADING channel.
  • Errors: a message that is not valid JSON gets INVALID_MESSAGE_FORMAT and the connection is closed with code 4000. A message with an unknown type is 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.

On this page