> For the complete documentation index, see [llms.txt](https://dev.strixlab.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dev.strixlab.io/typescript-sdk/orderbook.md).

# Order Book

Every read on this page is **public**. For a continuously updating book, subscribe over [WebSocket](/typescript-sdk/websockets.md) instead of polling these.

### Snapshot

```ts
const book = await client.orderbook.snapshot(tokenId, { depth: 20 });

book.bids;   // [{ price: 0.62, size: 500 }, { price: 0.61, size: 300 }, …] highest first
book.asks;   // [{ price: 0.63, size: 200 }, { price: 0.64, size: 450 }, …] lowest first
```

`depth` is levels per side — default 50, maximum 200. `size` is the total shares resting at that price.

{% code title="Printing a book" %}

```ts
const book = await client.orderbook.snapshot(tokenId, { depth: 5 });

console.log('    price    size');
for (const a of [...book.asks].reverse()) console.log(`ASK ${a.price.toFixed(3)}  ${a.size}`);
console.log('    ────────────');
for (const b of book.bids)                console.log(`BID ${b.price.toFixed(3)}  ${b.size}`);
```

{% endcode %}

### Midpoint

```ts
const { mid } = await client.orderbook.midpoint(tokenId);   // (bestBid + bestAsk) / 2
```

{% hint style="warning" %}
`midpoint()` throws a `StrixApiError` with `status: 404` when either side of the book is empty — a one-sided book has no midpoint to report. Catch it, or read `client.ws.orderbook.getMid(tokenId)` instead, which returns `null` fields rather than throwing.
{% endhint %}

### Best price

```ts
const { price: bestAsk } = await client.orderbook.price(tokenId, 'buy');   // lowest you can buy at
const { price: bestBid } = await client.orderbook.price(tokenId, 'sell');  // highest you can sell at
```

The side names the action you want to take, not the book side: `'buy'` returns the best **ask**, `'sell'` the best **bid**.

### Reading both sides from one book

YES and NO are complements — a bid on YES at `P` is an ask on NO at `1 − P` — so one subscription gives you both. The SDK computes it for you:

```ts
client.ws.orderbook.subscribe([yesTokenId], {
  onMid: ({ yesMid, noMid, bestBid, bestAsk }) => {
    console.log(`YES ${yesMid} (${bestBid}/${bestAsk})  ·  NO ${noMid}`);
  },
});
```

{% hint style="info" %}
The venue's own price ladder subscribes to **both** tokenIds and mirrors each into the other, so a user's NO orders show on the YES ladder. If you're rendering a book, do the same: subscribe to both legs and merge, rather than assuming one book carries everything.
{% endhint %}

### Snapshot or stream?

<table><thead><tr><th width="230">Use</th><th>When</th></tr></thead><tbody><tr><td><code>orderbook.snapshot()</code></td><td>One-off reads, backtests, health checks, and re-syncing after a gap.</td></tr><tr><td><code>ws.orderbook.subscribe()</code></td><td>Anything live. The server sends one snapshot then incremental deltas; the SDK merges them and hands you a maintained book.</td></tr><tr><td><code>ws.orderbook.getBook()</code></td><td>Synchronous read of the SDK's cached book, with no request at all — the right call inside a quoting loop.</td></tr></tbody></table>

{% hint style="danger" %}
**Don't poll `snapshot()` in a loop.** Read endpoints are rate limited, and a poll interval that keeps up with the book will burn your budget for no benefit. One WebSocket subscription costs nothing per update.
{% endhint %}


---

# 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://dev.strixlab.io/typescript-sdk/orderbook.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.
