Continuous double auction

The continuous double auction (CDA) is the matching engine underneath virtually every modern electronic exchange. Buyers and sellers post orders at any moment into a shared limit order book; whenever an incoming order is compatible with the best resting order on the other side, a trade prints immediately. There is no auctioneer and no pricing formula; price emerges from a continuous sequence of bilateral matches. It is fast and gives immediacy, but the same continuous-time operation that makes it responsive is what rewards latency and lets quick traders snipe stale quotes, a weakness that motivates the discrete-time frequent batch auction.

The limit order book and price-then-time priority

The book aggregates every resting order on two sides: bids (offers to buy, the best being the highest price) and asks (offers to sell, the best being the lowest). A limit order that cannot execute on arrival rests in the book, providing liquidity; a marketable order consumes it. Matching follows price-then-time priority: better prices are filled first, and ties at a given price are broken by earliest arrival (FIFO).

In mechanisms/cda.py the book is a LimitOrderBook holding two heaps, bids in a max-heap, asks in a min-heap, with a sequence counter to enforce time priority within a price level. An Order carries a side ("buy"/"sell"), price, qty and trader. Calling submit(order) matches it greedily against the opposite side while the prices cross, returns the list of Trades it generated, and rests any residual quantity. The book exposes best_bid(), best_ask(), spread(), mid(), and a depth() ladder of (price, qty) levels on each side.

The bid–ask spread and how marketable orders execute

The bid–ask spread is the gap between the best ask and the best bid,

$\text{spread} = a^\star - b^\star, \qquad \text{mid} = \tfrac12\,(a^\star + b^\star),$

where $b^\star$ is the best bid and $a^\star$ the best ask. While $b^\star \le a^\star$ the book is uncrossed and nothing trades; an order is marketable only when it crosses the spread, a buy with $\text{price} \ge a^\star$ or a sell with $\text{price} \le b^\star$. In _match, the incoming order walks the opposite heap, filling $\min(\text{incoming.qty},\ \text{resting.qty})$ at each level and stopping the moment the prices no longer cross.

Each trade prints at the resting (maker) price, not the aggressor's limit, the standard CDA rule, so any price improvement accrues to the taker who crossed the spread. A large marketable order walks up (or down) the book through successively worse levels, so its average execution price degrades with size against the available depth(), the order-book analogue of an AMM's slippage.

Zero-intelligence traders (Gode & Sunder, 1993)

A striking result about the CDA is how little the traders need to know for the mechanism to work. Smith (1962) had already shown that human double-auction markets converge fast to competitive equilibrium even with few participants and no one knowing the aggregate supply/demand curves. Gode & Sunder (1993) pushed this to the extreme with zero-intelligence (ZI) traders: agents that submit random bids and asks, subject only to a budget constraint, buyers never bid above their private value; sellers never ask below their cost, so no trade is ever unprofitable.

Even these random, budget-constrained traders drive the CDA to near the competitive equilibrium price and capture almost all the available gains from trade. Measuring this by allocative efficiency, realized surplus as a fraction of the maximum feasible surplus,

$\eta = \dfrac{\sum_{\text{trades}} (v_{\text{buyer}} - c_{\text{seller}})}{\max\text{ feasible surplus}} \approx 1,$

ZI traders reach near-100%. The lesson, "the market is a partial substitute for individual rationality", is that the price-then-time-priority matching and the budget constraint do most of the allocative work, not the cleverness of the participants. (The trade-off: ZI prices are far more volatile than human ones, since nothing damps the randomness; later ZIP and GD agents add adaptive bidding to recover the smoother price paths human markets exhibit.) The demo examples/sim_cda.py runs budget-constrained random traders against the LimitOrderBook and measures this efficiency.

Latency, quote-sniping, and the case for batching

Because the CDA processes orders in continuous time and serializes them by arrival, it bakes in a speed race. When new information arrives, the first trader to react can pick off ("snipe") the stale quotes still resting in the book before the maker can cancel them, a structural arbitrage that rewards being microseconds faster rather than better informed. Liquidity providers, anticipating this adverse selection, widen their spreads to compensate, so the latency race ends up taxing everyone through worse prices.

Budish, Cramton & Shim (2015) framed this as the central design flaw of the continuous market, "the high-frequency trading arms race", and proposed replacing continuous matching with frequent, discrete clearing. The frequent batch auction collects orders over a short interval and clears them all at once at a single uniform price, so that being first within an interval confers no advantage: the speed contest collapses into competition on price, and the sniping incentive disappears.

Watch a live order book

Limit orders rest in the book; marketable orders cross and print trades at the resting (maker) price. The shaded band is the bid–ask spread and the dark line is the last trade, price discovery, one order at a time.

Try it: sweep the book

A market buy sweeps the resting asks cheapest-first, each fill at the resting (maker) price, so a larger order walks up the book and pays a higher average. Book: 4@98, 3@100, 5@102. Set your order's size and limit price.

Code: mechanisms/cda.py · Demo: examples/sim_cda.py · Related: frequent batch auction · Research: perps-cda-monteprediction.md