> ## Documentation Index
> Fetch the complete documentation index at: https://docs.devnet.perp.ordr.trade/llms.txt
> Use this file to discover all available pages before exploring further.

# The Shared Book

> How several market makers quote into one order book per market

Every market has exactly one book: two accounts, a bid side and an ask side,
holding up to 64 resting orders between them, at most 16 from any single
maker. Every approved maker quoting on that market writes into the same
book. Nobody owns it alone.

## Orders are an offset, not a price

A resting order does not store an absolute price. It stores a small signed
offset in ticks from the mid price **that maker** controls:

```
price = mid + offset * tick_size
```

Here is a worked example. Say a maker's mid is $100, the market's tick size
is $0.01, and that maker has a bid resting with an offset of -5 and a size
of 10 tokens:

```
mid       = $100
tick_size = $0.01
offset    = -5

price = mid + (offset × tick_size)
price = $100 + (-5 × $0.01)
price = $99.95
```

When the market moves, the maker reprices once, and every one of their
resting orders moves with it automatically. If that maker's mid moves to
$101, the same order, offset unchanged, now rests at $100.95. Nothing about
the order itself has to change, which is what makes repricing a whole book
a single cheap write instead of a cancel and replace for every order.

A maker's mid lives in their own small **Mid** account, one per maker per
pool: `mid`, `tick_size`, `lot_size`, and a sequence number. Because that
account is scoped to the pool, not to a single market, one reprice updates
that maker's orders across every leverage tier in the pool at once.

## Staying fresh without racing anyone

The old way to protect a reprice from a stale, delayed, or replayed
transaction is priority ordering: get the maker's own cancel or reprice
transaction to land first, ahead of anything trying to trade against it in
the same block. perps.ordr doesn't need that, because nothing trades against
a quote the instant it lands. Every fill happens later, in a batch, covered
on the [Batching and Liquidations](https://docs.devnet.perp.ordr.trade/architecture/batching-and-liquidations.md)
page, so there is no same-slot race for a stale price to win.

What's still needed is a way to tell a stale mid apart from a fresh one. A
maker's reprice carries a sequence number that only ever increases, so a
delayed transaction that lands after a newer one is simply rejected rather
than rolling the price backward. And when the next batch runs, any maker
whose mid has gone stale, meaning its sequence number is older than the
book's own freshness window, or implausibly far in the future, is left out
of that batch entirely. Nothing is skipped as a penalty or a race, they're
just not included until they reprice again.

## Each side is a sorted structure

Bids and asks are kept separately, each sorted so the best order is always
found first: highest offset for bids, lowest for asks, with earlier orders
breaking ties at the same price. Every book has the same fixed capacity, so
every market on perps.ordr has the same shape regardless of how many makers
or orders it actually holds.

## Order lifecycle

Every order gets a unique id when it is placed, and that id is never
reused. An order can be:

* **Resized or repriced in place** by its maker, through `update_order`
* **Partially filled** during a batch, which only updates how much of it
  remains
* **Cancelled** by its maker through `cancel_order`, or all at once on one or
  both sides through `clear_orders`
* **Given an optional expiry**, a point after which it is skipped by the
  next batch rather than filled, and still needs a cancel to free its slot


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.