> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hotstuff.trade/llms.txt
> Use this file to discover all available pages before exploring further.

# bbo

Subscribe to real-time best bid and offer (BBO) data showing top-of-book prices and sizes.

## Example Request

```json theme={null}
{
  "jsonrpc": "2.0",
  "id": "1",
  "method": "subscribe",
  "params": {
    "channel": "bbo",
    "symbol": "BTC-PERP" // support "all"
  }
}
```

## Example Response

```json theme={null}
{
  "jsonrpc": "2.0",
  "method": "event",
  "params": {
    "channel": "bbo:BTC-PERP",
    "data": {
      "symbol": "BTC-PERP",
      "best_bid_price": 67738,
      "best_ask_price": 67741,
      "best_bid_size": 0.00273,
      "best_ask_size": 0.01499
    }
  }
}
```

## WebSocket Client Examples

### Python

```python theme={null}
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": "bbo",
            "symbol": "BTC-PERP"  # or "all"
        }
    }
    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

```javascript theme={null}
const ws = new WebSocket("wss://api.hotstuff.trade/ws");

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

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


## AsyncAPI

````yaml asyncapi/ws-subscriptions.json bbo
id: bbo
title: Bbo
description: ''
servers:
  - id: production
    protocol: wss
    host: api.hotstuff.trade/ws
    bindings: []
    variables: []
address: /
parameters: []
bindings: []
operations:
  - &ref_9
    id: bbo_sendSubscribe
    title: Bbo_send subscribe
    type: receive
    messages:
      - &ref_11
        id: a_subscribeRequest
        contentType: application/json
        payload:
          - name: Subscription request
            description: Send subscribe/unsubscribe request
            type: object
            properties:
              - name: jsonrpc
                type: string
                description: JSON-RPC version
                examples: &ref_0
                  - '2.0'
                required: true
              - name: id
                type: integer
                description: Client request identifier
                examples: &ref_1
                  - 1
                required: true
              - name: method
                type: string
                description: Subscription action
                enumValues:
                  - subscribe
                  - unsubscribe
                examples: &ref_2
                  - subscribe
                required: true
              - name: params
                type: object
                description: Channel subscription parameters
                required: true
                properties:
                  - name: channel
                    type: string
                    description: Must be `bbo`
                    examples: &ref_3
                      - bbo
                    required: true
                  - name: symbol
                    type: string
                    description: Must be `all` or a valid trading symbol (e.g. `BTC-PERP`)
                    examples: &ref_4
                      - all
                      - BTC-PERP
                    required: true
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            jsonrpc:
              type: string
              default: '2.0'
              examples: *ref_0
              description: JSON-RPC version
              x-parser-schema-id: <anonymous-schema-71>
            id:
              type: integer
              default: 1
              examples: *ref_1
              description: Client request identifier
              x-parser-schema-id: <anonymous-schema-72>
            method:
              type: string
              enum:
                - subscribe
                - unsubscribe
              default: subscribe
              examples: *ref_2
              description: Subscription action
              x-parser-schema-id: <anonymous-schema-73>
            params:
              type: object
              properties:
                channel:
                  type: string
                  description: Must be `bbo`
                  default: bbo
                  examples: *ref_3
                  x-parser-schema-id: <anonymous-schema-75>
                symbol:
                  type: string
                  description: Must be `all` or a valid trading symbol (e.g. `BTC-PERP`)
                  default: all
                  examples: *ref_4
                  x-parser-schema-id: <anonymous-schema-76>
              required:
                - channel
                - symbol
              description: Channel subscription parameters
              x-parser-schema-id: <anonymous-schema-74>
          required:
            - jsonrpc
            - id
            - method
            - params
          x-parser-schema-id: <anonymous-schema-70>
        title: Subscription request
        description: Send subscribe/unsubscribe request
        example: |-
          {
            "jsonrpc": "2.0",
            "id": 1,
            "method": "subscribe",
            "params": {
              "channel": "bbo",
              "symbol": "BTC-PERP"
            }
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: a_subscribeRequest
    bindings: []
    extensions: &ref_8
      - id: x-parser-unique-object-id
        value: bbo
  - &ref_10
    id: bbo_receiveEvent
    title: Bbo_receive event
    type: send
    messages:
      - &ref_12
        id: event
        contentType: application/json
        payload:
          - name: BBO channel event
            description: Server-pushed JSON-RPC event
            type: object
            properties:
              - name: jsonrpc
                type: string
                description: JSON-RPC version
                examples: &ref_5
                  - '2.0'
                required: false
              - name: method
                type: string
                description: '`event`'
                examples: &ref_6
                  - event
                required: false
              - name: params
                type: object
                required: false
                properties:
                  - name: channel
                    type: string
                    description: >-
                      returns `bbo:all` when subscribed to all symbols, or
                      `bbo:<symbol>` when subscribed to a specific symbol
                    examples: &ref_7
                      - bbo:all
                      - bbo:BTC-PERP
                    required: false
                  - name: data
                    type: object
                    required: false
                    properties:
                      - name: symbol
                        type: string
                        required: true
                      - name: best_bid_price
                        type: number
                        required: true
                      - name: best_ask_price
                        type: number
                        required: true
                      - name: best_bid_size
                        type: number
                        required: true
                      - name: best_ask_size
                        type: number
                        required: true
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            jsonrpc:
              type: string
              default: '2.0'
              examples: *ref_5
              description: JSON-RPC version
              x-parser-schema-id: <anonymous-schema-78>
            method:
              type: string
              default: event
              examples: *ref_6
              description: '`event`'
              x-parser-schema-id: <anonymous-schema-79>
            params:
              type: object
              properties:
                channel:
                  type: string
                  description: >-
                    returns `bbo:all` when subscribed to all symbols, or
                    `bbo:<symbol>` when subscribed to a specific symbol
                  examples: *ref_7
                  x-parser-schema-id: <anonymous-schema-81>
                data:
                  type: object
                  properties:
                    symbol:
                      type: string
                      x-parser-schema-id: <anonymous-schema-83>
                    best_bid_price:
                      type: number
                      x-parser-schema-id: <anonymous-schema-84>
                    best_ask_price:
                      type: number
                      x-parser-schema-id: <anonymous-schema-85>
                    best_bid_size:
                      type: number
                      x-parser-schema-id: <anonymous-schema-86>
                    best_ask_size:
                      type: number
                      x-parser-schema-id: <anonymous-schema-87>
                  required:
                    - symbol
                    - best_bid_price
                    - best_ask_price
                    - best_bid_size
                    - best_ask_size
                  x-parser-schema-id: <anonymous-schema-82>
              x-parser-schema-id: <anonymous-schema-80>
          x-parser-schema-id: <anonymous-schema-77>
        title: BBO channel event
        description: Server-pushed JSON-RPC event
        example: |-
          {
            "jsonrpc": "2.0",
            "method": "event",
            "params": {
              "channel": "bbo:BTC-PERP",
              "data": {
                "symbol": "BTC-PERP",
                "best_bid_price": 67738,
                "best_ask_price": 67741,
                "best_bid_size": 0.00273,
                "best_ask_size": 0.01499
              }
            }
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: event
    bindings: []
    extensions: *ref_8
sendOperations:
  - *ref_9
receiveOperations:
  - *ref_10
sendMessages:
  - *ref_11
receiveMessages:
  - *ref_12
extensions:
  - id: x-parser-unique-object-id
    value: bbo
securitySchemes: []

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.