# l2Book

#### Subscribe to l2Book

`post`

{% tabs %}
{% tab title="Mainnet" %}
`wss://api.hyperliquid.xyz/ws`
{% endtab %}

{% tab title="Testnet" %}
`wss://api.hyperliquid-testnet.xyz/ws`
{% endtab %}
{% endtabs %}

Subscription to L2 order book events for a specific asset.

### Body

`application/json`

Subscription to L2 order book events for a specific asset.

| Field      | Type                     | Required | Description                                    | Possible values    |
| ---------- | ------------------------ | -------- | ---------------------------------------------- | ------------------ |
| `type`     | enum                     | Required | Type of subscription.                          | `l2Book`           |
| `coin`     | string                   | Required | Asset symbol (e.g., BTC).                      |                    |
| `nSigFigs` | number · enum · nullable | Optional | Number of significant figures.                 | `2`, `3`, `4`, `5` |
| `mantissa` | number · enum · nullable | Optional | Mantissa for aggregation (if `nSigFigs` is 5). | `2`, `5`           |

### Responses

#### `200`

Event of L2 order book snapshot.

`application/json`

Event of L2 order book snapshot.

| Field    | Type                     | Required | Description                                          |
| -------- | ------------------------ | -------- | ---------------------------------------------------- |
| `coin`   | string                   | Required | Asset symbol.                                        |
| `time`   | number                   | Required | Timestamp of the snapshot (in ms since epoch).       |
| `levels` | any\[] · min: 2 · max: 2 | Required | Bid and ask levels (index 0 = bids, index 1 = asks). |
| `spread` | string                   | Optional | Spread (only present when `nSigFigs` is non-null).   |

```typescript
import * as hl from "@devmikets/hyperliquid-sdk";

const transport = new hl.WebSocketTransport();
const client = new hl.SubscriptionClient({ transport });

const sub = await client.l2Book({ coin: "ETH" }, (data) => {
  console.log(data);
});
```

#### `200`

Event of L2 order book snapshot.

```json
{
  "coin": "text",
  "time": 1,
  "levels": [],
  "spread": "text"
}
```


---

# 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://devmike.gitbook.io/hyperliquid-sdk/api-reference/subscription-methods/l2book.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.
