ITCH 5.0 order book
complete (November 2026)
https://github.com/devanandanj/hardware-orderbook
What is an Orderbook?
- A real-time list of buy and sell orders of a particular financial instrument, organised by price level. Exchanges use it to match buyers with sellers and show current supply and demand of that particular instrument.
- Stock and Currency Trading: Traders check an order book for a stock or currency pair to see market depth and liquidity before placing a market or limit order.
- Cryptocurrency Exchanges: Crypto traders watch live order books to spot large buy or sell “walls” and gauge short-term price pressure.
Purpose
- This is the project the low-latency Ethernet was built for.
- An order book for one stock, fully in hardware. It reads NASDAQ ITCH 5.0 messages framed in MoldUDP64 off 1G Ethernet, rebuilds the book, and sends back the best bid and offer as one 48 byte UDP packet per book message.
- Target board : Xilinx Virtex-5 LX110T (XUPV5). Same board, same ISE pain.
Tools and technologies
- SystemVerilog RTL, converted to Verilog with sv2v for ISE
- Xilinx ISE 14.7
- C++20 golden model (Orderbook-cpp), my own
- Verilator 5.020 benches, UVM on Vivado xsim with the golden model through DPI-C
- SymbiYosys for formal proofs
- Data feed from a real NASDAQ sample day (BX, 30 July 2019)
Book, not matching engine
- I first thought of it as a matching engine. It isn’t one. ITCH is an outbound feed, and fills already come in as
Emessages. If I matched orders myself I would count every execution twice. - So the job is to rebuild the book exactly as the exchange says it is, nothing more.
- Scope : one symbol, picked at build time. Seven message types :
A,F,E,C,X,D,U. - The price window is fixed at build time too : 16,384 levels per side, which covers a base price ± $81.92.
Block diagram
Design Decisions
- ISE’s XST can’t read SystemVerilog. I didn’t want to write Verilog 2001 by hand, so the
.svfiles stay the source and sv2v converts them before every build. The formal flow reads the same.svfiles through Yosys, which only takes a subset of SV, so I had to give up things like packed struct casts and 2D packed arrays. - Orders are looked up in a 3 way set associative hash table in BRAM, one BRAM bank per way, so a whole set reads in one cycle. A small flip-flop CAM catches sets that overflow. The golden model places orders bit for bit the same way, so if hardware drops an order, the model drops the same one.
- It is not one message per cycle. The shortest book message takes about 21 cycles just to arrive on an 8 bit bus, so a multi cycle FSM has time for several memory accesses and still keeps up with the wire.
- Messages go into the book before the frame’s CRC is known, same as the Ethernet front end. A bad frame is already applied by the time we know, so it sets a sticky
book_taintedbit instead. - The output is a fixed 48 byte packet. Full depth won’t fit on the wire, and a fixed size makes the sender just a register file and a byte counter.
- At one point the project had two snapshot formats, written by hand, that didn’t agree with each other. Now one YAML spec generates the formats for Verilog, C++ and Python, and
gen.pyrefuses anything that doesn’t add up.
Result
Book update : 10 to 19 cycles (80 to 152 ns)
Last message byte to commit : at most 20 cycles (160 ns)
Timing (ISE, 125 MHz) : worst path 7.458 ns of 8 ns
Size : 5,261 LUTs (7.6%), 65 of 148 BRAMs
- Latency is measured from the last byte of the ITCH message. The PHY, the MAC and the header bytes on the wire come before that and aren’t included.
- I replayed a full real trading day of SPY through the whole design in simulation : 260,752 messages. Every snapshot matched the golden model. Only SPY’s messages were framed into that feed, so it didn’t test the symbol filter against mixed traffic.
- The bottleneck is now the output, not the book. Each snapshot takes 114 cycles on the wire, so one link carries about 1.1M snapshots a second, while a back to back feed can send a message about every 32 cycles. If the output fills up the snapshot is dropped and LED 7 lights, so the host sender is paced.
Verification
- Every block has its own Verilator bench against the golden model’s own code, then the whole design is tested from GMII frames in to GMII frames out.
- The snapshot bytes are the trace. The golden model writes the same format, so checking is just a byte diff.
- The UVM bench compares every memory write, in order, against the golden model through DPI-C. A test fails if the rare cases like CAM spills and drops never happened.
- SymbiYosys proves control properties of the book FSM, on a small geometry (2 sets of 1 way, a 1 entry CAM, 16 slots per side). The FSM is the same at any size. It proves every command finishes within the time its own message takes to arrive, and within 25 cycles. I wanted to prove 19, but k-induction couldn’t get there cheaply.
- That the book keeps up with the wire comes from simulation, not the proof : the slowest command takes 19 cycles, the shortest message takes 21 to arrive, and ingress holds one command while the next one arrives.
What’s next
- It only runs in simulation so far. ISE meets timing, so next is loading it on the Virtex-5 and replaying the SPY day over a real cable.
