---
title: "Order book levels"
description: "Get one instrument's order book, up to 10 price levels a side."
---

Do not use this to poll for data -- a websocket subscription is much more performant, and useful.

| | |
|---|---|
| SDK | `client.orderbook_levels(...)` |
| HTTP | `POST https://market-data.<domain>/full/v1/book`, or `/lite/v1/book` for [lite names](../../guides/environments.md#encoding-full-or-lite) (the SDKs' default) |
| WebSocket | method `v1/book` on `wss://market-data.<domain>/ws/full`, or `/ws/lite` for lite names |
| Auth | None (public) |
| Retries | Read: the SDKs retry retryable errors ([rules](../../guides/errors-and-retries.md)) |
| Contract id | `orderbook.orderbook_levels` (`RPCOrderbookLevelsV1`) |

## Request

Body type `ApiOrderbookLevelsRequest`. Fields the server fills are left out.

- `instrument` · lite `i` · string (instrument name) · required — The instrument name, e.g. `BTC_USDT_Perp` (perpetual), `BTC_USDT_SFP` (stable funding perp) or `BTC_USDT_SpotSwap` (spot swap).
- `depth` · lite `d` · integer (uint32) · required — Depth of the order book to be retrieved (10, 50, 100, 500)

## Response

Body type `ApiOrderbookLevelsResponse` (the same object is the JSON-RPC `result` over WebSocket).

- `result` · lite `r` · object OrderbookLevels · required — The orderbook levels objects matching the request asset
- `result.event_time` · lite `et` · string (int64 unix ns) · required — Time at which the event was emitted in unix nanoseconds
- `result.instrument` · lite `i` · string (instrument name) · required — The instrument name, e.g. `BTC_USDT_Perp` (perpetual), `BTC_USDT_SFP` (stable funding perp) or `BTC_USDT_SpotSwap` (spot swap).
- `result.bids` · lite `b` · object OrderbookLevel[] · required — The list of best bids up till query depth
- `result.bids[].price` · lite `p` · string · required — The price of the level. Decimal string, e.g. "65000.5"; up to 9 decimals.
- `result.bids[].size` · lite `s` · string · required — The number of assets offered. Decimal string, e.g. "0.01"; up to the instrument's base_decimals.
- `result.bids[].num_orders` · lite `no` · integer (uint32) · required — The number of open orders at this level
- `result.asks` · lite `a` · object OrderbookLevel[] · required — The list of best asks up till query depth
  Fields: same as `result.bids[]` above.

## Errors

Errors come back as `{"code", "message", "status"}` (lite `{"c", "m", "s"}`) with the HTTP status. Codes this call can return, as code, name (HTTP status) ([all error codes](../errors.md)):

`1002` InternalServer (500) · `1003` InvalidRequest (400) · `1004` NotFound (404) · `1006` RateLimit (429, retryable) · `3000` InvalidInstrument (400) · `3031` InvalidDepth (400) · `7725` SfpEndpointNotSupported (403)

## Example

```python
from grvt import Grvt

with Grvt(env="testnet") as client:
    resp = client.orderbook_levels(
        instrument="BTC_USDT_Perp",
        depth=50,
    )
    print(resp)
```

Raw HTTP (set `GRVT_DOMAIN`, see [Environments](../../guides/environments.md)):

With full field names:

```sh
curl -sS "https://market-data.$GRVT_DOMAIN/full/v1/book" \
  -H "Content-Type: application/json" \
  --data @- <<EOF
{
  "instrument": "BTC_USDT_Perp",
  "depth": 50
}
EOF
```

With lite field names:

```sh
curl -sS "https://market-data.$GRVT_DOMAIN/lite/v1/book" \
  -H "Content-Type: application/json" \
  --data @- <<EOF
{
  "i": "BTC_USDT_Perp",
  "d": 50
}
EOF
```
