Skip to main content

Connection

WebSocket endpoint: wss://api.whitebit.com/ws The API is based on JSON RPC over the WebSocket protocol. The API returns time in Unix-time format.

Connection Timeout

  • The server closes the connection after 60 seconds of inactivity.
  • Inactivity means no messages sent by the client.
  • Send a ping message every 50 seconds to keep the connection alive.

Ping Example

const socket = new WebSocket("wss://api.whitebit.com/ws");

setInterval(() => {
  if (socket.readyState === WebSocket.OPEN) {
    socket.send(JSON.stringify({
      id: 0,
      method: "ping",
      params: [],
    }));
  }
}, 50000);

Rate Limits

Rate limit: 1000 WebSocket connections per minute and 200 requests per minute per connection.

Request Message

JSON structure of a request message:
FieldTypeDescription
idIntegerUnique identifier to match the response to the request
methodStringName of the method to call
paramsArrayParameters for the method
🚫 The connection will be closed if invalid JSON is sent.

Types of Request Messages

  • Query — one-time requests (ping, candles_request, balanceSpot_request, etc.)
  • Subscription — streaming updates (candles_subscribe, lastprice_subscribe, balanceSpot_subscribe, etc.). Repeating a subscription cancels the previous one for the same data type.

Response Message

JSON structure of a response message:
FieldTypeDescription
idIntegerID of the original request
resultObject / nullnull on failure; see channel docs for success payloads
errorObject / nullnull on success; error object on failure

Error Codes

CodeMessage
1invalid argument
2internal error
3service unavailable
4method not found
5service timeout

Types of Response Messages

  • Query result — direct response to a query request
  • Subscription status — success or failure of a subscription request
  • Update events — pushed by the server when subscribed data changes

Examples

Query — ping/pong:
// ⤴️ Request
{ "id": 0, "method": "ping", "params": [] }

// ⤵️ Response
{ "id": 0, "result": "pong", "error": null }
Subscription:
// ⤴️ Request
{ "id": 0, "method": "candles_subscribe", "params": [] }

// ⤵️ Response
{ "id": 0, "result": { "status": "success" }, "error": null }
Update event:
{ "id": null, "method": "candles_update", "params": [] }

Authentication

Private channels (Account Streams) require authorization before subscribing. After connecting, send an authorize request with API credentials to gain access to private data such as balances, orders, deals, and positions. See the Authorize channel page for the full request format, parameters, and examples.

Channels