6 · The book Draft
Order-book references
On this page
Reading
WK Selph, “How to Build a Fast Limit Order Book” (2011), is a blog essay on a per-order (L3) book: a price-sorted tree of price levels per side, a doubly linked list of orders at each level, hash maps from order id and from price, and pointers to the best bid and best offer. Read it for what the per-order book adds, which is cancelling by order id and keeping each order’s place in the queue, and which this chapter chose not to build; it also remarks that a sparse array can replace the tree. The original blog was deleted, so the post survives as copies: the title and a pointer to the text are at http://howtohft.blogspot.com/2011/02/how-to-build-fast-limit-order-book.html, and a text copy taken from an archived version is at https://gist.github.com/halfelf/db1ae032dc34278968f8bf31ee999a25.
Binance, “How to manage a local order book correctly”, is a section of the spot WebSocket streams documentation, in the repository Binance publishes at https://github.com/binance/binance-spot-api-docs/blob/master/web-socket-streams.md; the futures version, which adds the pu field, is at https://developers.binance.com/docs/derivatives/usds-margined-futures/websocket-market-streams/How-to-manage-a-local-order-book-correctly. Read it for the join rule itself and the update procedure that follows it: the snapshot’s lastUpdateId set against U and u, the buffered events to discard, the test for a missed event, and the rule that a quantity of zero removes the level. Take the rule from the page for the stream you are on, not from the other.
Larry Harris, Trading and Exchanges: Market Microstructure for Practitioners (Oxford University Press, 2002), is a textbook written, as its subtitle says, for practitioners; Oxford’s page for it is https://academic.oup.com/book/52292. Read it for the reasons behind the words of the first sections of this chapter, the kinds of order, how an order-driven market matches them, what a tick size does to the spread, and who makes money from a quote and who loses on it.
CME Group, MDP 3.0, is the classic case of the other kind of venue, binary multicast with a recovery channel, and its documentation is the CME Group Client Systems Wiki, the page “MDP 3.0 - Dissemination”, at https://cmegroupclientsite.atlassian.net/wiki/spaces/EPICSANDBOX/pages/457222936/MDP+3.0+-+Dissemination. Read it for the same problem on a feed that cannot be resent: the incremental feed carried on two multicast feeds, A and B, every packet on both, so that a receiver that loses one still has the other; separate snapshot feeds to recover from; and a TCP replay of a range of packet sequence numbers for small gaps, which at the time of writing the page limits to 2,000 packets from the last 24 hours. The state machine is this chapter’s, a gap, then Stale, then a snapshot and the buffered deltas replayed, with recovery on channels of its own.
David Gross, “When Nanoseconds Matter: Ultrafast Trading Systems in C++”, a keynote at CppCon 2024, is a practitioner’s talk on building a trading system for low latency; CppCon’s page for it, https://cppcon.org/2024-keynote-david-gross/, lists “Optimizing Order Books for Speed” as one of its three topics. Read it after the lab, once you have numbers of your own to set against his: the language is C++, but the machine under it is the one these chapters measured.