FREE4/4+0ACC--

The Order Book Engine - matching engine practice

DEV2G · THE ORDER BOOK ENGINE
SPEC 11 CHECKS
BUDGET 5x
PRICE-TIME PRIORITY · O(1) CANCEL

What does your cancel cost?

Nearly everyone writes a working book. The follow-up - “now cancel is on the hot path” - is the actual question.

THE SPEC

Run the feed and every check reports here.

THE LATENCY GATE

Latency is only measured once every correctness check passes.

R RUN THE FEED · S REVEAL SOLUTIONBUDGET 5x REFERENCE

About The Order Book Engine

Implement a price-time-priority limit order book in the browser, pass an 11-check matching script, then beat a latency gate built around O(1) cancels.

You are given starter JavaScript for createBook(), a limit order book with four operations: add(id, side, price, qty) returns an array of trades and rests any unfilled quantity; cancel(id) returns true if the order was removed and false if it is unknown or already gone; bestBid() and bestAsk() return a price or null for an empty side. Matching follows price-time priority - best price first, then oldest at that price - and every fill prints at the resting (maker) order's price, not the incoming taker's. The starter stub rests orders without matching, scans on cancel, and returns null for both best-price queries; you edit it in the on-page editor.

Run the feed executes your code in a sandboxed Web Worker against a fixed 11-step script: three sells rest (5 and 3 at 101, 10 at 102), a buy at 100 rests without crossing, a buy of 6 at 101 must sweep the first ask for 5 then the second for 1, a cancel of the partially filled ask must return true, cancelling it again and cancelling an unknown id must both return false, a buy of 5 at 102 must trade with the 102 ask while skipping the cancelled order, and best bid and best ask must read 100 and 102. Each step shows PASS or FAIL with the expected and actual values on a failure. A run that hangs is killed after a timeout with a hint that a scanning cancel is the usual cause.

Only once all 11 checks pass does the latency benchmark run: 6,000 orders are rested across 20 price levels and then every one is cancelled, timed for both your engine and a reference O(1) implementation in the same worker (both JIT-warmed, medians of repeated runs), so a slow machine moves both numbers together rather than changing the verdict. You pass the gate if your time is at most 5x the reference. A Reveal solution button swaps in the full reference code at the cost of a revealed mark on your progress record, and Reset restores the starter stub.

Why quant interviews test this

Build me a limit order book is arguably the signature quant developer interview question - it tests data-structure selection, exact spec adherence (price-time priority, maker pricing, partial fills), and cost reasoning in one problem. As the game's brief notes, nearly everyone writes a working book; the follow-up about what cancel costs on the hot path is what separates candidates.

The two-grade structure mirrors how the real interview is scored: correctness gets you to the follow-up, and the follow-up is a complexity conversation. Being able to say cancel is O(1) via an id index plus tombstones, and why splice would quietly reintroduce O(n), is a prepared answer to the exact question the interviewer is holding.

The The Order Book Engine guide covers how scoring works, the strategy that wins, a worked example and the mistakes most players make.

More Quant Dev games