# Order Book Simulator: Slippage and Queues

Interactive limit order book: bid and ask depth, market orders that walk the book, slippage, and a limit order waiting in the queue.

## About this tool

A limit order book is the list of all resting buy and sell orders for an asset, sorted by price. Buyers post bids below the market, sellers post asks above it, and the gap between the best bid and the best ask is the spread. Orders at the same price are filled in the order they arrived, which is called price–time priority. A market order trades immediately against the best resting orders and, if it is larger than the quantity at the best price, keeps eating into worse prices. This lab lets you build that picture by hand: send orders, watch the book react and see what each trade really cost you.

## Frequently asked questions

### What is price–time priority?

It is the rule that decides who trades first. Orders with a better price always come first: the highest bid and the lowest ask. Among orders at the same price, the one that arrived earliest is filled first. That is why a trader who joins a busy price level late can wait a long time, or never be filled at all, even though their price is as good as everyone else's in that queue.

### What does it mean that a market order walks the book?

A market order takes whatever liquidity is available, best price first. If you buy 500 shares and only 200 are offered at the best ask, the next 300 are bought at the next price levels up. Your average price is therefore worse than the best ask, and the larger the order relative to the depth of the book, the further it walks and the worse the average becomes.

### How is slippage measured?

Slippage compares what you actually paid with a benchmark, usually the mid price before you traded: slippage = average fill price − mid for a buy, and mid − average fill price for a sell. Half the spread is the minimum you pay on any market order; anything beyond that comes from walking the book. In the lab, try the same order size on a deep book and on a thin one and compare the two numbers.

### Is a limit order always cheaper than a market order?

Not necessarily. A limit order avoids paying the spread, but it may never be filled, and it tends to be filled exactly when the price is moving against you, because someone better informed chose to trade with it. The real comparison is the expected cost including the risk of missing the trade, which the queue part of the lab lets you explore.

## Learn the theory

- [The limit order book](https://quantsandbox.dev/guide/microstructure/limit-order-book): Limit and market orders, price–time priority, depth, how a market order walks the book, and slippage measured against the mid price.
- [Queue position and fill probability](https://quantsandbox.dev/guide/microstructure/queue-position): First-in, first-out queues at a price, how long a limit order waits, the chance it fills, why moving it costs priority, and why fills come before price moves.
- [Price impact and optimal execution](https://quantsandbox.dev/guide/microstructure/price-impact): Temporary and permanent impact, the square-root rule of thumb, splitting a large order over time, and the Almgren–Chriss trade-off between cost and risk.

Open the interactive tool: https://quantsandbox.dev/order-book
