The Matching Engine is the PolyEngine component that handles price discovery and execution.
It maintains the active order books for all spot markets and deterministically matches eligible orders according to strict sequencing and priority rules. The Matching Engine operates only on orders that have already passed admission and reservation and produces execution events that drive settlement, market data, and proofs.
Role in the Trading Flow
Orders reach the Matching Engine only after passing validation and reservation in the Account Admission Shard (AAS) and being registered and tracked by Symbol Order State (SOS).
At this point, an order represents committed trading intent. The Matching Engine never evaluates balances, permissions, or risk directly. It assumes those guarantees have already been enforced upstream.
It determines only how orders interact once they are eligible to trade.
Order Book Model
The Matching Engine maintains a full L3 order book for each market.
Each order book contains all active limit orders for a given trading pair and is ordered by price and time submitted.
Market orders, limit orders, post-only orders, and triggered orders are all normalized into a common execution model before entering the book.
Matching Rules
Matching follows price-time priority.
Orders are matched according to:
- Best price: more aggressive prices take precedence
- Time priority: among orders at the same price, earlier orders are matched first
These rules are applied consistently across all markets and execution paths.
Partial fills are handled natively. An order may generate multiple execution events as it interacts with available liquidity until it is fully filled or removed.
Deterministic Execution
Given the same ordered sequence of inputs, the Matching Engine will always produce the same matches and execution outcomes. Order sequencing is explicit and stable, and matching decisions do not depend on nondeterministic factors such as thread timing or network arrival order.
Execution Events
When orders match, the Matching Engine produces execution events.
Each execution event records:
- Price and quantity of the match
- Maker and taker identification
- Ordering information
These events are forwarded to settlement for balance updates, market data pipelines for trade and book updates, and the immutable database for replayability and proof generation.
Market Data Implications
Market data is derived directly from matching outcomes.
- Trades reflect finalized executions produced by the Matching Engine
- L1 and L2 updates are published in real time based on execution and order state changes
- L3 order-level activity is produced continuously but distributed according to visibility policies
The Matching Engine itself does not manage market data distribution; it only emits execution events.
Fairness Guarantees
The Matching Engine ensures fair access to liquidity.
All orders are sequenced explicitly before matching. No participant receives preferential execution ordering.
Post-only and self-trade prevention rules are enforced before execution eligibility.
Because matching is deterministic and event-driven, fairness can be independently verified through replay.