Limit Order Book

A low-latency matching engine I wrote in C++: flat-array price levels, intrusive linked lists, arena allocation and a bitmap for best-price tracking. It's compiled to WebAssembly, so the matching runs on your machine, not on my server. Place orders, or turn on random flow and watch the book move.

Best bid
—
Best ask
—
Spread
—
Live orders
—
Trades
—
Operations
—
Loading engine…

New order

Prices move in 0.01 ticks.

Modify

Amending downwards keeps your place in the queue; amending upwards sends you to the back.

Depth

—mid

Cumulative quantity: bids left, asks right.

Trades

  • No trades yet.

How it works

Flat array of price levels

Price ticks index straight into Level levels_[65536]. Finding or inserting a level is O(1) with no pointer chasing and no red-black tree node allocation, unlike a std::map book.

Intrusive lists, arena memory

Each level is a doubly-linked FIFO of orders held by 32-bit indices rather than pointers: half the memory and friendlier to the cache. Orders come from a pre-allocated arena with a free list, so the hot path never calls malloc.

Bitmap best price

One bit per price tick. When a level empties, the next best price comes from __builtin_ctzll / clzll over the bitmap: in practice one or two 64-bit words.

Open-addressed id map

Cancels look up order ids in a linear-probing hash table with a splitmix64 finalizer, which beats unordered_map's chaining, where every lookup costs at least one pointer dereference and usually a cache miss.

About the numbers

The operation counter above is honest about throughput, but this page deliberately does not advertise per-operation latency. Browsers clamp performance.now() to somewhere between roughly 5 µs and 100 µs to defend against timing attacks, which is orders of magnitude coarser than the operations being measured. Latency percentiles only mean something when measured natively with rdtscp on a pinned core — I'll publish those as a static chart, with the benchmark script, rather than pretend the browser can measure them.

← All projects