Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Matching Engine

Every instrument has its own in-memory matching-engine instance. Matching runs inside the deterministic state machine, so fills are reproducible by any node replaying the block.

Supported markets

MarketDescription
Spotdirect asset-for-asset matching; no leverage or position tracking
Perpetualleveraged contracts with position tracking, margin, funding, liquidation, and ADL
Outcomeprediction markets traded as Yes / No shares; runs on the perpetual matching path and settles once the market resolves

Order book structure

  • Each side (bid / ask) is organized by price level, kept in price order.
  • Within a price level, orders queue by arrival order.
  • Together this gives strict price–time priority.

Order types

TypeBehavior
Marketexecutes immediately against the book at the best available prices
Limitrests on the book at a specified price
Trigger (TP/SL)stored separately; activates into the book when the mark price crosses the trigger price

Time-in-force (TIF)

TIFMeaning
GTCgood-til-canceled — rests until canceled
IOCimmediate-or-cancel — fill what crosses now, cancel the remainder
ALOpost-only — rest only; if it would cross immediately, the order is rejected
GTDgood-til-date — valid until a specified time (measured by the consensus timestamp); requires an expiry

Availability differs by instrument type: perps reject GTD; spot rejects GTD and trigger orders; outcome limit orders accept only GTC, GTD, and ALO, and reject trigger orders. Reduce-only is available on perps and outcome, not on spot.

Perpetual-specific rules

  • Reduce-only orders may only reduce an existing position; they can never open or increase one.
  • Trigger orders are stored outside the book and activate when the mark price crosses the trigger price, then enter the book as the configured order type.

TWAP

A TWAP order slices a large order into a series of child orders executed across blocks, reducing market impact. Slicing is driven by the consensus timestamp, so the schedule is deterministic across nodes. See the Exchange API for the TWAP operation.

Protections & constraints

  • Self-trade prevention — if a new order would trade against a resting order from the same account, the resting order is cancelled and matching continues. The incoming order is not cancelled by this check.
  • Minimum order size — each instrument limits the minimum order size by its size precision, preventing dust orders. See Instruments for how size precision maps to the minimum order size.
  • Order-size caps — instruments may cap the size of a single limit order and a single market order.
  • Price limits — the oracle can publish per-instrument buy/sell price bounds; orders outside the bounds are rejected. See Oracle.

From match to settlement

Matching produces fills. Fills are handed to the clearing module, which converts them into balance and position changes atomically in the same block — see Clearing & Settlement.