Overview
BULK runs a central limit order book (CLOB) for each perpetual contract market. Orders are matched using price-time priority, the same model used by traditional exchanges.Structure
Each instrument has aBook with two sides:
- Bid levels - buy orders sorted by price (highest first)
- Ask levels - sell orders sorted by price (lowest first)
Matching
When an aggressive order enters:- Price check - buy orders cross if
price >= best_ask, sell orders cross ifprice <= best_bid - Walk the book - the order matches against resting levels at successively worse prices until filled, the limit price is breached, or the book is exhausted
- Risk callback - after each fill, the risk engine verifies the resulting position is within margin limits. If a fill would cause a margin breach, the remainder is cancelled
- Rest or expire - unfilled GTC remainder rests on the book. IOC remainder is cancelled. ALO orders that would have crossed are rejected before matching.
Pre-Flight Margin Check
Before any order touches the book, the executor validates:- Sufficient available equity for the new position
- Leverage within configured limits
- Valid order parameters (size, price, side)
- Reduce-only orders actually reduce the position
Self-Trade Prevention
When an incoming order would match against a resting order from the same account, the match is skipped. See Self-Trade Prevention.Deterministic Execution
Every validator processes the same committed batch through the same matching engine and produces the same fills, the same order statuses, and the same book state. Any divergence is immediately detectable by comparing output state hashes.Integration with Risk
The order book and the portfolio risk engine operate as a tightly coupled system. They share state on every tick:- Mark price - The book’s bid, ask, and last traded price feed directly into the mark price model. The depth-weighted mid-price is one of the three core components of the mark price calculation. See Price Indices.
- Lambda surfaces - Order book depth is used to estimate the market impact of unwinding a position. This impact estimate feeds into the lambda surface lookup, which determines maintenance margin rates. Thin books produce higher lambdas and higher margin requirements.
- Liquidation execution - Order-book depth determines closeout impact, reserve-adjusted margin, and the size of protected execution. Planned reductions are not submitted as one unrestricted market order: BULK uses available market liquidity only within limits independently anchored to fair price and oracle price. Planned quantity that cannot be accepted within protocol capacity becomes an ADL underfill candidate. See Liquidations.