TESTNET
Markets
Trade
Lending Vaults
More
User Docs Developer Docs Sdk API Docs Help
Welcome to Polyester
Concepts
Overview
Creating an Account
Authentication Methods
Turnkey
Smart Wallets
Dashboard
Account Security
MFA
Asset Lifecycle
Supported Assets
Deposit Funds
Withdraw Funds
Transfer Funds
Inventory and Supply
Overview
Trading Fees
Base vs Quote
Lending Fees
Withdrawal Fees
Liquidation Fees
Rebates
Overview
On-chain Visibility
Overview
Supplying
Borrowing
Collateral
Interest
Liquidations
Overview
Trades
Candles
Order Book
Data Delivery
Notifications
Appearance
Localization
Sound Effects
Overview
Architecture
Benchmarks
Matching Engine
Settlement
Safeguards
Overview
Validators
Gas Abstraction
Layer-1 Benchmarks
Audits
Read Pre-compiles
Create Invite Code
Managing Links/Codes
Claiming Rewards
Auto-Convert Rewards
Overview
Create/Delete subaccounts
Permissions
Roles
Audit Logs
Unified Trading Account
Spot Trading
Order Types
Tools
Privacy
Custom Layouts
Overview
Asset Wrapping
Vaults
Zipper Security
What Is TEE?
  1. Polyengine
  2. /
  3. Matching Engine

Matching Engine

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:

  1. Best price: more aggressive prices take precedence
  2. 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.

Time Priority = First in First Out (FIFO)
Orders at the same price are matched based on when they were received into the order book. The first orders in are the oldest resting orders, and they will be the first out when a match is found.

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.

Previous

Benchmarks

Next

Settlement

  • Role in the Trading Flow
  • Order Book Model
  • Matching Rules
  • Deterministic Execution
  • Execution Events
  • Market Data Implications
  • Fairness Guarantees