How Exchanges Match Orders
Matching engine mechanics, price-time priority queues, maker/taker economics, and understanding the infrastructure that processes your trades.
From Thrive on YouTube
Watch the matching Thrive video
Welcome to Thrive | Crypto Market Intelligence Platform for Traders
Education only. Not financial advice.
The Matching Engine
When you click "buy" on an exchange, your order enters a matching engine: a high-performance system that pairs incoming orders with resting orders on the opposite side of the book. This happens in microseconds on major exchanges. The matching engine is the invisible referee of every trade: it decides who gets filled, at what price, and in what order. Understanding how it works is understanding why your fill price is rarely the price you saw on the screen.
Price-Time Priority
Nearly every exchange uses price-time priority to determine which resting order gets filled first. The best price always wins: if someone is willing to sell at $60,000 and another at $60,001, the $60,000 order fills first regardless of when it was placed. Among orders at the same price, the earliest order gets priority. First come, first served at each price level.
This creates a queue at every price level. If there are 50 BTC of sell orders at $60,000, a market buy order for 10 BTC fills against the first 10 BTC that were placed at that level. The remaining 40 BTC keep their queue position. New sellers at $60,000 go to the back of the line behind the existing 40 BTC.
How Limit Orders Queue
A limit order that does not immediately cross the spread sits in the book, passively waiting for someone to trade against it. Your limit buy at $59,800 when the market is at $60,000 will only fill if the market drops to your level and a market sell order (or a lower-priced limit sell) matches against it. Your order provides liquidity. You are paid for this patience through maker fee discounts or rebates.
The depth of limit orders at each price level determines how much size the market can absorb without moving price. Thin order books (few resting orders) mean large trades cause significant price impact. Deep order books (many resting orders) can absorb large trades with minimal slippage. This is why the same market order fills differently at 3 AM versus 3 PM: liquidity follows the clock.
Market Orders Consuming Depth
A market order demands immediate execution at the best available price. It walks through the order book, filling against resting orders level by level until the order is complete. A market buy of 100 BTC might fill 30 BTC at $60,000, 40 BTC at $60,010, 20 BTC at $60,025, and the final 10 BTC at $60,050. Your average fill is $60,016, not the $60,000 you saw. This is execution slippage, and it is proportional to your order size relative to available depth.
Order Types and Their Processing
| Market order | Execute immediately at the best available price. Guaranteed fill, uncertain price. Crosses the spread and pays taker fees. Use when speed matters more than price. |
| Limit order | Execute only at a specified price or better. Uncertain fill, guaranteed price. Sits in the book until matched. Earns maker fee discount. |
| Stop-market | Triggers a market order when a price level is reached. Used for stop-losses. The trigger price and fill price can differ significantly in fast markets. |
| Stop-limit | Triggers a limit order at the stop price. Avoids the slippage of stop-market, but risks not filling if price gaps through your limit. |
| IOC (Immediate or Cancel) | Fill whatever is immediately available, cancel the rest. Partial fills are accepted. Used when you want some fill but not a resting order. |
| FOK (Fill or Kill) | Fill the entire order immediately or cancel it entirely. No partial fills. Used for all-or-nothing execution. |
| Post-only | Rejects the order if it would immediately match (cross the spread). Guarantees maker fee. Used by market makers to avoid accidentally taking liquidity. |
From Click to Fill
Between clicking "buy" and receiving a fill confirmation, your order travels through your internet connection to the exchange's servers, enters a queue, is validated (margin check, risk check), enters the matching engine, and executes. On a major exchange with a good connection, this takes 10–100 milliseconds for a retail trader. For co-located high-frequency firms, it takes microseconds. In those milliseconds, the order book can change: other orders can arrive first, prices can move, and your expected fill becomes reality plus slippage.
Why your fill differs from the screen
Put this lesson to work
Free on Thrive, no account needed.