JayBeams
0.1
Another project to have fun coding.
|
Represent one side of the book. More...
#include <array_based_order_book.hpp>
Classes | |
struct | side |
template specialization struct to handle differences between BUY and SELL version SELL side. More... | |
struct | side< std::greater< std::size_t >, DUMMY > |
version BUY side More... | |
Public Member Functions | |
array_based_book_side (array_based_order_book::config const &cfg) | |
Constructor, initialize a book side from its configuration. More... | |
half_quote | best_quote () const |
half_quote | worst_quote () const |
std::size_t | count () const |
bool | add_order (price4_t px, int qty) |
Add a price and quantity to the side order book. More... | |
bool | reduce_order (price4_t px, int qty) |
Reduce the quantity for a given price. More... | |
bool | is_ascending () const |
Testing hook. More... | |
Static Public Member Functions | |
static std::size_t | price_levels_empty_quote () |
Return the number of price levels for the empty quote. More... | |
Static Public Attributes | |
static std::size_t const | tk_empty_quote |
Cache the number of levels for the empty quote. More... | |
Private Member Functions | |
std::size_t | relative_worst_top_level () const |
std::size_t | top_levels_count () const |
void | move_top_to_bottom (std::size_t const tk_max) |
Move prices from tk_begin_top_ to tk_max (excluded) out of top_levels_ to bottom_levels_. More... | |
void | move_top_to_bottom_ranged (std::size_t N) |
Move the bottom N levels from the top vector to the bottom map. More... | |
void | move_bottom_to_top () |
Move relative prices from best price to tk_begin_top* (included) out of bottom_levels_ to top_levels_. More... | |
std::size_t | next_best_price_level () const |
Static Private Member Functions | |
static auto | get_limits (std::size_t const tk_px, std::size_t const rel) |
Private Attributes | |
std::size_t | max_size_ |
top_levels_ max size More... | |
std::vector< int > | top_levels_ |
the best relative prices and quantity More... | |
std::map< std::size_t, int, compare_t > | bottom_levels_ |
the worst (tail) price level and quantity More... | |
std::size_t | tk_inside_ |
price level the inside More... | |
std::size_t | tk_begin_top_ |
worst price level on the top_levels_ range More... | |
std::size_t | tk_end_top_ |
one price level past-the-best price in top_levels_ range More... | |
Represent one side of the book.
This implementation uses a top_levels_ fix sized vector<price4_t> to keep the prices around the inside. We are hoping this makes a faster order book side (instead of map based).
We have observed that most of the changes to an order book happen in the levels closer to the inside. We are trying to exploit this observation by using a vector<> for the N levels closer to the inside, as updates in a vector should be O(1) instead of O(log N) for tree-based implementations, and O(1) (with a larger constant) for hash-based implementations. This introduces some complexity: maintaining all the levels in the vector would consume too much memory, so we use a vector for the N levels closer to the inside, and a map for all the other levels.
compare_t | function object class type to sort the side |
Definition at line 78 of file array_based_order_book.hpp.
|
inlineexplicit |
Constructor, initialize a book side from its configuration.
Definition at line 131 of file array_based_order_book.hpp.
|
inline |
Add a price and quantity to the side order book.
px | the price of the new order |
qty | the quantity of the new order |
feed_error | px out of valid range, or qty <= 0 |
Definition at line 192 of file array_based_order_book.hpp.
References jb::itch5::price_levels(), and jb::itch5::detail::validate_operation_params().
Referenced by BOOST_AUTO_TEST_CASE().
|
inline |
Definition at line 142 of file array_based_order_book.hpp.
Referenced by BOOST_AUTO_TEST_CASE().
|
inline |
Definition at line 175 of file array_based_order_book.hpp.
Referenced by BOOST_AUTO_TEST_CASE().
|
inlinestaticprivate |
Definition at line 509 of file array_based_order_book.hpp.
References jb::itch5::empty_offer_price(), and jb::itch5::price_levels().
|
inline |
Testing hook.
Definition at line 333 of file array_based_order_book.hpp.
|
inlineprivate |
Move relative prices from best price to tk_begin_top* (included) out of bottom_levels_ to top_levels_.
*tk_begin_top_ is updated before calling this function.
Definition at line 464 of file array_based_order_book.hpp.
|
inlineprivate |
Move prices from tk_begin_top_ to tk_max (excluded) out of top_levels_ to bottom_levels_.
tk_max | first limit price level that is not moved out. |
Inserts the prices into bottom_levels_ Shift top_levels_ prices in order for rel_max to become relative 0 Clear (value = 0) former relative position of moved prices
Definition at line 394 of file array_based_order_book.hpp.
References JB_ASSERT_THROW.
|
inlineprivate |
Move the bottom N levels from the top vector to the bottom map.
This function "copies" the bottom N levels from the top vector, and then zeroes out that portion of the vector ...
N | the number of elements to move. |
Definition at line 431 of file array_based_order_book.hpp.
|
inlineprivate |
Definition at line 489 of file array_based_order_book.hpp.
|
inlinestatic |
Return the number of price levels for the empty quote.
This is mostly used to initialize tk_empty_quote, because otherwise the template definitions get too gnarly.
Definition at line 351 of file array_based_order_book.hpp.
References jb::itch5::price_levels().
|
inline |
Reduce the quantity for a given price.
px | the price of the order that was reduced |
qty | the quantity reduced in the order |
feed_error | qty <= 0 |
feed_error | px should be in bottom_levels_ but is empty |
feed_error | trying to reduce a non-existing bottom_levels price |
feed_error | trying to reduce a non-existing top_levels price |
feed_error | trying to reduce a price better than px_inside_ |
Checks and handles if px is a bottom_level_ price Checks if top_levels_ is empty after reducing If so, limits have to be redefined, and tail moved into top_levels
Definition at line 249 of file array_based_order_book.hpp.
References JB_LOG, jb::itch5::price_levels(), jb::itch5::detail::raise_invalid_reduce(), jb::itch5::detail::validate_operation_params(), and jb::warning.
Referenced by BOOST_AUTO_TEST_CASE().
|
inlineprivate |
feed_error | top_levels_ is empty. |
Definition at line 360 of file array_based_order_book.hpp.
|
inlineprivate |
Definition at line 369 of file array_based_order_book.hpp.
|
inline |
Definition at line 155 of file array_based_order_book.hpp.
Referenced by BOOST_AUTO_TEST_CASE().
|
private |
the worst (tail) price level and quantity
Definition at line 619 of file array_based_order_book.hpp.
|
private |
top_levels_ max size
Definition at line 613 of file array_based_order_book.hpp.
|
private |
worst price level on the top_levels_ range
Definition at line 625 of file array_based_order_book.hpp.
|
static |
Cache the number of levels for the empty quote.
This value is used numerous times in the critical path, and we want to avoid recomputing it over and over.
Definition at line 343 of file array_based_order_book.hpp.
|
private |
one price level past-the-best price in top_levels_ range
Definition at line 628 of file array_based_order_book.hpp.
|
private |
price level the inside
Definition at line 622 of file array_based_order_book.hpp.
|
private |
the best relative prices and quantity
Definition at line 616 of file array_based_order_book.hpp.