Quant engineering lab

Make price-time priority, partial fills and sequence recovery observable. Predict the result before advancing the system.

Model contract. One instrument, integer ticks and units, maker-price execution, FIFO within a price. Same-price size reduction keeps priority; a price change or size increase loses it. Market remainders expire. This is a deterministic teaching model; exchange-specific rules and production latency require a separate implementation.

01 · Matching engine

Submit an order or load the FIFO example.

Bids

IDTicksUnitsPriority
No resting orders

Asks

IDTicksUnitsPriority
No resting orders

Trades · 0

SequenceMaker → takerPriceUnits
No fills yet
Accepted event log · 0
[]

02 · Market-data gap and recovery

Deliver 1, then 3. The book must stop at 1 while 3 is buffered. Deliver missing 2 to drain the buffer, or recover from a trusted snapshot through 3. Duplicate delivery is idempotent.

LIVE · Waiting for sequence 1.

Bids

IDTicksUnitsPriority
No resting orders

Asks

IDTicksUnitsPriority
No resting orders

03 · Explain the design

04 · Measure native code

Compare a contiguous scan with a dependent shuffled traversal using the same dataset and checksum. Then stress a bounded C++ SPSC queue with one million FIFO values. Predict first, compile locally, and explain the observations.

c++ -std=c++20 -O3 -pthread -Wall -Wextra latency_lab.cpp -o latency_lab
./latency_lab

The program reports 21 whole-batch samples and compiler metadata. Batch percentiles are not per-message latency. The queue exercise assumes one producer, one consumer and 64-byte padding; discuss those constraints before extending it.