Skip to main content
Matching two traders together happens off-chain, in memory, before anything is sent on-chain for settlement. This keeps matching fast and cheap, on-chain transactions only happen once a trade is actually ready to settle.

One order book per market

Each market keeps its own list of resting orders, sorted by price first and arrival time second: the best-priced order is always at the front, and among orders at the same price, the one that arrived first gets matched first. When a new order comes in, it’s checked against the opposite side of the book, buyers against sellers or vice versa, starting from the best-priced match and working outward, until either the new order is fully matched or nothing left on the book is willing to trade at a compatible price.

Limit orders vs. market orders

These two behave differently once the matching pass finishes:
  • Limit orders that don’t fully match simply rest on the book, waiting for a future order to complete them, the same as a normal exchange order book.
  • Market orders that don’t fully match are different: whatever portion didn’t find a match is simply dropped rather than left resting. A market order either fills against what’s currently available or it doesn’t, it never waits around.
A trader’s own resting order is never matched against their own incoming order, self-trades are skipped automatically.

The order book alone isn’t the final word

Matching who trades with whom is deliberately kept separate from deciding whether that trade is currently allowed. The order book only knows about resting orders and their prices, it has no idea what the live oracle price is, what the market’s current risk limits are, or whether either trader’s slippage tolerance has been breached. A second, separate check runs against all of that live information before anything is sent on-chain, exactly the check described in Slippage & Execution.

What actually gets settled

The order book only decides how much trades between two orders, not the price it settles at. Every trade actually settles at the live oracle mark price at the moment of settlement, not at either trader’s limit price. A limit price is a boundary you won’t cross past, not the price you’re guaranteed to get.

When settlement doesn’t go through

If an on-chain settlement attempt fails, nothing was actually changed on-chain, so the trade is rechecked against current live conditions and retried. If it still can’t go through after retrying, it’s marked as failed rather than silently left half-done, and any leftover portion of either order is pulled off the book. The trader needs to submit a fresh order at that point rather than assuming the old one is still working in the background.