> For the complete documentation index, see [llms.txt](https://docs.21x.eu/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.21x.eu/websocket-api/orderbook.md).

# Orderbook

## Orderbook data

This guide explains how to use the WebSocket API to subscribe to market data updates via the `/orderbook` channel.

***

### Overview

The WebSocket API allows clients to receive real-time market data updates. Subscribing to the `/orderbook` channel provides updates for market ticker data, including prices, bids, asks, and quantities.

***

### Channel

#### `/orderbook/*`

* Subscribe to get ticker data from all active markets.

#### `/orderbook/bytradingpair/{market symbol}`

* Subscribe to get ticker data from specific markets
* Client may be subscribed to many markets at the same time.

***

### Subscription

```json
{
    "id": "94c68f6e-44ba-46ec-b9fb-4eb7addfe5ea",
    "type": "subscribe",
    "channel": "orderbook/*",
    "authorization": {
        "host": "vfqqino6svadzoqkann4355in4.appsync-api.eu-central-1.amazonaws.com",
        "x-amz-date": "20250117T133706Z",
        "x-api-key": "da2-vjlcb7rsira4bggsctnmzcjvwe"
    }
}
```

```json
{"id":"94c68f6e-44ba-46ec-b9fb-4eb7addfe5ea","type":"subscribe_success"}
```

***

### Market Data Model

When subscribed to the `/orderbook` channel, the server sends market data updates in the following format:

#### Level 2 Market Data Example

#### Example message

```json
{
  "channel": "orderbook",
  "data": [
    {
      "symbol": "ABCEUROe",
      "buy": [
        {
          "limit": 120.05,
          "totalQuantity": 36,
          "orderCount": 2
        },
        {
          "limit": 120.0,
          "totalQuantity": 65,
          "orderCount": 1
        }
      ],
      "sell": [
        {
          "limit": 120.2,
          "totalQuantity": 150.5,
          "orderCount": 3
        },
        {
          "limit": 120.5,
          "totalQuantity": 77,
          "orderCount": 1
        }
      ],
      "time": "2024-12-16T12:28:22.462Z"
    }
  ]
}
```

#### Field Descriptions

| Field           | Type              | Description                                            |
| --------------- | ----------------- | ------------------------------------------------------ |
| `channel`       | String            | The type of data channel, e.g., "orderbook".           |
| `data`          | Array             | Array containing market data for the specified symbol. |
| `symbol`        | String            | The trading pair, e.g., "ABCEUROe".                    |
| `buy`           | Array of Objects  | List of buy orders with price levels and quantities.   |
| `sell`          | Array of Objects  | List of sell orders with price levels and quantities.  |
| `limit`         | Number            | Price limit for the order.                             |
| `totalQuantity` | Number            | Total quantity of orders at the price level.           |
| `orderCount`    | Number            | Number of orders at the price level.                   |
| `time`          | String (ISO 8601) | Timestamp of the market data.                          |


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.21x.eu/websocket-api/orderbook.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
