Skip to main content

Documentation Index

Fetch the complete documentation index at: https://whitebit-preview.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

Service

Kline

Last price

Market statistics

Market statistics for current day UTC

Market trades

Market depth

Book Ticker

WebSocket Connection Management

WebSocket endpoint is wss://api.whitebit.com/ws The API is based on JSON RPC of WebSocket protocol. ⚠️️ Connection Timeout ⚠️️
  • Server closes websocket connection after 60 seconds of inactivity
  • Inactivity is defined as no messages sent by the client

Maintaining Connection

To keep the websocket connection active:
  • Send periodic ping messages every 50 seconds
  • Handle potential connection closures gracefully in your application logic

Example Implementation

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

// Set up periodic ping
setInterval(() => {
  if (socket.readyState === WebSocket.OPEN) {
    socket.send(JSON.stringify({
            id: 0,
            method: "ping",
            params: [],
        }));
  }
}, 50000); // Every 50 seconds
Rate limit 1000 ws connections per minute and 200 requests per minute in one connection.
All endpoints return time in Unix-time format.

⤴️ Request message

JSON Structure of request message:
  • id - Integer. Should be unique to handle response for your request.
  • method - String. Name of request.
  • params - Array. Here you pass params for method.
🚫 WebSocket connection will be closed if invalid JSON was sent.

Types of request messages

  • Query (ping, candles_request, etc)
  • Subscription (candles_subscribe, lastprice_subscribe, etc). Repeated subscription will be cancelled for the same data type.

⤵️ Response message

JSON Structure of response message:
  • id - Integer. Id of request.
  • result - Null for failure, for success - look for responses below
  • error - Null for success, JSON Object for failure:
    • message - Detailed text
    • code - Error code
CodeMessage
1invalid argument
2internal error
3service unavailable
4method not found
5service timeout

Types of response messages

  • Query result
  • Subscription status (success/failed)
  • Update events

Examples

Example messages for request with response:

⤴️ Request

{
  "id": 0,
  "method": "ping",
  "params": []
}

⤵️ Response

{
  "id": 0,
  "result": "pong",
  "error": null
}
Example subscription:

⤴️ Request

{
  "id": 0,
  "method": "candles_subscribe",
  "params": []
}

⤵️ Response

{
  "id": 0,
  "result": {
    "status": "success"
  },
  "error": null
}

🔄 Update events

{
  "id": null,
  "method": "candles_update",
  "params": [] // look below for params
}