On-chain matching

The NeutronX order book lives in network state, and the validators match it in every block. Matching rules are the same for every participant, and every validator checks them.

Where matching happens

The proposer takes new orders from the mempool and matches them against the book. It places the resulting trades in the first transaction of the block. The other validators repeat the matching and reject the block on any mismatch. Trades are settled at the start of block execution.

Details are in Architecture.

Priority

  1. Price. The best price executes first.
  2. Block. Within one price level, an order from an earlier block goes first.
  3. Place in the block. Within one block, the order that comes earlier in the block goes first. No order field, including client_id, can move it in the queue.

Trade price

CasePrice
Limit orders crossed while matching in the blockThe price of the order that rested in the book first, if it is inside the execution band, otherwise the other order's price
Market orderThe price of the resting order it matches
System orders: liquidations, SL/TP, TWAP, POV, position closeThe price of the resting order it matches

The oracle price and the mark price never set a trade price. They are used only for margin, liquidations and conditional order triggers.

A consequence of the first row: the order that crossed the book later gets the price of the order resting in it, as on any continuous book.

Price bands

BandValueWhat it limits
Placement50% of the oracle priceHow far from the oracle an order can be placed
Execution1% of the oracle price, 0.5% for BTC and ETHAt what price a trade can execute

An order beyond the execution band rests in the book and fills once the oracle price comes closer. Governance sets the bands for each market.

Self-trading and post-only

  • Self-trading. An order never matches an opposite order of the same owner. That order is skipped, and matching continues down the book.
  • Post-only. A post-only order never takes liquidity. If it would fill at once, at placement or later as the oracle price moves, it is cancelled.

If a trade fails to settle

Each trade settles separately. If settlement fails, for example one side lacks margin, the whole trade is cancelled. The order of the side that caused the failure is removed from the book. The other side stays in the book.

Limits

LimitValue
Minimum order size10 USDC
Open orders per subaccount500
Placements and replacements per address per block30, each order of a batch counts separately
Active orders across the network500,000