# Perpetual book depth

> Order-book depth within 0.2 % to 5 % of the mid of each crypto perpetual, every ~30 seconds.

Source: https://getmarkethistory.com/docs/book-depth

**Not live yet.** `crypto/perps` will carry a snapshot of each Binance perpetual's order book **about
every 30 seconds**, from January 2023 on, delisted contracts included. Until the first backfill
is published the route answers 404; the [changelog](https://getmarkethistory.com/docs/changelog) will date it.

Each snapshot gives the book's cumulative size within 0.2 %, 1 %, 2 %, 3 %, 4 % and 5 % of the
mid, on each side, in the base asset and in the quote currency. A day is added the day after it
ends.

## Query

curl:

```bash
curl -sD - "https://getmarkethistory.com/query/v1/book-depth?ticker=BTCUSDT&start=2026-09-01&end=2026-09-01" \
  -H "Authorization: Bearer $MARKET_HISTORY_KEY"
```

Python client:

```python
from markethistory import Client

mh = Client()  # reads MARKET_HISTORY_KEY

rows = list(mh.each(mh.book_depth, "BTCUSDT", start="2026-09-01", end="2026-09-01"))
len(rows)  # 2,880 snapshots a day
```

Plain `requests`:

```python
import json
import os

import requests

url = "https://getmarkethistory.com/query/v1/book-depth"
params = {"ticker": "BTCUSDT", "start": "2026-09-01", "end": "2026-09-01"}
headers = {"Authorization": f"Bearer {os.environ['MARKET_HISTORY_KEY']}"}

rows, cursor = [], ""
while cursor is not None:  # one request per page, until no next cursor comes back
    page = {**params, "cursor": cursor} if cursor else params
    r = requests.get(url, params=page, headers=headers, timeout=60)
    r.raise_for_status()  # see /docs/errors for what each status means
    rows += [json.loads(line) for line in r.text.splitlines() if line]
    print(r.headers["X-Row-Count"], "rows,", r.headers["X-Bars-Charged"], "bars")
    cursor = r.headers.get("X-Next-Cursor")
```

Response (shape and headers as served; values illustrative):

```http
HTTP/2 200
content-type: application/x-ndjson
x-row-count: 1000
x-bars-charged: 1000
x-next-cursor: eyJ…
x-query-ms: 18

{"ask_depth_0_2":1203.118,"ask_depth_1":4127.5,"ask_depth_2":5961.04,"ask_depth_3":7012.33,"ask_depth_4":7998.61,"ask_depth_5":9102.47,"ask_notional_0_2":131050112.4,"ask_notional_1":451077206.2,"ask_notional_2":654780193.9,"ask_notional_3":773502114.6,"ask_notional_4":886230051.3,"ask_notional_5":1014470227.8,"bid_depth_0_2":1311.402,"bid_depth_1":4402.917,"bid_depth_2":6020.55,"bid_depth_3":7130.2,"bid_depth_4":8967.166,"bid_depth_5":10267.922,"bid_notional_0_2":142563790.1,"bid_notional_1":475034512.7,"bid_notional_2":643520198.4,"bid_notional_3":754228310.9,"bid_notional_4":690917971.3,"bid_notional_5":788466627.1,"timestamp":"2026-09-01T00:00:04Z"}
```

One symbol per request, spelled as `/api/v1/symbols?dataset=crypto/perps&timeframe=1m` lists
it.

| Parameter      | Meaning                                                                                                                                                                                                                                               |
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ticker`       | The perpetual (`BTCUSDT`). Required.                                                                                                                                                                                                                  |
| `dataset`      | Optional: `crypto/perps`, the only source with book depth.                                                                                                                                                                                            |
| `feed`         | Which feed serves the book depth, on a dataset with several: `crypto/perps` `binance` or `bybit` (`main` and `1s` still work). Omitted, the first feed that holds book depth for the ticker. `X-Feed` names the one that answered; a cursor keeps it. |
| `start`, `end` | Time range, inclusive (RFC 3339 or a bare date). Default: all of it.                                                                                                                                                                                  |
| `limit`        | Rows per page: default and maximum by format ([Limits](https://getmarkethistory.com/docs/limits#request-limits)).                                                                                                                                                                 |
| `cursor`       | `X-Next-Cursor` from the previous page.                                                                                                                                                                                                               |
| `format`       | `jsonl` (default), `csv`, `json`, `parquet` or `arrow`. `mbt1` is bars only.                                                                                                                                                                          |

Pages run oldest first. Follow `X-Next-Cursor` (or the `Link` header) until it is absent: the
cursor holds no server state. A symbol without book depth is a 404.

## Columns

| Column                                | Type      | Meaning                                                       |
| ------------------------------------- | --------- | ------------------------------------------------------------- |
| `timestamp`                           | timestamp | the snapshot's time, UTC, to the second (about every 30 s)    |
| `bid_depth_0_2` … `bid_depth_5`       | float     | bids within 0.2 %, 1 % … 5 % below the mid, in the base asset |
| `ask_depth_0_2` … `ask_depth_5`       | float     | asks within 0.2 %, 1 % … 5 % above the mid, in the base asset |
| `bid_notional_0_2` … `bid_notional_5` | float     | the same bids in the quote currency (USDT for `BTCUSDT`)      |
| `ask_notional_0_2` … `ask_notional_5` | float     | the same asks in the quote currency                           |

Each band is cumulative: `bid_depth_2` includes `bid_depth_1`. Any value column can be `null`:
snapshots before February 2023 have no 0.2 % bands. A missing snapshot is a missing row, not a
row of nulls. Values are stored exactly as published (every digit) and are served as the
nearest float.

## Price

Billed like bars: **one row is one bar**, a page rounds up to a block of 100 rows, and an empty
page is free. Book depth needs bought bars: the free plan's monthly bars do not pay for it.
A day of one perpetual is about 2,880 rows.
