How an order book works: the queue behind every price

How an order book works: the queue behind every price
Short answer

An order book is two sorted lists: everyone willing to buy at a stated price, and everyone willing to sell at a stated price. The highest buy and the lowest sell sit facing each other at the top, and the gap between them is the spread. What gets called 'the price' is just those two top rows, which means a price is only valid for the quantity sitting on that row.

An order book is two lists. One holds every resting offer to buy at a stated price, sorted highest first; the other holds every resting offer to sell at a stated price, sorted lowest first.

The highest buy and the lowest sell sit facing each other at the top. That pair is what gets displayed as “the price”. Everything else about execution follows from this one fact: a quote is not a value the market holds, it is two specific orders that two specific participants have left sitting there, each of which can be cancelled at any moment.

Why a market needs two queues instead of one price

A price cannot exist without someone willing to act on it. If you want to sell something, your price only means anything if a buyer exists at that level. So a venue cannot simply store a price. It has to store intentions.

That is what a limit order is: a stated intention, resting. “I will buy 5 units at 100.” “I will sell 3 units at 101.” Neither trades yet, because nobody wants both sides of the same number. The venue files the buy in the bid queue and the sell in the ask queue, and waits.

The two queues are sorted in opposite directions for one reason. A buyer who offers more should be served before a buyer who offers less, and a seller who asks less should be served before a seller who asks more. Sorting bids high-to-low and asks low-to-high puts the most competitive order of each side at the front. The result is that the best bid is always below the best ask. If they ever overlapped, the overlapping orders would simply trade and the overlap would vanish.

The gap left over is the spread. It is not a fee anyone charges. It is the width of the disagreement between the most eager buyer and the most eager seller.

What actually makes a trade happen

Nothing in the book trades on its own. A trade requires someone to cross the gap.

That is a market order: an instruction to trade now at whatever price the book offers. It does not join a queue. It consumes the front of the opposite queue, one price level at a time, until the full quantity is filled.

When two resting orders sit at the same price, venues generally fill them in the order they arrived. This is price-time priority: better price first, and among equal prices, earlier arrival first. It is why a limit order placed at the current best price is not guaranteed a fill even when trading happens at that price. There may be a hundred units ahead of yours that have been waiting longer, and the incoming market orders may only consume twenty of them before the price moves away.

So the book sorts you twice. Once on how competitive your price is, and once on how long you have been patient.

What this costs you on a real order

Here is the part that shows up in your account. Every price level holds a finite quantity. “The price” applies only to the quantity on that one row.

Suppose a venue’s ask side looks like this, with entirely made-up numbers:

Ask priceQuantity resting
100.002 units
100.055 units
100.1020 units

The displayed price is 100.00. You send a market order to buy 6 units.

The first 2 units fill at 100.00, costing 200.00. The next 4 come from the level behind it at 100.05, costing 400.20. Your total is 600.20 for 6 units, an average of about 100.033 each. You paid roughly 0.03% above the price you saw, and the quote never lied to you. It was simply only ever a quote for 2 units.

That difference between the price you saw and the average price you got is slippage, covered in more detail in what is slippage. Notice that nothing went wrong here. No delay, no bad connection, no hidden markup. The book worked exactly as designed, and the cost came entirely from asking for more quantity than the top row held. If you had used a limit order at 100.00 instead, you would have bought 2 units and the remaining 4 would have joined the bid queue, waiting. Different mechanism, different outcome, and the trade-off between the two is the subject of market order vs limit order.

The mistake: reading the top row as the whole market

The specific error is treating a quoted price as a property of the asset rather than as a property of two resting orders.

It produces three concrete miscalculations.

  1. Sizing against the quote instead of against the depth. Someone decides a position is affordable because the price looks right, without checking how much quantity sits at that price. The order then walks several levels deep. The fix is to size against what is actually resting, and to work out the position before sending it rather than after, which is what a position size calculator is for.
  2. Reading a narrow spread as cheap execution. A spread measures the cost of trading the top row. If the top row is thin, a narrow spread is a cheap quote on an amount you were never going to trade. Thin books can show very tight spreads precisely because there is so little resting there.
  3. Assuming a stop will fill at its trigger price. A stop is not a resting order in the book at that level. It is an instruction that becomes an order when the price is touched. What it becomes then has to cross the book like anything else, and in a fast move the levels near the trigger may already be gone. This is the reason stop-limit orders exist, and also the reason they can fail to fill at all.

There is a fourth habit worth naming. The book you see on screen is a snapshot of something that changed while it was being transmitted. Orders are added and cancelled continuously, and in most markets cancellations vastly outnumber trades. The display is a photograph, not a window.

How to read a book next time you see one

Look at the two top rows and note the gap. That is the spread, and the cost of an immediate round trip at the smallest size.

Then look down. Count how many levels you would need to consume for the size you actually intend to trade, and add up what that average would be. If the quantity you want is larger than the first two or three levels combined, the displayed price is not your price, and no amount of speed or timing will make it your price. The only levers you have are size, order type, and patience.

That is the whole mechanism. Two sorted queues, a gap between them, finite quantity on each row, and a rule that serves better prices first and earlier arrivals next. Fees and spreads differ between venues, which is a separate comparison and covered in compare, but the queue behaves this way everywhere.

Education only, not financial advice, and trading carries a risk of loss.

Key facts

  • A bid is a resting offer to buy at a stated price; an ask is a resting offer to sell at a stated price.
  • Bids are sorted highest first and asks lowest first, so the two best prices always face each other at the top of the book.
  • A trade happens only when one side agrees to cross the gap between the best bid and the best ask.
  • Most venues fill orders at the same price by time of arrival, so the order that rested longest is filled first.
  • Every price level holds a finite quantity, so an order larger than the top level walks into worse prices behind it.
  • Limit orders add quantity to the book and market orders remove it, which is why the same trade idea can produce very different fills.

Frequently asked

Why does the quoted price change even when nobody trades?

The quote is the best bid and best ask, and those are just resting orders. If the person holding the best ask cancels it, the next-lowest ask becomes the new best, and the quoted price moves. No trade occurred. Cancellations and new orders move a quote constantly without a single unit changing hands.

What is depth, and why does it matter more than the spread?

Depth is the quantity resting at each price level, not just the best one. A narrow spread with almost nothing behind it will give you a worse average fill than a slightly wider spread with large quantity at the top. The spread tells you the cost of trading small; depth tells you the cost of trading big.

Does forex have an order book if it has no central exchange?

Forex has many order books rather than one. Liquidity providers quote into venues and aggregators, each with its own book, and your broker shows you a price derived from whichever streams it receives. The mechanism is identical, but the book you trade against is a slice of the market rather than the whole of it.

Can I see the full order book?

Sometimes. Many crypto venues publish aggregated depth, showing quantity per price level without identifying who placed each order. Elsewhere you may see only the top of the book. Either way, what is published is a snapshot that was already out of date by the time it reached your screen.

Risk warning: trading is high risk and most retail accounts lose money. Education only, not financial advice.

Run the numbers