Matching Engines
A matching engine is the system that pairs buy and sell orders on an exchange. Learn price time priority, pro rata matching, auctions and why it matters to you.
A matching engine is the core software of every exchange. It receives buy and sell orders, keeps them in the order book and decides which orders trade with each other, at what price and in what order. Every trade you have ever made on an exchange was decided by a matching engine following a fixed set of rules, usually in millionths of a second.
What a matching engine does#
- Accepts orders and checks them: valid price, size, symbol and risk limits.
- Places resting orders in the order book, sorted by price and arrival.
- Matches incoming orders against the best resting orders on the other side.
- Reports trades to both parties and publishes them to the market data feed.
- Updates the order book and publishes the new best bid and ask.
Price time priority#
Most stock and many futures exchanges use price time priority, also called first in first out (FIFO):
- Price first: the best priced orders trade first. The highest bid and the lowest ask always have priority.
- Time second: among orders at the same price, the one that arrived first trades first.
This is why queue position matters for limit orders and why many traders avoid joining very long queues at round numbers. See Fill Probability and Queue Position.
Other matching rules#
| Rule | How it works | Where used |
|---|---|---|
| Price time (FIFO) | Best price, then earliest order | Most stock exchanges, many futures |
| Pro rata | At the best price, fills shared in proportion to order size | Some interest rate futures |
| Price size time | Larger orders can get priority | Some venues and options markets |
| Displayed before hidden | Visible orders fill before hidden ones at the same price | Most exchanges with hidden orders |
| Auction (call market) | Orders collected and matched at one price at a set time | Opens, closes and reopenings after halts |
Pro rata matching rewards large orders, which is why some traders place oversized orders there and cancel the excess after a fill. FIFO rewards speed, which is one reason high frequency traders invest heavily in latency. See Latency in Trading and High-Frequency Trading.
Auctions#
At the open and close, and after trading halts, many exchanges switch from continuous matching to an auction. Orders are collected for a period, and the engine finds the single price that matches the most volume. See Opening and Closing Auctions.
Speed and fairness#
Modern matching engines process orders in microseconds. Exchanges offer co-location, where trading firms place servers in the same data centre, so that everyone paying for the service has the same distance to the engine. Some venues add deliberate tiny delays, called speed bumps, to reduce the advantage of the very fastest traders. See Co-Location.
Matching engines in crypto and prediction markets#
Centralised crypto exchanges run their own matching engines, usually with price time priority. Decentralised exchanges often use automated market makers instead of order books, where prices are set by a formula based on pool balances. Prediction markets such as Polymarket run an order book for each outcome's shares, matched off chain and settled on chain.
Why it matters to you#
- Your limit order's chance of filling depends on its price and its place in the queue.
- Market orders always take the best available prices first, then walk the book. See Market Orders.
- In auctions, everyone trades at the same price, which can be useful for large or end of day orders.
Frequently asked questions#
What is a matching engine in trading?#
The exchange system that matches buy and sell orders according to set rules and records the resulting trades.
What does price time priority mean?#
Orders at better prices fill first, and among orders at the same price, the earliest one fills first.
Do all exchanges match orders the same way?#
No. Most use price time priority, but some futures markets use pro rata matching, and auctions are used at the open and close.
Sources#
- Wikipedia, Order matching system
3 quick questions on this lesson. Get them all right to finish it.
Turn on JavaScript to take the quiz.
Mentioned in
- Direct Market Access and Sponsored AccessOrders and Execution
- ECNsMarket Structure
- Fill Models, Partial Fills and Order QueuesResearch and Backtesting
- Exchange vs Receive Timestamps and Latency MeasurementProgramming and Data
- Lock-Free Programming and Ring BuffersTrading Infrastructure
- Quant Developer and Trading EngineerThe Trading Industry