About this simulation

This simulation models a live limit order book, the core mechanism behind modern electronic exchanges. Buy (bid) and sell (ask) limit orders arrive continuously at random prices near the mid, while a smaller share of orders are market orders that walk the book and fill immediately at the best available price. Whenever a bid meets or crosses an ask, the matching engine executes a trade at their midpoint under continuous double-auction rules, and the bid-ask spread you see is a direct measure of how much liquidity is resting near the top of the book.

🔬 What it shows

A continuous limit order book with price-time matching: the book depth chart shows resting bid and ask quantities by price level, the price chart tracks best bid, best ask and the mid-price over time, and the recent-trades log records every fill as buy, sell or matched-cross execution.

🎮 How to use

Use the Order arrival rate (λ) slider to control how often new orders hit the book, and Price volatility (σ) to widen or narrow the random-walk drift of the mid-price. The Depth levels shown slider changes how many price levels are drawn in the book. Toggle HFT mode to multiply the arrival rate by 5×, simulating a high-frequency trading environment, and use Pause/Reset to freeze the simulation or reseed the book from scratch.

💡 Did you know?

Roughly 80% of the simulated order flow is passive limit orders that add liquidity, while only about 20% are aggressive market orders that take it. This 4:1 ratio mirrors real markets, where the majority of order-book activity is quoting and cancelling rather than immediate execution.

Frequently asked questions

What is a limit order book?

A limit order book is a list of all outstanding buy and sell orders for an asset, organised by price. Buy orders (bids) are sorted from highest to lowest price and sell orders (asks) from lowest to highest, so the "best bid" and "best ask" sit at the top of each side. In this simulation, bids and asks are stored in separate price-to-quantity maps and redrawn every frame as a depth chart.

What is the bid-ask spread and why does it matter?

The spread is the difference between the best ask and the best bid — the gap you would immediately lose by buying and reselling instantly. A narrow spread signals a liquid, competitive market with many resting orders close to the mid-price, while a wide spread signals thin liquidity or high uncertainty. In the simulation the spread is recalculated every tick as best ask minus best bid and displayed live in the stats panel.

How does a trade actually get matched?

Whenever the best bid price is greater than or equal to the best ask price, the two orders cross and the matching engine fills them at their midpoint, reducing both quantities and removing any price level that reaches zero. Market orders instead walk directly through the opposite side of the book, consuming price levels from best to worst until the requested quantity is filled, which is why large market orders can move the price more than small ones.

What does HFT mode change?

Enabling HFT mode multiplies the order arrival rate (λ) by five, so orders are generated and matched five times more frequently. This compresses the same statistical process into a shorter time window, producing a busier book, tighter average spreads, and faster price discovery — illustrating how high-frequency participants can increase quote turnover without changing the underlying matching logic.

Why does the mid-price drift randomly instead of following a trend?

Between order arrivals, the mid-price is nudged using a small geometric random walk driven by the Price volatility (σ) slider, similar to the diffusion term in a geometric Brownian motion model of asset prices. This keeps the simulated market moving even during quiet periods and lets you see how higher σ produces a choppier price chart and, indirectly, a wider realised spread as new limit orders are placed further from the previous mid.