TradeLabs AILearn

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.

Intermediate3 min readUpdated 3 Oct 2026
Markdown
Lesson 18 of 38

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#

  1. Accepts orders and checks them: valid price, size, symbol and risk limits.
  2. Places resting orders in the order book, sorted by price and arrival.
  3. Matches incoming orders against the best resting orders on the other side.
  4. Reports trades to both parties and publishes them to the market data feed.
  5. 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#

RuleHow it worksWhere used
Price time (FIFO)Best price, then earliest orderMost stock exchanges, many futures
Pro rataAt the best price, fills shared in proportion to order sizeSome interest rate futures
Price size timeLarger orders can get prioritySome venues and options markets
Displayed before hiddenVisible orders fill before hidden ones at the same priceMost exchanges with hidden orders
Auction (call market)Orders collected and matched at one price at a set timeOpens, 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#

Check your understanding

3 quick questions on this lesson. Get them all right to finish it.

Turn on JavaScript to take the quiz.

Finished this lesson?Sign in to save your progress across devices.
Next lessonOrder Routing and Smart Order RoutingOrder routing decides which venue your order is sent to. Learn how brokers route orders, smart order routers, payment for order flow and how routing affects fills.

Mentioned in