exchange book →HFT engine →

Inside the exchange — one order, matched in microseconds

one order · ambient traffic pausedorders inmarket datatrades / fillsrisk / surveillance
order in1/22

An order leaves a co-located trading member — one of thousands of authenticated sessions — and arrives at the order-entry gateway, the only door in. Follow this single order to a matched trade.

Trading membersexternal · co-locatedOrder entry & validationMatching engine — the hot pathper-symbol shard · single writer · in-memory CLOBMarket-data disseminationTrade & clearingRisk & surveillanceorders in →← market data out · UDP multicast to all memberstrades → clearingMember AOE sessionMember BOE sessionMember …thousandsOrder-entry gatewayTAP/IML · session authValidationprice band · qty freeze · order valueorder valueSequencer + timestamp0/s inOrder ack · drop-copyprivate confirm to ownerSymbol routershard by instrumentCentral limit order book18 levelsprice-timeOrder typesLIMIT · MARKET · IOC · SLMatch loopmatch 6.2 µsIn-memory stateno DB on the hot pathTick-by-tick (TBT)every order & tradeMarket-by-price5 / 20 depth levelsSnapshot / retransmitgap recoveryMulticast (A/B)UDP · two linesBroadcast to the marketlast 2500.0Trade generator0/s matchedClearing hand-off→ clearing corp · T+1 netPrice bands & circuit breakershalt symbol / market on breachbreachMarket surveillancespoofing · manipulation

Trace mode. The ambient traffic is paused so you can follow exactly one order — and every module it touches. Press next ▸ to walk it: a member order is validated and sequenced, the matching engine shards it to the order book and crosses it; a trade prints to clearing and a private ack returns, then the book change is disseminated to the whole market, with circuit breakers and surveillance watching. Switch to Live traffic to see it all at once. Hover any module for its job and exact data in/out.

Explained in the book

zoom in

The two hot sub-systems, broken down

The overview shows the whole venue. Here the two stages that decide fairness and price are opened up into their own sub-components, animated with the actual work each one does — step through them.

1Inside the sequencer & order gate

Every order passes a pipeline of small gates before it can be matched. The sequence-assign step — a single atomic counter — is the fairness the exchange can never take back: it fixes your place in the queue.

SEQUENCER · ORDER GATE
step 1/15

The order gate is a pipeline of small, independent sub-components. Watch one order pass through each — and where the sequencer stamps the fairness it can never take back.

01Session RX

read frame · identify member

02Decode

binary → order fields

03Auth & entitlement

segment / instrument allowed?

04Rate gate

per-session token bucket

05Price-band check

within the day's band?

06Qty-freeze check

under the freeze size?

07Order value · tick · lot

value & tick / lot valid?

08Risk / limits

member exposure & margin

09Sequence assignfairness

atomic monotonic counter ++

10PTP timestampfairness

hardware clock · nanoseconds

11Enqueue → matching

inbound ring · per shard

12Ack + drop-copy

confirm back to member

gate idle — waiting for the next order

sequence #

4,80,191

PTP timestamp

statusidle

inbound ring → matching shard

0accepted
0rejected
Explained in the book

2Inside the matching loop

The cycle the engine runs for every order: marketability → price-level lookup → FIFO front → cross & fill → trade generate → book update → walk-or-rest → market-data emit. Watch the live order book mutate at each sub-step.

MATCHING LOOP
step 1/19

The matching loop is a tight cycle of sub-components. Watch one aggressive order run the cycle until it is filled.

01Marketability

does it cross best opposite?

02Price-level lookup

bitmap index → best level

03FIFO front

oldest order at the level

04Cross & fill

min(qty) trades

05Trade generate

price · qty · ids · ts

06Book update

pop filled · update totals

07Walk or rest

next level, or rest in queue

08Market-data emit

publish change + trade

price · queue (oldest first →)asks

100.65
25·A4
100.60
40·A3
100.55
50·A130·A2
bid 100.50spreadask 100.55
100.50
40·B120·B2
100.45
60·B3

bids

trades:
Explained in the book

How a stock exchange works — the matching engine, end to end

An exchange is, at its core, one machine: a matching engine that keeps a central limit order book for every instrument and crosses orders by strict price-time priority. Members send orders over authenticated sessions; the exchange validates them, stamps each with a sequence number and timestamp, matches them in microseconds, prints trades, hands them to clearing, and broadcasts every change to the whole market at the same instant. The animation above traces one order through that whole path — the venue's own engine, not a trading firm's.

Built by Ashutosh Pandeyabout →