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

# Order Book

> Stream CLOB order book snapshots.

<Note>
  **Room ID:** `polymarket_order_book` \
  **Endpoint:** `wss://api.struct.to/ws` \
  **Rate:** 0.001 credits per message
</Note>

Stream CLOB order book snapshots for specific markets or outcome positions. At least one filter is required. The combined total of `condition_ids` and `position_ids` must not exceed 500.

## Subscribe

At least one of `condition_ids` or `position_ids` is required. Without any filters, the room will not emit events. You can combine both filters to narrow the stream.

### Filters

| Filter          | Type       | Required | Description                                                                                                                              |
| --------------- | ---------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `condition_ids` | `string[]` | No       | Markets to stream order books for                                                                                                        |
| `position_ids`  | `string[]` | No       | Outcome token IDs to stream order books for                                                                                              |
| `subscribe_all` | `boolean`  | No       | Firehose: receive every market's snapshots, delivered as conflated `order_book_batch` envelopes every 50ms. Filters are ignored when set |

### Example

```json theme={null}
{
  "type": "join_room",
  "payload": {
    "room_id": "polymarket_order_book"
  }
}
```

```json theme={null}
{
  "type": "room_message",
  "payload": {
    "room_id": "polymarket_order_book",
    "message": {
      "action": "subscribe",
      "condition_ids": ["0xabc123..."]
    }
  }
}
```

### Response

```json theme={null}
{
  "type": "order_book_stream_subscribe_response",
  "room_id": "polymarket_order_book",
  "data": {
    "condition_ids": ["0xabc123..."],
    "position_ids": [],
    "rejected": []
  }
}
```

## Events

### `order_book_update`

```json theme={null}
{
  "type": "order_book_update",
  "room_id": "polymarket_order_book",
  "data": {
    "asset_id": "12345678901234567",
    "market": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
    "bids": [{ "p": "0.60", "s": "500" }, { "p": "0.59", "s": "1200" }, { "p": "0.58", "s": "3000" }],
    "asks": [{ "p": "0.61", "s": "800" }, { "p": "0.62", "s": "1500" }, { "p": "0.63", "s": "2500" }],
    "timestamp": 1743500000000,
    "hash": "abc123def456",
    "best_bid": 0.60,
    "best_ask": 0.61,
    "mid_price": 0.605,
    "spread": 0.01,
    "bid_liquidity_usd": 4500.0,
    "ask_liquidity_usd": 5200.0,
    "bid_levels": 3,
    "ask_levels": 3
  }
}
```

Each entry in `bids` and `asks` is a price level object:

| Field | Type     | Description                         |
| ----- | -------- | ----------------------------------- |
| `p`   | `string` | Price (0–1), as a decimal string    |
| `s`   | `string` | Size in shares, as a decimal string |

`bids` are sorted best-first (highest price first); `asks` are sorted best-first (lowest price first).

### `order_book_batch`

In firehose mode (`subscribe_all: true`), snapshots are conflated into `order_book_batch` envelopes emitted every 50ms instead of a message per book change. `count` is the number of snapshots in the batch, and each entry in `data` has the same shape as the `order_book_update` `data` object.

```json theme={null}
{
  "type": "order_book_batch",
  "room_id": "polymarket_order_book",
  "count": 2,
  "data": [
    {
      "asset_id": "25372132047423243393274625033211281816817614495645323101576308577715572160691",
      "market": "0x1238ad393b16d730f09210caee750695b12e27090d2d56589bb45f78aa92c031",
      "bids": [{ "p": "0.983", "s": "11.41" }, { "p": "0.982", "s": "70" }, { "p": "0.981", "s": "140" }],
      "asks": [{ "p": "0.999", "s": "7308.15" }],
      "timestamp": 1783971763067,
      "hash": "4cc4abf3723bbbe90d7ccbce39324b12bd24be91",
      "best_bid": 0.983,
      "best_ask": 0.999,
      "mid_price": 0.991,
      "spread": 0.016,
      "bid_liquidity_usd": 2501.15777,
      "ask_liquidity_usd": 7300.84185,
      "bid_levels": 54,
      "ask_levels": 1
    },
    {
      "asset_id": "77346748644272683089734212154044987565539531010435964787371832114367915821100",
      "market": "0x1238ad393b16d730f09210caee750695b12e27090d2d56589bb45f78aa92c031",
      "bids": [{ "p": "0.001", "s": "7308.15" }],
      "asks": [{ "p": "0.017", "s": "11.41" }, { "p": "0.018", "s": "70" }, { "p": "0.019", "s": "140" }],
      "timestamp": 1783971763067,
      "hash": "ee1c4a2594a54b9ab1f09849eb0e84deffbe0bfb",
      "best_bid": 0.001,
      "best_ask": 0.017,
      "mid_price": 0.009,
      "spread": 0.016,
      "bid_liquidity_usd": 7.30815,
      "ask_liquidity_usd": 15971.74223,
      "bid_levels": 1,
      "ask_levels": 54
    }
  ]
}
```
