Deep Orderbook Account (SDK Reference)#
The deep orderbook account is the single fixed-size Solana account that holds one market's entire resting order book — both bid and ask sides, stored as bounded red-black trees for price-time-priority matching. This page is the SDK-facing reference for that account: what it exposes, how to decode it, its fixed capacity, and the order-ID format. For the design rationale (why one account holds both the YES and NO outcome lanes), see Design → Order Book; for the general trading model, see How It Works → Order Book.
Public model: decoded bids and asks#
Every SDK decoder exposes the same public model regardless of language:
a decoded orderbook has a bids array and an asks array, each in
descending/ascending price-time priority, plus a header with the market
address, bump, capacity, and the next order-insertion sequence. This
shape remains the same in the indexed layout with header version 2.
The on-chain loader and all three SDK decoders require the indexed version 2 layout. Use the maintained SDK decoder for live accounts and snapshots in that format.
| Language | Decoder function |
|---|---|
| TypeScript | decodeDeepOrderbookAccount |
| Rust | decode_deep_orderbook |
| Python | decode_deep_orderbook |
Capacity and account size#
Every market has one capacity: 4,096 orders per side. The account is exactly
1,376,448 bytes (192 + 336 * capacity at capacity 4,096), assembled from a 128-byte header, two 32-byte side headers,
and for each side 4,096 32-byte nodes plus 4,096 136-byte orders (a total of
128 + 2 * (32 + 4096 * 32 + 4096 * 136)). An order includes a 16-byte
client_order_id at offset 73, its trading generation at offset 89, and indexed
metadata beginning with the maker's ledger seat index at offset 93 and seat
generation at offset 95. See Market Capacity for
rent figures and allocation-prelude requirements, and Design → Order
Book for why the account is
sized this way.
A fully populated book can exceed the transaction's default 32-KiB heap, so
request a 64-KiB heap frame for a single placement. For post-only batches,
request the greater of 64 KiB and 23 KiB per entry across both sides. The
eight-entry maximum requests 184 KiB. Use the SDK compute-budget helpers for
RequestHeapFrame and simulate the actual transaction to size its compute-unit
limit. Priority Fees and Compute Budget
Order IDs#
Order IDs are opaque 64-bit values — never parse them as a bit-packed
struct. For a market with capacity C, given the canonical side, physical
slot, and insertion sequence at fill time:
id = sequence * (2 * C) + (side == Ask ? C : 0) + slot + 1
Decoding is the inverse: divide id - 1 by 2 * C to recover the sequence,
and take the remainder to recover the side and slot. You should not need to
do this yourself — the SDK's per-order decode already resolves and validates
this for you, checking that the capacity is supported, the node is
currently occupied, the slot matches, the node/order/locator all agree, the
canonical side is correct, and the decoded sequence is below the account's
current insertion counter. A stale or reused ID fails that check rather
than silently resolving to the wrong order.
The account's raw insertion-counter field is named next_order_id at the
Rust byte-offset level, but every SDK exposes it under a clearer name:
nextOrderSequence in TypeScript, next_order_sequence in Rust and Python.
Redeem is bounded and retryable#
Redeem is paginated: a single call may only partially process a large
position, so the caller is responsible for looping. Authenticate the
finalized three-byte return value and keep re-sending the identical
instruction until its has_more flag reads false. Do not build a
single-send helper that assumes one call always finishes the redemption — a
partial call intentionally performs no burn or payout on that step, and
re-sending with the same arguments is safe and idempotent. The retry loop is
implemented in the official clients' source (for example, the web app's
portfolio flow), but treat public release/production-readiness of any given
client as a separate question from source availability; if you are building
your own integration, implement the has_more loop yourself. For the
Redeem account layout and a worked single-call example, see Building
Transactions → Redeeming After Resolution.
External-market allocation sequencing#
External-market creators should use the receipt-bound allocation planners and
wait for each confirmed/finalized preallocation transaction before submitting
the next dependent step or OpenExternalMarket. The legacy four-account,
receipt-free allocation instruction remains a permissionless donation-only
primitive: a third-party payer is not recorded as the creator and cannot rely
on a later rent refund or attribution. Use the creator-funded receipt plan when
funding must be attributable and refundable, and treat transaction finality as
part of the safety boundary before opening the market.
ForceClose progress and completion#
Each current ForceClose step emits ForceCloseProgress, including the
post-step position and has_more. A completed step also emits ForceClosed.
Consumers of historical records may encounter ForceClosed alone and should
use the historical event projection for those records.
Related#
- Design → Order Book — why a single account holds both outcome lanes, and the trade-offs of that choice.
- How It Works → Order Book — matching rules and the user-facing trading model.
- Market Capacity — canonical rent costs and allocation prelude sizing.
- Reading Data — how to fetch and decode a market's orderbook (and other accounts) end to end.