JayBeams
0.1
Another project to have fun coding.
|
Compute the book and call a user-defined callback on each change. More...
#include <compute_book.hpp>
Public Types | |
Type traits | |
using | clock_type = jb::itch5::clock_type |
clock_type is used as a compute_book<book_type> type in some modules More... | |
using | time_point = jb::itch5::time_point |
time_point is used as a compute_book<book_type> type in some modules More... | |
using | book_type_config = typename book_type::config |
config type is used to construct the order_book More... | |
using | callback_type = std::function< void(message_header const &header, order_book< book_type > const &updated_book, book_update const &update)> |
Define the callback type. More... | |
Public Member Functions | |
compute_book (callback_type &&cb, book_type_config const &cfg) | |
Constructor. More... | |
compute_book (callback_type const &cb, book_type_config const &cfg) | |
void | handle_message (time_point recvts, long msgcnt, std::size_t msgoffset, add_order_message const &msg) |
Handle a new order message. More... | |
void | handle_message (time_point recvts, long msgcnt, std::size_t msgoffset, add_order_mpid_message const &msg) |
Handle a new order with MPID. More... | |
void | handle_message (time_point recvts, long msgcnt, std::size_t msgoffset, order_executed_message const &msg) |
Handle an order execution. More... | |
void | handle_message (time_point recvts, long msgcnt, std::size_t msgoffset, order_executed_price_message const &msg) |
Handle an order execution with a different price than the order's. More... | |
void | handle_message (time_point recvts, long msgcnt, std::size_t msgoffset, order_cancel_message const &msg) |
Handle a partial cancel. More... | |
void | handle_message (time_point recvts, long msgcnt, std::size_t msgoffset, order_delete_message const &msg) |
Handle a full cancel. More... | |
void | handle_message (time_point recvts, long msgcnt, std::size_t msgoffset, order_replace_message const &msg) |
Handle an order replace. More... | |
void | handle_message (time_point recvts, long msgcnt, std::size_t msgoffset, stock_directory_message const &msg) |
Pre-populate the books based on the symbol directory. More... | |
template<typename message_type > | |
void | handle_message (time_point, long, std::size_t, message_type const &) |
Ignore all other message types. More... | |
void | handle_unknown (time_point recvts, unknown_message const &msg) |
Log any unknown message types. More... | |
std::vector< stock_t > | symbols () const |
Return the symbols known in the order book. More... | |
time_point | now () const |
Return the current timestamp for delay measurements. More... | |
Private Types | |
using | books_by_security = std::unordered_map< stock_t, order_book< book_type >, boost::hash< stock_t > > |
Represent the collection of order books. More... | |
using | orders_by_id = std::unordered_map< std::uint64_t, order_data > |
Represent the collection of all orders. More... | |
using | orders_iterator = typename orders_by_id::iterator |
Private Member Functions | |
void | handle_order_reduction (time_point recvts, long msgcnt, std::size_t msgoffset, message_header const &header, std::uint64_t order_reference_number, std::uint32_t shares) |
Refactor code to handle order reductions, i.e., cancels and executions. More... | |
book_update | do_reduce (orders_iterator position, order_book< book_type > &book, time_point recvts, long msgcnt, std::size_t msgoffset, message_header const &header, std::uint64_t order_reference_number, std::uint32_t shares) |
Refactor code common to handle_order_reduction() and handle_message(order_replace_message). More... | |
Private Attributes | |
callback_type | callback_ |
Store the callback function, this is invoked on each event that changes a book. More... | |
books_by_security | books_ |
The order books indexed by security. More... | |
orders_by_id | orders_ |
The live orders indexed by the "order reference number". More... | |
book_type_config const & | cfg_ |
reference to the order book config More... | |
Compute the book and call a user-defined callback on each change.
Keep a collection of all the order books, indexed by symbol, and forward the updates to them. Only process the relevant messages types in ITCH-5.0 that are necessary to keep the book.
book_type | the type used to define order_book<book_type>, must be compatible with jb::itch5::map_price |
Definition at line 107 of file compute_book.hpp.
using jb::itch5::compute_book< book_type >::book_type_config = typename book_type::config |
config type is used to construct the order_book
Definition at line 122 of file compute_book.hpp.
|
private |
Represent the collection of order books.
Definition at line 402 of file compute_book.hpp.
using jb::itch5::compute_book< book_type >::callback_type = std::function<void( message_header const& header, order_book<book_type> const& updated_book, book_update const& update)> |
Define the callback type.
A callback of this type is required in the constructor of this class. After each book update the user-provided callback is invoked.
header | the header of the raw ITCH-5.0 message |
update | a representation of the update just applied to the book |
updated_book | the order_book after the update was applied |
Definition at line 138 of file compute_book.hpp.
using jb::itch5::compute_book< book_type >::clock_type = jb::itch5::clock_type |
clock_type is used as a compute_book<book_type> type in some modules
Definition at line 115 of file compute_book.hpp.
|
private |
Represent the collection of all orders.
Definition at line 405 of file compute_book.hpp.
|
private |
Definition at line 406 of file compute_book.hpp.
using jb::itch5::compute_book< book_type >::time_point = jb::itch5::time_point |
time_point is used as a compute_book<book_type> type in some modules
Definition at line 119 of file compute_book.hpp.
|
inlineexplicit |
Constructor.
Definition at line 142 of file compute_book.hpp.
|
inlineexplicit |
Definition at line 149 of file compute_book.hpp.
|
inlineprivate |
Refactor code common to handle_order_reduction() and handle_message(order_replace_message).
position | the location of the order matching order_reference_number |
book | the order_book matching the symbol for the given order |
recvts | the timestamp when the message was received |
msgcnt | the number of messages received before this message |
msgoffset | the number of bytes received before this message |
header | the header of the message that triggered this event |
order_reference_number | the id of the order being reduced |
shares | the number of shares to reduce, if 0 reduce all shares |
Definition at line 460 of file compute_book.hpp.
References jb::itch5::order_book< book_type >::handle_order_reduced(), JB_LOG, jb::itch5::book_update::qty, jb::itch5::book_update::recvts, and jb::warning.
|
inline |
Handle a new order message.
New orders are added to the list of known orders and their qty is added to the right book at the order's price level.
recvts | the timestamp when the message was received |
msgcnt | the number of messages received before this message |
msgoffset | the number of bytes received before this message |
msg | the message describing a new order |
Definition at line 164 of file compute_book.hpp.
References JB_LOG, jb::trace, and jb::warning.
|
inline |
Handle a new order with MPID.
recvts | the timestamp when the message was received |
msgcnt | the number of messages received before this message |
msgoffset | the number of bytes received before this message |
msg | the message describing a new order |
Definition at line 206 of file compute_book.hpp.
|
inline |
Handle an order execution.
recvts | the timestamp when the message was received |
msgcnt | the number of messages received before this message |
msgoffset | the number of bytes received before this message |
msg | the message describing the execution |
Definition at line 222 of file compute_book.hpp.
|
inline |
Handle an order execution with a different price than the order's.
recvts | the timestamp when the message was received |
msgcnt | the number of messages received before this message |
msgoffset | the number of bytes received before this message |
msg | the message describing the execution |
Definition at line 239 of file compute_book.hpp.
|
inline |
Handle a partial cancel.
recvts | the timestamp when the message was received |
msgcnt | the number of messages received before this message |
msgoffset | the number of bytes received before this message |
msg | the message describing the cancelation |
Definition at line 256 of file compute_book.hpp.
|
inline |
Handle a full cancel.
recvts | the timestamp when the message was received |
msgcnt | the number of messages received before this message |
msgoffset | the number of bytes received before this message |
msg | the message describing the cancelation |
Definition at line 273 of file compute_book.hpp.
|
inline |
Handle an order replace.
recvts | the timestamp when the message was received |
msgcnt | the number of messages received before this message |
msgoffset | the number of bytes received before this message |
msg | the message describing the cancel/replace |
Definition at line 289 of file compute_book.hpp.
References JB_ASSERT_THROW, JB_LOG, jb::trace, and jb::warning.
|
inline |
Pre-populate the books based on the symbol directory.
ITCH-5.0 sends the list of expected securities to be traded on a given day as a sequence of messages. We use these messages to pre-populate the map of books and avoid hash map updates during the critical path.
recvts | the timestamp when the message was received |
msgcnt | the number of messages received before this message |
msgoffset | the number of bytes received before this message |
msg | the message describing a known symbol for the feed |
Definition at line 354 of file compute_book.hpp.
|
inline |
Ignore all other message types.
We are only interested in a handful of message types, anything else is captured by this template function and ignored.
Definition at line 369 of file compute_book.hpp.
|
inlineprivate |
Refactor code to handle order reductions, i.e., cancels and executions.
recvts | the timestamp when the message was received |
msgcnt | the number of messages received before this message |
msgoffset | the number of bytes received before this message |
header | the header of the message that triggered this event |
order_reference_number | the id of the order being reduced |
shares | the number of shares to reduce, if 0 reduce all shares |
Definition at line 419 of file compute_book.hpp.
References JB_ASSERT_THROW, JB_LOG, and jb::warning.
|
inline |
Log any unknown message types.
recvts | the timestamp when the message was received |
msg | the unknown message location and contents |
Definition at line 378 of file compute_book.hpp.
References jb::itch5::unknown_message::buf(), jb::itch5::unknown_message::count(), jb::error, JB_LOG, and jb::itch5::unknown_message::offset().
|
inline |
Return the current timestamp for delay measurements.
Definition at line 395 of file compute_book.hpp.
|
inline |
Return the symbols known in the order book.
Definition at line 386 of file compute_book.hpp.
|
private |
The order books indexed by security.
Definition at line 496 of file compute_book.hpp.
|
private |
Store the callback function, this is invoked on each event that changes a book.
Definition at line 493 of file compute_book.hpp.
|
private |
reference to the order book config
Definition at line 502 of file compute_book.hpp.
|
private |
The live orders indexed by the "order reference number".
Definition at line 499 of file compute_book.hpp.