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

# 【Public】Orderbook Channel

Get orderbook data. Two channels are available: `orderbookupdate` pushes incremental updates, `orderbook10` pushes a 10-level snapshot.

### Pushing Rules

1. No user login required
2. `orderbookupdate`: incremental updates, RPI orders are not included. `orderbookupdaterpi`: incremental updates including both non-RPI and RPI orders
3. `orderbook10`: a 10-level snapshot pushed every 200ms

## Orderbook Update

### Request

> Request

```json theme={null}
{
  "id": "1",
  "cmd": "SUBSCRIBE",
  "params": ["orderbookupdate@PERP_BTC_USDT@50"]
}
```

Topic Format:

`orderbookupdate@<symbol>@<depth>`

* symbol: Trading pair, such as `PERP_BTC_USDT`
* depth: Depth level, support `50`, `200` or `500`

| Depth | Push Interval |
| :- | :- |
| 50 | 50ms |
| 200 | 100ms |
| 500 | 200ms |

### Response

> Response

```json theme={null}
{
  "topic": "orderbookupdate@PERP_BTC_USDT@50",
  "ts": 1618826337580,
  "data": {
    "s": "PERP_BTC_USDT",
    "prevTs": 1618826337380,
    "asks": [
      ["65002.15", "3.92864"],
      ["65002.80", "0"]
    ],
    "bids": [
      ["65001.20", "1.03895025"],
      ["65000.60", "1.0807"]
    ],
    "ts": 1618826337570
  }
}
```

Return data description:

| Field | Type | Description |
| :- | :- | :- |
| s | String | Symbol |
| prevTs | Long | Orderbook generation time of the previously sent message, used to check continuity |
| asks | List | Changed ask levels, each item is `[price, quantity]` |
| bids | List | Changed bid levels, each item is `[price, quantity]` |
| ts | Long | Matching engine generation time (in millisecond) |

The quantity is the absolute quantity at that price. A quantity of `0` means the price level is removed.

### How to correctly maintain a copy of OrderBook locally:

1. Subscribe to `orderbookupdate@<symbol>@<depth>` and buffer the messages received
2. Request the snapshot via REST `GET /v3/public/orderbook?symbol=<symbol>&maxLevel=<depth>`
3. Start processing the buffered messages whose `prevTs` equals the timestamp of the snapshot
4. For each newly processed message, check that its `prevTs` equals the `ts` of the previous message. If not, a message was missed, request the snapshot again and rebuild
5. If a price level has quantity `0`, delete that price level
6. If a price level does not exist, insert it with the quantity
7. If a price level already exists, update it with the new quantity

***

## Orderbook 10

### Request

> Request

```json theme={null}
{
  "id": "1",
  "cmd": "SUBSCRIBE",
  "params": ["orderbook10@PERP_BTC_USDT"]
}
```

Topic Format:

`orderbook10@<symbol>`

* symbol: Trading pair, such as `PERP_BTC_USDT`

### Response

> Response

```json theme={null}
{
  "topic": "orderbook10@PERP_BTC_USDT",
  "ts": 1618826337580,
  "data": {
    "s": "PERP_BTC_USDT",
    "bids": [
      ["65001.36", "731.000"]
    ],
    "asks": [
      ["65002.44", "230.000"]
    ],
    "ts": 1618826337570
  }
}
```

Return data description:

| Field | Type | Description |
| :- | :- | :- |
| s | String | Symbol |
| bids | List | 10 bid levels, each item is `[price, quantity]` |
| asks | List | 10 ask levels, each item is `[price, quantity]` |
| ts | Long | Matching engine generation time (in millisecond) |

Each push is the full 10 levels.

***

## Orderbook Update (RPI)

Subscribe to the delta updates of the order book with both non-RPI and RPI orders.

### Request

> Request

```json theme={null}
{
  "id": "1",
  "cmd": "SUBSCRIBE",
  "params": ["orderbookupdaterpi@PERP_BTC_USDT@50"]
}
```

Topic Format:

`orderbookupdaterpi@<symbol>@<depth>`

* symbol: Trading pair, such as `PERP_BTC_USDT`
* depth: Depth level, support `50`, `200` or `500`. The push interval is the same as `orderbookupdate`

### Response

The response format is the same as `orderbookupdate`, with `topic` being `orderbookupdaterpi@PERP_BTC_USDT@50`.

### How to correctly maintain a copy of OrderBook locally:

When using both the orderbook snapshot and the orderbook update streams, ensure both include RPI or both exclude it. Mixing them may result in inconsistent or incorrect order book states.

1. Subscribe to `orderbookupdaterpi@<symbol>@<depth>` and buffer the messages received
2. Request the snapshot via REST `GET /v3/public/orderbook?symbol=<symbol>&maxLevel=<depth>&rpi=true`
3. Follow steps 3 to 7 of the `orderbookupdate` procedure above


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