Skip to main content
Subscribe to real-time order book depth updates with bid/ask levels and quantities for trading instruments. WebSocket URL: wss://api.hotstuff.trade/ws Channel: orderbook

Parameters

ParameterTypeRequiredDescriptionExample
jsonrpcstringYesJSON-RPC version"2.0"
idstringYesRequest identifier for tracking"1"
methodstringYesAction to perform"subscribe" or "unsubscribe"
channelstringYesChannel name"orderbook"
symbolstringYesTrading symbol"BTC-PERP", "ETH-PERP"

Supported Methods

  • subscribe - Subscribe to orderbook updates
  • unsubscribe - Unsubscribe from orderbook updates

Example Request

{
  "jsonrpc": "2.0",
  "id": "1",
  "method": "subscribe",
  "params": {
    "channel": "orderbook",
    "symbol": "BTC-PERP"
  }
}

Example Response

The first event received after subscribing is a snapshot of the complete orderbook. Subsequent events are delta updates that modify the orderbook state.

Snapshot (First Event)

{
    "jsonrpc": "2.0",
    "method": "event",
    "params": {
        "channel": "orderbook:BTC-PERP",
        "data": {
            "update_type": "snapshot",
            "books": {
                "instrument_name": "BTC-PERP",
                "bids": [
                    {
                        "price": 63874,
                        "size": 0.0003
                    }
                ],
                "asks": [
                    {
                        "price": 62761,
                        "size": 0.05
                    }
                ],
                "sequence_number": 11414520,
                "timestamp": 1770859215981
            }
        }
    }
}

Delta Updates (Subsequent Events)

After the initial snapshot, subsequent events contain delta updates with "update_type": "delta" that modify the orderbook state. Apply these deltas to maintain an up-to-date orderbook.

WebSocket Client Examples

Python

import websocket
import json

def on_message(ws, message):
    print(f"Received: {message}")

def on_open(ws):
    subscribe_msg = {
        "jsonrpc": "2.0",
        "id": "1",
        "method": "subscribe",
        "params": {
            "channel": "orderbook",
            "symbol": "BTC-PERP"
        }
    }
    ws.send(json.dumps(subscribe_msg))

ws = websocket.WebSocketApp("wss://api.hotstuff.trade/ws",
                          on_message=on_message,
                          on_open=on_open)
ws.run_forever()

JavaScript

const ws = new WebSocket('wss://api.hotstuff.trade/ws');

ws.onopen = function() {
    const subscribeMsg = {
        "jsonrpc": "2.0",
        "id": "1",
        "method": "subscribe",
        "params": {
            "channel": "orderbook",
            "symbol": "BTC-PERP"
        }
    };
    ws.send(JSON.stringify(subscribeMsg));
};

ws.onmessage = function(event) {
    console.log('Received:', event.data);
};