Skip to content

Trading

Matching engine

The matching engine decides which orders trade against each other. This page covers priority rules, halt triggers, restart behavior, and the fairness invariants the engine enforces.

Price-time priority

When a new order arrives, the engine matches it against the best counter-order in the book. Best is defined first by price, then by time.

  • Better prices fill first โ€” a higher bid beats a lower bid for sellers.
  • Equal prices fill by time โ€” the earlier order wins.
  • Fill price comes from the resting order, not the incoming order.

Halt triggers

Three events can stop matching on a market. While halted, the engine rejects new orders and freezes resting orders.

TriggerEffectResume
Circuit breaker โ€” 30%+ price move Halt new orders, freeze rests, notify users. Admin review + manual resume.
Resolution halt โ€” pre-resolution lockup Halt then drive market to settlement.Market closes after settlement.
Platform maintenance window Reject orders for a short window with a clear error code. Automatically when the window ends.

What happens during a restart

Engine restarts are rare but real. SatoriEx replays the book deterministically; users see a brief outage on writes, never on reads.

  1. API rejects new orders with a transient error code.
  2. Existing rests are loaded from the persistent store.
  3. Book state is replayed to the last committed sequence number.
  4. Matching resumes; rejected clients should retry with the same idempotency key.

Fairness invariants

The engine never lets an order trade ahead of an older order at the same price. No order, including platform seed liquidity, is given priority โ€” orders carry no fast-lane flag.

Retries during restart

During a restart the API may reject `POST /orders` with a transient error. Retry-safe behavior is the caller's responsibility today โ€” track the local order ID before submission and check `/orders` after a transient error to confirm whether the order made it through.