Skip to main content
Connect to the WhiteBIT WebSocket API for real-time streaming data. The guide targets developers building trading bots, live price feeds, or account monitoring dashboards.

Prerequisites

  • A terminal with a WebSocket client (Python websocket-client library, or wscat for 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
WhiteBIT has no public testnet or sandbox. Private channel subscriptions expose live account data. Store API credentials securely — never commit secrets to version control or expose them in shared environments. For risk-free balance-change testing, use Demo Tokens (DBTC/DUSDT) — activate from the WhiteBIT Codes page.

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.
2

Subscribe to last price updates

Subscribe to real-time price updates for BTC_USDT.
Subscribe confirmation:
Update message:
The 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 (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:
The first element in 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.
Private channels (balance updates, order updates) require authentication. First obtain a WebSocket token via the REST API, then send an authorize message.
Token endpoint: 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: 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.
The six steps above cover a single connection. Production integrations need automatic reconnection and state recovery, covered next.

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

Key points:
  • 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
For an implementation with fill monitoring, grid strategy logic, and error recovery, see Building a Trading Bot — Auto-resubscription.

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.