itch-l3
A C++20 library and program that rebuilds the order-by-order book of every symbol from a day of Nasdaq TotalView-ITCH 5.0, and checks that book against the exchange's own executions and two open-source implementations.
12302019.NASDAQ_ITCH50.gz, from bench-results/compare/pod/12302019.NASDAQ/summary.json, on one vCPU of a rented container whose host, an AMD EPYC 7702P, other tenants shared. Each program was built as its repository publishes it, itch-l3 at commit 3abb3e9, and read the same file, decompressed into memory before timing; a run counted only if it reported the file's 268,744,780 messages. itch-l3 ran twice: in its own book mode, and driven by the harness the other entries share. CppTrader's optimized and aggressive managers index an array of 300,000,000 orders by reference, and this file holds larger references, so they were not run on it.
latency mode on the held-out main file, 01302020.NASDAQ_ITCH50.gz, native build at commit c3a3189, median of 5 rounds, from bench-results/held-out/main-slot-1/summary.json, on one vCPU of a laptop, an Intel Core Ultra 7 256V under WSL2. A percentile is the lower bound of its histogram bucket, and the cost of the timing, 15 ns at p99, is not subtracted. Of the order messages, Order Replace, which removes one order and adds another, has the highest p50, p99 and p99.9.
bench-results/held-out/main/rb/summary.json. After every order message of ten symbols, at ranks 1, 2, 3, 5, 10, 30, 100, 300, 1000 and 3000 by number of order messages, the top five levels on both sides were compared with martinobdl/ITCH at a pinned commit and MeatPy 0.5.0, both run unchanged. All 18,908,365 rows agreed with both, and none was unpaired. The rows came from itchl3 dump at commit c3a3189 on the same laptop. Key metrics
- messages of the main-market file of Nasdaq's held-out day, 2020-01-30, decoded with completeness met; all 8,415,610 Order Executed messages named a live order at the best price of its side
- 423,285,709
- symbols whose top five levels agreed with martinobdl/ITCH and MeatPy after every order message, 18,908,365 rows; the ten sit at ranks 1, 2, 3, 5, 10, 30, 100, 300, 1000 and 3000 by number of order messages
- 10 of 10
- messages per second on the held-out main file through framing, decoding and the book, on one vCPU of a laptop,
nativebuild, median of 10 rounds; decompression, about 18.8M per second, is timed apart - 7.30M
- p99 time per message over all messages of the held-out main file in
latencymode,nativebuild, which times every message and runs at 4.57M messages per second; the cost of the timing, 15 ns at p99, is not subtracted - 564 ns
The laptop is an Intel Core Ultra 7 256V under WSL2 with GCC 13.3.0, and each run used one vCPU whose physical core, performance or low-power, Windows chose; work on the Windows side was not stopped during the slots. The held-out BX file of the same day, 53,268,643 messages, also met every criterion. The comparison's figures come from a rented container and are not compared with the laptop's. The results were measured at the tag protocol-v2, commit c3a3189, and the comparison at commit 3abb3e9; release 1.0.0 adds packaging after them and leaves every compile and link command of the measured code unchanged. Benchmarks and results
Problem and goals
TotalView-ITCH 5.0 is Nasdaq's binary feed of every displayed order: each add, execution, cancel, delete and replace, for every symbol. itch-l3 reads a day of it from Nasdaq's public sample files as a gzip stream, decodes all 22 message types, and keeps every displayed order in its place in the queue of its price level. One thread does all of it, and nothing is allocated after start. Release 1.0.0 installs as a CMake package: find_package(itchl3) gives itchl3::book, the decoder and the book, and itchl3::study, which adds the checks.
The rebuilt book is checked two ways. R-a uses the exchange's own reports: every execution, cancel, delete and replace must name a live order of its symbol, and every Order Executed message must hit the best price of its side. R-b compares the top five levels after every order message of ten symbols with two open-source implementations run unchanged on the same file, martinobdl/ITCH in C++ and MeatPy in Python.
The code and the checks were developed on the two files of 2019-12-30. Version 2 of the protocol holds out both files of 2020-01-30: it was tagged as protocol-v2 and pushed before either was decoded, and itchl3 refuses them unless built from a clean tree that contains the tag. Every run on them is logged and committed. One deviation stands beside the main file's results: before the tag, a test of that guard decoded a 2,000,000-byte copy of the file's start, and its outputs were deleted unread. On the held-out main file, 423,285,709 messages, every criterion was met.
The speed comparison follows a method tagged before its rented container started. itch-l3 and four other published implementations, each built as its repository publishes it, read the same file decompressed into memory, and a run counts only if it reports the file's message count. charles-cooper/itch-order-book, which keeps a price and a total per level and no queue of orders, was the fastest on all three files, the two BX files and the main-market file of 2019-12-30, and on the last ran 2.9 times as fast as itch-l3. On that file itch-l3 and groovg/itch-book are level, their ranges overlapping, and both are faster than bbalouki/itchcpp and CppTrader's market manager.
Architecture
The .gz file is read as a stream through zlib's API, linked against zlib-ng, in 1 MiB blocks; a frame cut by a block boundary is carried into the next. The framer checks each frame's length against a table of the types' lengths, and the decoder reads fields at fixed offsets. Book routes each message by its stock locate code to that symbol's book, whose two sides are sorted arrays of price levels, and finds orders through an open-addressing index into a pool. These parts make up the library itchl3::book. itchl3::study adds the checks: counts of what the protocol defines, state digests that check every timed run against the correctness run, and dumps of the top levels of chosen symbols, which tools/compare.py compares row by row with the rows of martinobdl/ITCH and MeatPy. One thread runs the reader, the decoder, the book and the checks.
Key decisions
-
D016 Criteria tagged before the judged files are read
Each protocol was tagged and pushed before the files it judges were decompressed or decoded:
protocol-freezefor the main file of 2019-12-30, developed on the BX file of that day, andprotocol-v2for both files of 2020-01-30, developed on both files of 2019-12-30, apart from one recorded test on a 2,000,000-byte copy of the held-out main file's start.itchl3knows a held-out file by its name, its size or the hash of its first MiB, and refuses it unless built from a clean tree whose commit contains the tag. Every run on it is logged and published, and the verdict is the first complete run, which leaves no room to rerun until a criterion is met. -
D009 Price levels chosen on real order flow
A
std::map, a sorted array with the best price at the end, and an array indexed by price ticks share one interface and one test suite. On the BX file of 2019-12-30, 82.5% of updates land at the best price and 97.5% within 4 levels of it. Measured again on that file after the price-indexed array learned to recentre its window, the sorted array ranhandlermode,nativebuild, on the laptop at 24,375,431 messages per second, against 20,699,911 for the price-indexed array and 16,659,048 for the map; its range over 10 rounds overlaps neither of the others, so it stays the default by the rule fixed before the measurement. -
D007 Orders in a pool, found through an open-addressing index
Orders live in a preallocated array whose slots never move, so each level's queue links them by slot number. An open-addressing index with linear probing maps each 64-bit order reference to its slot. Timed runs size both from the peak of live orders, 1,925,638 on the held-out main file, and exceeding a capacity stops the run.
std::unordered_mapwould allocate once per order and chase a pointer per lookup. -
D012 No allocation after start
Pools, index, books and buffers are allocated at start. A test counts calls to the global allocation functions during a synthetic day and requires zero after start. An allocation on the path of a message would show up in the latency tail and make runs depend on the allocator's state.
Limits
-
An error all three share is invisible
R-b counts a row as agreeing when this book agrees with both references, so an error that all three implementations share leaves every row in agreement. R-a checks only what an execution, cancel, delete or replace message reveals about the order it names; an error in a level behind the best price is outside it.
-
No cents at 10,000 and above
martinobdl/ITCH prints prices with six significant digits. On the held-out main file, 8,194 rows have a price of 10,000.0000 or more in their five levels; all agreed, but the comparison with martinobdl/ITCH cannot see their cents. The comparison with MeatPy covers them in full, as integers.
-
Slower on the main file
In
handlermode,nativebuild, the laptop processed the held-out BX file 3.3 times as fast as the held-out main file, 23,830,360 against 7,302,258 messages per second. For this code no run isolates the cause. -
The comparison measures different work
charles-cooper and two of CppTrader's managers keep totals per level and no queue of orders, and no run isolates how much of a gap that accounts for. The other programs are checked by their message count only, so the comparison says nothing about their correctness. It ran on one host shared with other tenants, whose load average was 17.54 to 21.54 at the slots' starts.