# 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: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
