> For the complete documentation index, see [llms.txt](https://docs.outpoll.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.outpoll.com/api/rest-api/websockets/order-book.md).

# Order Book

Use this stream for live order book updates by event.

### Endpoint

```
wss://order-book.outpoll.com/event/ws
```

### Authentication

No authentication required.

### Message envelope

Every message uses the same top-level fields:

```json
{
  "t": "<TYPE>",
  "e": "<EVENT_ID>",
  "d": [...],
  "r": "<ERROR_MESSAGE>"
}
```

| Field | Type   | Description                    |
| ----- | ------ | ------------------------------ |
| `t`   | string | Message type                   |
| `e`   | string | Event ID                       |
| `d`   | array  | Outcome price payload          |
| `r`   | string | Error message for failed calls |

### Message types

| Type                | Direction | Description              |
| ------------------- | --------- | ------------------------ |
| `SUBSCRIBE`         | Client    | Subscribe to one event   |
| `SUBSCRIBED`        | Server    | Subscription confirmed   |
| `UNSUBSCRIBE`       | Client    | Remove one subscription  |
| `UNSUBSCRIBED`      | Server    | Unsubscribe confirmed    |
| `REQUEST_DATA`      | Client    | Request a full snapshot  |
| `PRICES_DATA`       | Server    | Full price snapshot      |
| `PRICES_DATA_DELTA` | Server    | Incremental price update |
| `PING`              | Server    | Heartbeat                |
| `ERROR`             | Server    | Request error            |

### Subscribe

```json
{
  "t": "SUBSCRIBE",
  "e": "54ccea1a-16fd-469c-8018-84b375243e8a"
}
```

Server confirmation:

```json
{
  "t": "SUBSCRIBED",
  "e": "54ccea1a-16fd-469c-8018-84b375243e8a"
}
```

### Price payload

`PRICES_DATA` sends the current state.

`PRICES_DATA_DELTA` sends only changed outcomes.

```json
{
  "t": "PRICES_DATA",
  "e": "54ccea1a-16fd-469c-8018-84b375243e8a",
  "d": [
    {
      "o": "b21f6fd8-b9d1-4b9f-bb79-ef141e3dcb76",
      "c": 0.55,
      "b": 0.54,
      "a": 0.56
    }
  ]
}
```

| Field | Type   | Description |
| ----- | ------ | ----------- |
| `o`   | string | Outcome ID  |
| `c`   | number | Last chance |
| `b`   | number | Best bid    |
| `a`   | number | Best ask    |

### Python example

{% code title="order\_book.py" %}

```python
import asyncio, json, websockets

async def order_book():
    uri = "wss://order-book.outpoll.com/event/ws"
    async with websockets.connect(uri) as ws:
        await ws.send(json.dumps({
            "t": "SUBSCRIBE",
            "e": "54ccea1a-16fd-469c-8018-84b375243e8a",
        }))

        async for msg in ws:
            data = json.loads(msg)
            if data["t"] in ("PRICES_DATA", "PRICES_DATA_DELTA"):
                for price in data["d"]:
                    print(price["o"], price["c"], price["b"], price["a"])
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.outpoll.com/api/rest-api/websockets/order-book.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
