Prerequisites
- A terminal with a WebSocket client (Python
websocket-clientlibrary, orwscatfor interactive testing) - For private channels: a WhiteBIT API key with Trading permission and familiarity with Authentication
- No special setup for public channels — same zero-authentication principle as the Market Data API
Connection parameters
1
Connect to the WebSocket endpoint
Establish a WebSocket connection.A successful connection produces no immediate response. The server is ready to receive subscription messages.For Go and PHP examples, see SDKs.
- Python
- wscat
2
Subscribe to last price updates
Subscribe to real-time price updates for BTC_USDT.Subscribe confirmation:Update message:The
- Python
- wscat
params array contains: market name (index 0) and last traded price (index 1). Updates arrive whenever a trade executes on the pair.3
Subscribe to orderbook depth
Subscribe to orderbook depth updates for BTC_USDT with 5 price levels.Parameters: market name, depth limit (The first element in
- Python
- wscat
1/5/10/20/30/50/100), price aggregation interval ("0" = no aggregation), and multiple subscription flag. Set the flag to true to add a subscription alongside existing depth subscriptions. Setting the flag to false unsubscribes from all active depth subscriptions. Full parameter details: Depth channel.Update message:params is a boolean: true = full snapshot, false = incremental update. For local orderbook maintenance, apply incremental updates to the initial snapshot.4
Authenticate for private channels
Steps 1–3 cover public channels (no authentication required). Steps 4–5
require an API key — see Authentication
for key creation and HMAC-SHA512 signing details.
authorize message.- Python
- wscat
POST /api/v4/profile/websocket_token (authenticated REST call).Authorization response:5
Subscribe to spot balance updates
After authentication, subscribe to real-time spot balance changes.Update message (triggered by a trade or transfer):Key fields:
- Python
- wscat
available (funds ready for trading), freeze (funds locked in open orders).6
Send a keepalive ping
The server closes the connection after 60 seconds of inactivity. Send a ping message to verify the connection is alive.Expected response:In production, send a ping every 50 seconds or less to prevent disconnection.
- Python
- wscat
Reconnection and state recovery
WebSocket connections can drop due to network issues or server maintenance. Production integrations require automatic reconnection, re-authentication, and state recovery logic.Reconnection with exponential backoff
- Exponential backoff — delays double on each failure (1s → 2s → 4s → … → 30s max) with random jitter to prevent thundering herd
- Fresh token — obtain a new WebSocket token on every reconnect; tokens may expire during long disconnections
- Full resubscription — re-subscribe to all channels after reconnecting; the server does not remember previous subscriptions
State recovery after reconnect
Different channels use different update models. The recovery strategy depends on the channel type:
For incremental-delta and event-stream channels, use a query-then-subscribe pattern:
What’s next
Market Data Overview
REST API counterpart — polling-based market data for simpler integrations.
Building a Trading Bot
Combine WebSocket data with REST order placement for automated trading.
WebSocket Channels
Full channel catalog — 10 market streams and 11 account streams with schema references.