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

# L2 Book

Name of channel: `l2_book`

Description: Pushes order book snapshots and deltas.

URL path: `/v1/public/market`

Authentication: No auth required

Request parameters:

| Parameter   | Type    | Required | Description                                           |
| ----------- | ------- | -------- | ----------------------------------------------------- |
| `channel`   | string  | Yes      | `l2_book`                                             |
| `symbol_id` | integer | Yes      | Trading pair ID.                                      |
| `depth`     | integer | No       | `5`, `10`, `20`, `50`, `100`, or `200`. Default `20`. |
| `merge`     | integer | No       | Price merge multiplier of `price_step`. Default `1`.  |

Subscription acknowledgement fields:

| Field     | Type    | Description                                                             |
| --------- | ------- | ----------------------------------------------------------------------- |
| `id`      | string  | Echoes the request `id`. String, max 32 characters, `[A-Za-z0-9]` only. |
| `op`      | string  | `subscribe` or `unsubscribe`.                                           |
| `success` | boolean | Whether at least one subscription succeeded.                            |
| `args`    | array   | Successful subscription args. Present on success.                       |
| `code`    | string  | Error code. Present on failure.                                         |
| `msg`     | string  | Error message. Present on failure.                                      |

Push data parameters:

| Field | Type    | Description                                |
| ----- | ------- | ------------------------------------------ |
| `s`   | integer | Symbol ID.                                 |
| `b`   | array   | Bid levels as `[price, size]`, descending. |
| `a`   | array   | Ask levels as `[price, size]`, ascending.  |
| `p`   | integer | Previous sequence.                         |
| `q`   | integer | Current sequence.                          |
| `t`   | integer | Market data timestamp.                     |

Book update sequencing:

* Use a \`snapshot\` message to initialize the local order book.
* For later update messages, apply the update only when \`p\` matches the last applied \`q\`.
* If \`p\` does not match the last applied \`q\`, resubscribe to rebuild from a fresh snapshot.

Request example:

```json
{
  "id": "subBook",
  "op": "subscribe",
  "args": [
    { "channel": "l2_book", "symbol_id": 100001, "depth": 20, "merge": 1 }
  ]
}
```

Response example, success:

```json
{
  "id": "subBook",
  "op": "subscribe",
  "success": true,
  "args": [
    { "channel": "l2_book", "symbol_id": 100001, "depth": 20, "merge": 1 }
  ]
}
```

Response example, failure:

```json
{
  "id": "subBook",
  "op": "subscribe",
  "success": false,
  "code": "222001",
  "msg": "Invalid depth"
}
```

Push data example:

```json
{
  "arg": { "channel": "l2_book", "symbol_id": 100001, "depth": 20, "merge": 1 },
  "type": "snapshot",
  "finality": "final",
  "data": {
    "s": 100001,
    "b": [["67499.50", "0.900"]],
    "a": [["67500.00", "1.200"]],
    "p": 0,
    "q": 123456,
    "t": 1719500000000
  },
  "ts": 1719500000000
}
```


---

# 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.ticko.xyz/api-documentation/market/websocket/l2-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.
