|
order_book 0.3.0
Exchange feed order book that prints the best bid and offer
|
#include <itch_market.hpp>
Public Member Functions | |
| std::expected< bool, BookError > | apply (const ItchMessage &message) |
| std::expected< bool, BookError > | add (const ItchMessage &message) |
| apply() for an Add, without dispatching on the kind | |
| std::expected< bool, BookError > | execute (const ItchMessage &message) |
| apply() for an Execute | |
| std::expected< bool, BookError > | remove (const ItchMessage &message) |
| apply() for a Delete | |
| std::expected< bool, BookError > | replace (const ItchMessage &message) |
| apply() for a Replace | |
| void | prefetch (std::uint64_t order, std::uint16_t locate) const |
| void | prefetch_levels (std::uint64_t order, std::uint16_t locate) const |
| Bbo | bbo (std::uint16_t locate) const |
| Current best bid and offer of locate. | |
| std::size_t | order_count () const |
| Number of live orders in every book. | |
| std::size_t | level_count () const |
| Number of price levels in every book. | |
Static Public Attributes | |
| static constexpr std::size_t | prefetch_distance = 16 |
| static constexpr bool | prefetch_levels_enabled = true |
The books of every stock locate in an ITCH feed, with their orders indexed by reference number
ITCH names each order by a reference number that is unique for the day across all stocks and assigned in sequence, so orders live in pages of consecutive reference numbers, each found from the reference number through a two-level directory that holds only the ranges in use, and the recent orders that most messages name share a few pages. Each level is a pooled record whose handle its orders keep, so executions and deletes reach it directly, and each side of a book is a vector of prices and handles, worst price first, so its best level is the last one.
Each book keeps its own reference numbers, as the CSV books keep their order IDs, so that which locates share a market does not change what a feed means. An order whose reference number names a live order of another locate goes to a hash map keyed by both instead of the index, as does one whose reference number is too large for the index.
Definition at line 36 of file itch_market.hpp.
|
nodiscard |
Apply message to its locate's book, returning whether that book's best bid or offer changed; on a BookError nothing changes, and after an exception, such as running out of memory, the market must not be used. An add or a replacement fails with DuplicateOrder if its reference number names a live order of the message's locate, and an execution, delete, or replace fails with UnknownOrder if its order is not live in that locate. Trades and skipped messages change nothing.
|
inlinenodiscard |
Number of price levels in every book.
Definition at line 76 of file itch_market.hpp.
|
inlinenodiscard |
Number of live orders in every book.
Definition at line 74 of file itch_market.hpp.
| void order_book::ItchMarket::prefetch | ( | std::uint64_t | order, |
| std::uint16_t | locate ) const |
Start loading the index entry of order and the book of locate, so that a message naming them a few messages later does not wait for memory
| void order_book::ItchMarket::prefetch_levels | ( | std::uint64_t | order, |
| std::uint16_t | locate ) const |
Start loading the level of order and the best levels of locate's book, once prefetch() has loaded the index entry and the book that point to them
|
staticconstexpr |
Messages ahead of the one being applied for which to call prefetch(), and half as many for prefetch_levels(), so that the loads finish first: a message takes over 50 ns on one core and a miss to memory roughly 100 ns. On the real day, distances from 8 to 64 ran within 4% of each other.
Definition at line 57 of file itch_market.hpp.
|
staticconstexpr |
Whether to call prefetch_levels() at all: level prefetch slowed the measured synthetic Linux x86-64 replay workload, so that platform stops at prefetch()
Definition at line 63 of file itch_market.hpp.