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

# Order Book Stream

This stream provides real-time order book updates for a specified market.

Upon subscription to this stream, you will receive `publicOrderBookDelta` messages whenever the order book changes:

```json theme={null}
{
    "resultType": "publicOrderBookDelta",
    "market": "ETH-USDT",
    "data": {
        "orders": [
            {
                "orderType": "sell",
                "price": "3181.41",
                "quantity": "38.92"
            },
            {
                "orderType": "buy",
                "price": "3181.39",
                "quantity": "38.98"
            }
        ],
        "statusCode": 200,
        "ts": 1772576154169
    }
}
```

| Field                     | Type   | Required | Description                                  |
| ------------------------- | ------ | -------- | -------------------------------------------- |
| `resultType`              | string | Yes      | `publicOrderBookDelta`                       |
| `market`                  | string | Yes      | Market name                                  |
| `data.orders`             | array  | Yes      | Incremental order book changes               |
| `data.orders[].orderType` | string | Yes      | Order side: `buy` or `sell`                  |
| `data.orders[].price`     | string | Yes      | Price level                                  |
| `data.orders[].quantity`  | string | Yes      | New total quantity at this price level       |
| `data.statusCode`         | number | Yes      | `200`                                        |
| `data.ts`                 | number | Yes      | Update timestamp in milliseconds since epoch |

### Order Book Snapshot Request

There is one request called **emitPublicOrderBook** that returns a full order book snapshot with `publicOrderBook` response messages. This request is useful for:

* Bootstrap order book state when first subscribing to the stream
* Recover after temporary data loss or connection issues
* Synchronize local book models with the current market state
* Get the complete order book picture before processing delta updates

#### Request

```json theme={null}
{
  "message":"emitPublicOrderBook",
  "content": {
    "clientRequestId": "4cc68b60-ed2d-42aa-a21e-cb5486f8fd1a",
    "market": "ETH-USDT"
  }
}
```

| Field                     | Type   | Required | Description                                                  |
| ------------------------- | ------ | -------- | ------------------------------------------------------------ |
| `message`                 | string | Yes      | `emitPublicOrderBook`                                        |
| `content.clientRequestId` | string | No       | Client-generated UUID for correlation                        |
| `content.market`          | string | No       | Market name, only required when connecting with `market=ALL` |

#### Response

```json theme={null}
{
    "resultType": "publicOrderBook",
    "market": "ETH-USDT",
    "data": {
        "clientRequestId": "4cc68b60-ed2d-42aa-a21e-cb5486f8fd1a",
        "orders": [
            {
                "orderType": "buy",
                "price": "3181.39",
                "quantity": "38.98"
            },
            {
                "orderType": "sell",
                "price": "3181.41",
                "quantity": "38.92"
            }
        ],
        "statusCode": 200,
        "ts": 1772576154169
    }
}
```

| Field                     | Type   | Required | Description                                    |
| ------------------------- | ------ | -------- | ---------------------------------------------- |
| `resultType`              | string | Yes      | `publicOrderBook`                              |
| `market`                  | string | Yes      | Market name                                    |
| `data.clientRequestId`    | string | No       | Client-generated UUID for correlation          |
| `data.orders`             | array  | Yes      | Full order book entries                        |
| `data.orders[].orderType` | string | Yes      | Order side: `buy` or `sell`                    |
| `data.orders[].price`     | string | Yes      | Price level                                    |
| `data.orders[].quantity`  | string | Yes      | Total quantity at this price level             |
| `data.statusCode`         | number | Yes      | `200`                                          |
| `data.ts`                 | number | Yes      | Snapshot timestamp in milliseconds since epoch |
