|
Slick Sim 0.10.1
Exchange simulator that shadows real venues for risk-free strategy testing
|
#include <order_book/order_book.hpp>
Public Member Functions | |
| OrderBook (symid_t sid, std::string_view symbol, Venue venue, uint_fast32_t buffer_size=65536) | |
| ~OrderBook () override=default | |
| Order * | allocateOrder () |
| void | freeOrder (Order *order) |
| Order * | findOrderByClientOrderId (std::string_view client_order_id) |
| Order * | findOrderByOrderId (std::string_view order_id) |
| Order * | findOrder (uint64_t id) |
| const symbol_name_t & | symbolName () const noexcept |
| Wire-ready, so publishers copy it as a fixed block instead of reading sizeof(field) bytes out of a shorter std::string. | |
| symid_t | sid () const noexcept |
| void | onPriceLevelUpdate (const PriceLevelUpdate &update) override |
| void | onOrderUpdate (const OrderUpdate &update) override |
| qty_t | getMDLevelQty (price_t price) const |
| virtual void | populateL2SubscriptionResponse (slick::queue< uint8_t > &md_update_queue, uint8_t channel)=0 |
| virtual void | populateL2Snapshot (slick::queue< uint8_t > &md_update_queue)=0 |
| virtual void | populateMDBookUpdate (MDBookUpdate &book_update)=0 |
| void | addOrder (Order *order, uint64_t timestamp, uint64_t seq_num=0, bool is_last_in_batch=true) |
| virtual void | addBookOrder (uint64_t order_id, slick::orderbook::Side book_side, price_t price, qty_t qty, uint64_t timestamp, uint64_t seq_num, bool is_last_in_batch=true)=0 |
| Rest phantom (market-data) liquidity. | |
| void | deleteOrder (Order *order, uint64_t timestamp, uint64_t seq_num=0, bool is_last_in_batch=true) |
| void | deleteOrder (Order *order) |
| void | modifyOrder (Order *order, price_t new_price, qty_t new_qty, uint64_t timestamp, uint64_t seq_num=0, bool is_last_in_batch=true) |
| void | clearMDOrders () |
| bool | executeOrder (slick::orderbook::OrderId order_id, slick::orderbook::Quantity executed_quantity, uint64_t timestamp, uint64_t seq_num=0, bool is_last_in_batch=true) override |
| time_t | lastUpdateTime () const noexcept |
| uint64_t | lastSeqNum () const noexcept |
| void | setLastUpdate (time_t timestamp, uint64_t seq_num) noexcept |
| virtual std::string | to_string () const =0 |
Static Public Member Functions | |
| static uint64_t | nextOrderPriority () noexcept |
| One sequence shared by every book, so it is drawn from atomically: each exchange runs on its own thread, and a plain increment raced between them could hand a book a priority lower than one it had already issued - its FIFO order, and the MDOrderPriority it publishes, would then run backwards. | |
Protected Types | |
| using | StringViewHash = utils::StringViewHash |
| using | StringViewEq = utils::StringViewEq |
Protected Attributes | |
| time_t | last_update_time_ = 0 |
| uint64_t | last_seq_num_ = 0 |
| symid_t | sid_ |
| Venue | venue_ |
| symbol_name_t | symbol_ |
| slick::ObjectPool< Order > | order_buffer_ |
| std::unordered_map< uint64_t, Order * > | orders_ |
| std::unordered_map< utils::fixed_string< 37 >, Order *, StringViewHash, StringViewEq > | orders_by_client_order_id_ |
| std::unordered_map< utils::fixed_string< 37 >, Order *, StringViewHash, StringViewEq > | orders_by_order_id_ |
| OrderUpdate | last_order_update_ |
| std::unordered_map< price_t, qty_t > | feed_md_level_quantity_ |
Static Protected Attributes | |
| static std::atomic< uint64_t > | next_priority_ {0} |
Friends | |
| struct | Observer |
Definition at line 43 of file order_book.hpp.
|
protected |
Definition at line 255 of file order_book.hpp.
|
protected |
Definition at line 254 of file order_book.hpp.
|
inline |
Definition at line 45 of file order_book.hpp.
References order_buffer_, orders_, orders_by_client_order_id_, orders_by_order_id_, sid(), symbol_, and venue_.
Referenced by slick::sim::OrderBookImpl< BookType >::OrderBookImpl().
|
overridedefault |
|
pure virtual |
Rest phantom (market-data) liquidity.
Prefer this over the inherited OrderBookL3::addOrder - that one takes priority as its sixth argument, so a call that means to pass a sequence there silently lands it in priority and shifts the sequence and batch flag one place along.
Implemented in slick::sim::OrderBookImpl< BookType >.
|
inline |
Definition at line 89 of file order_book.hpp.
References addOrder(), slick::sim::OrderIdentity::client_order_id, slick::sim::utils::fixed_string< N >::empty(), slick::sim::Order::id, slick::sim::Order::leaves_quantity, nextOrderPriority(), slick::sim::OrderIdentity::order_id, orders_, orders_by_client_order_id_, orders_by_order_id_, slick::sim::Order::price, slick::sim::Order::priority, slick::sim::Order::side, and slick::sim::to_book_side().
Referenced by slick::sim::OrderBookImpl< BookType >::addBookOrder(), and addOrder().
|
inline |
Definition at line 300 of file order_book.hpp.
References slick::sim::utils::get_current_time_ns(), slick::sim::utils::nextOrderId(), order_buffer_, and slick::sim::OrderIdentity::order_id.
|
inline |
Definition at line 173 of file order_book.hpp.
References feed_md_level_quantity_, orders_, and slick::sim::to_book_side().
|
inline |
Definition at line 122 of file order_book.hpp.
References slick::sim::OrderIdentity::client_order_id, slick::sim::utils::fixed_string< N >::empty(), freeOrder(), slick::sim::Order::id, slick::sim::OrderIdentity::order_id, orders_, orders_by_client_order_id_, and orders_by_order_id_.
|
inline |
Definition at line 108 of file order_book.hpp.
References slick::sim::OrderIdentity::client_order_id, deleteOrder(), slick::sim::utils::fixed_string< N >::empty(), slick::sim::Order::id, slick::sim::OrderIdentity::order_id, orders_, orders_by_client_order_id_, and orders_by_order_id_.
Referenced by deleteOrder(), slick::sim::engine::detail::fillResting(), slick::sim::engine::detail::fillRestingFromFeed(), and slick::sim::engine::detail::handleSelfMatch().
|
inlineoverride |
Definition at line 189 of file order_book.hpp.
References slick::sim::utils::executeOrder(), findOrder(), orders_, orders_by_client_order_id_, and orders_by_order_id_.
Referenced by slick::sim::engine::detail::fillResting(), and slick::sim::engine::detail::fillRestingFromFeed().
|
inline |
Definition at line 382 of file order_book.hpp.
References orders_.
Referenced by slick::sim::engine::detail::canFillCompletely(), executeOrder(), slick::sim::engine::detail::fillRestingFromFeed(), onOrderUpdate(), and slick::sim::engine::detail::wouldSelfMatch().
|
inline |
Definition at line 372 of file order_book.hpp.
References orders_by_client_order_id_.
|
inline |
Definition at line 377 of file order_book.hpp.
References orders_by_order_id_.
|
inline |
Definition at line 58 of file order_book.hpp.
References order_buffer_.
Referenced by deleteOrder(), and slick::sim::engine::detail::handleSelfMatch().
Definition at line 324 of file order_book.hpp.
References feed_md_level_quantity_.
|
inlinenoexcept |
Definition at line 223 of file order_book.hpp.
References last_seq_num_.
|
inlinenoexcept |
Definition at line 219 of file order_book.hpp.
References last_update_time_.
|
inline |
Definition at line 136 of file order_book.hpp.
References slick::sim::OrderIdentity::client_order_id, slick::sim::utils::fixed_string< N >::empty(), slick::sim::Order::id, slick::sim::Order::leaves_quantity, modifyOrder(), nextOrderPriority(), slick::sim::OrderIdentity::order_id, orders_, orders_by_client_order_id_, orders_by_order_id_, slick::sim::Order::price, slick::sim::Order::priority, and slick::sim::Order::quantity.
Referenced by modifyOrder().
|
inlinestaticnoexcept |
One sequence shared by every book, so it is drawn from atomically: each exchange runs on its own thread, and a plain increment raced between them could hand a book a priority lower than one it had already issued - its FIFO order, and the MDOrderPriority it publishes, would then run backwards.
Public so a feed can draw a market order's place in the queue when the order joins it, and keep it: a level sorts by this value, so an order re-added under the priority it was given goes back where it was.
Definition at line 242 of file order_book.hpp.
References next_priority_.
Referenced by slick::sim::OrderBookImpl< BookType >::addBookOrder(), addOrder(), slick::sim::exch::Symbol::modifyOrder(), and modifyOrder().
|
inlineoverride |
Definition at line 340 of file order_book.hpp.
References feed_md_level_quantity_, and findOrder().
|
inlineoverride |
Definition at line 333 of file order_book.hpp.
References feed_md_level_quantity_.
|
pure virtual |
|
pure virtual |
|
pure virtual |
Implemented in slick::sim::OrderBookImpl< BookType >, slick::sim::OrderBookImpl< BookType >, and slick::sim::OrderBookImpl< BookType >.
Referenced by slick::sim::exch::Exchange::publishMDBookUpdate().
|
inlinenoexcept |
Definition at line 227 of file order_book.hpp.
References last_seq_num_, and last_update_time_.
|
inlinenoexcept |
Definition at line 71 of file order_book.hpp.
Referenced by OrderBook(), and slick::sim::OrderBookImpl< BookType >::OrderBookImpl().
|
inlinenoexcept |
Wire-ready, so publishers copy it as a fixed block instead of reading sizeof(field) bytes out of a shorter std::string.
Definition at line 67 of file order_book.hpp.
References symbol_.
Referenced by slick::sim::engine::detail::fillRestingFromFeed(), and slick::sim::exch::Exchange::publishMDBookUpdate().
|
pure virtual |
Implemented in slick::sim::OrderBookImpl< BookType >.
|
friend |
Definition at line 265 of file order_book.hpp.
Referenced by clearMDOrders(), getMDLevelQty(), onOrderUpdate(), and onPriceLevelUpdate().
|
protected |
Definition at line 264 of file order_book.hpp.
|
protected |
Definition at line 250 of file order_book.hpp.
Referenced by lastSeqNum(), and setLastUpdate().
|
protected |
Definition at line 249 of file order_book.hpp.
Referenced by lastUpdateTime(), and setLastUpdate().
|
inlinestaticprotected |
Definition at line 248 of file order_book.hpp.
Referenced by nextOrderPriority().
|
protected |
Definition at line 257 of file order_book.hpp.
Referenced by OrderBook(), allocateOrder(), and freeOrder().
|
protected |
Definition at line 258 of file order_book.hpp.
Referenced by OrderBook(), addOrder(), clearMDOrders(), deleteOrder(), deleteOrder(), executeOrder(), findOrder(), and modifyOrder().
|
protected |
Definition at line 262 of file order_book.hpp.
Referenced by OrderBook(), addOrder(), deleteOrder(), deleteOrder(), executeOrder(), findOrderByClientOrderId(), and modifyOrder().
|
protected |
Definition at line 263 of file order_book.hpp.
Referenced by OrderBook(), addOrder(), deleteOrder(), deleteOrder(), executeOrder(), findOrderByOrderId(), and modifyOrder().
|
protected |
Definition at line 251 of file order_book.hpp.
|
protected |
Definition at line 253 of file order_book.hpp.
Referenced by OrderBook(), slick::sim::OrderBookImpl< BookType >::populateL2Snapshot(), slick::sim::OrderBookImpl< BookType >::populateL2SubscriptionResponse(), symbolName(), and slick::sim::OrderBookImpl< BookType >::to_string().
|
protected |
Definition at line 252 of file order_book.hpp.
Referenced by OrderBook(), slick::sim::OrderBookImpl< BookType >::populateL2Snapshot(), and slick::sim::OrderBookImpl< BookType >::populateL2SubscriptionResponse().