|
Slick Sim 0.10.1
Exchange simulator that shadows real venues for risk-free strategy testing
|
#include <exchange/symbol.hpp>
Public Member Functions | |
| Symbol () | |
| Both caches are filled by book observers and drained by the exchange thread, which only ever clear()s them, so the capacity reserved here is the capacity they keep for the process's lifetime. | |
| ~Symbol ()=default | |
| Symbol (const Symbol &)=delete | |
| Symbol & | operator= (const Symbol &)=delete |
| Symbol (Symbol &&other) noexcept | |
| Symbol & | operator= (Symbol &&other) |
| void | creditTradedQty (Side side, price_t price, qty_t phantom_consumed, time_t event_time) |
| Records that a trade print consumed phantom_consumed of the phantom liquidity resting at (side, price). | |
| qty_t | takeTradedQty (Side side, price_t price, time_t as_of) |
| Returns the quantity traded at (side, price) that a level update stamped as_of does not yet reflect, and drops every credit it does reflect. | |
| void | recordTrade (const MDTrade &trade) |
| Appends a trade to the tape history that serves the subscribe snapshot. | |
| void | clearTradeHistory () |
| Drops the tape history, so a venue that is about to resend its own trade snapshot does not end up replaying the overlap twice. | |
| template<OrderBookType BookType> | |
| void | createOrderBook () |
| std::tuple< OrdRejectReason, std::vector< TradeSummaryInfo > > | addOrder (Order *order, time_t request_time) |
| std::tuple< OrdRejectReason, std::vector< TradeSummaryInfo > > | modifyOrder (Order *order, price_t new_price, qty_t new_qty, time_t request_time) |
| void | cancelOrder (Order *order, time_t request_time) |
| Order * | findOrderByClientOrderId (const char *client_order_id) const |
| Order * | findOrderByOrderId (const char *order_id) const |
| Order * | findOrder (uint64_t order_id) const |
| void | onPriceLevelUpdate (const PriceLevelUpdate &update) |
| void | onOrderUpdate (const OrderUpdate &update) |
| Called when an individual order is updated (L3 event). | |
Public Attributes | |
| symid_t | id_ = INVALID_SYMBOL_ID |
| Venue | venue_ |
| symbol_name_t | symbol_ |
| Stored at wire width so publishing can copy the whole field without reading past the end of a shorter string buffer. | |
| engine::MatchingEngine * | matching_engine_ = nullptr |
| std::shared_ptr< OrderBook > | order_book_ |
| std::atomic_uint16_t | num_subscriptions_ = 0 |
| SelfMatchPreventionMode | smp_mode_ = SelfMatchPreventionMode::NONE |
| std::vector< MDLevel > | md_level_update_cache_ |
| std::vector< MDOrder > | md_order_update_cache_ |
| std::shared_ptr< OrderBookObserver > | book_observer_ |
| utils::RingBuffer< MDTrade > | trade_history_ {TRADE_HISTORY_CAPACITY} |
Static Public Attributes | |
| static constexpr size_t | TRADE_HISTORY_CAPACITY = 64 |
| Recent trades published on this instrument's tape, newest at the back. | |
Definition at line 36 of file symbol.hpp.
|
inline |
Both caches are filled by book observers and drained by the exchange thread, which only ever clear()s them, so the capacity reserved here is the capacity they keep for the process's lifetime.
Sized for the largest batch a busy instrument produces in one feed message so a market-data flood never reaches the allocator.
Definition at line 61 of file symbol.hpp.
References book_observer_, md_level_update_cache_, and md_order_update_cache_.
Referenced by Symbol(), Symbol(), operator=(), and operator=().
|
default |
|
delete |
References Symbol().
|
inlinenoexcept |
Definition at line 70 of file symbol.hpp.
References Symbol(), book_observer_, order_book_, and slick::sim::UNKNOWN_VENUE.
| std::tuple< OrdRejectReason, std::vector< TradeSummaryInfo > > Symbol::addOrder | ( | Order * | order, |
| time_t | request_time ) |
Definition at line 15 of file symbol.cpp.
References slick::sim::OrderIdentity::client_order_id, slick::sim::Order::created_time, slick::sim::F_END_EVENT, slick::sim::Order::id, slick::sim::Order::leaves_quantity, matching_engine_, md_level_update_cache_, slick::sim::NONE, slick::sim::NULL_PRICE, order_book_, slick::sim::OrderIdentity::order_id, slick::sim::Order::price, slick::sim::Order::quantity, slick::sim::Order::restsRemainder(), smp_mode_, symbol_, slick::sim::Order::time_in_force, slick::sim::to_price_double(), slick::sim::to_qty_double(), slick::sim::to_string(), and slick::sim::utils::fixed_string< N >::view().
Definition at line 89 of file symbol.cpp.
References slick::sim::OrderIdentity::client_order_id, slick::sim::utils::get_current_time_ns(), slick::sim::Order::last_update_time, matching_engine_, order_book_, slick::sim::OrderIdentity::order_id, symbol_, and slick::sim::utils::fixed_string< N >::view().
|
inline |
Drops the tape history, so a venue that is about to resend its own trade snapshot does not end up replaying the overlap twice.
Definition at line 175 of file symbol.hpp.
References trade_history_, and TRADE_HISTORY_CAPACITY.
|
inline |
Definition at line 180 of file symbol.hpp.
References book_observer_, id_, order_book_, symbol_, and venue_.
|
inline |
Records that a trade print consumed phantom_consumed of the phantom liquidity resting at (side, price).
The venue will report the same reduction again in its own level update for that trade. Applying both would reduce the level twice, so the level path offsets against this credit when the update predates the trade. Only phantom quantity is credited: when a trade fills the simulator's own resting order the venue's level still legitimately drops by that amount, because that liquidity really did trade at the venue.
Definition at line 116 of file symbol.hpp.
References slick::sim::SELL.
|
inline |
Definition at line 198 of file symbol.hpp.
References order_book_.
Referenced by slick::sim::exch::Exchange::reconcilePhantomQty().
|
inline |
Definition at line 190 of file symbol.hpp.
References order_book_.
|
inline |
Definition at line 194 of file symbol.hpp.
References order_book_.
| std::tuple< OrdRejectReason, std::vector< TradeSummaryInfo > > Symbol::modifyOrder | ( | Order * | order, |
| price_t | new_price, | ||
| qty_t | new_qty, | ||
| time_t | request_time ) |
Definition at line 58 of file symbol.cpp.
References slick::sim::OrderIdentity::client_order_id, slick::sim::utils::get_current_time_ns(), slick::sim::Order::id, slick::sim::Order::last_update_time, slick::sim::Order::leaves_quantity, matching_engine_, slick::sim::OrderBook::nextOrderPriority(), slick::sim::NONE, order_book_, slick::sim::OrderIdentity::order_id, slick::sim::Order::price, slick::sim::Order::priority, slick::sim::Order::quantity, smp_mode_, symbol_, and slick::sim::utils::fixed_string< N >::view().
| void Symbol::onOrderUpdate | ( | const OrderUpdate & | update | ) |
Called when an individual order is updated (L3 event).
Definition at line 112 of file symbol.cpp.
References slick::sim::ACTION_CHANGE, slick::sim::ACTION_DELETE, slick::sim::ACTION_NEW, and md_order_update_cache_.
| void Symbol::onPriceLevelUpdate | ( | const PriceLevelUpdate & | update | ) |
Definition at line 98 of file symbol.cpp.
References slick::sim::ACTION_NEW, slick::sim::F_END_EVENT, slick::sim::F_NONE, and md_level_update_cache_.
Definition at line 91 of file symbol.hpp.
References Symbol(), id_, matching_engine_, md_level_update_cache_, md_order_update_cache_, num_subscriptions_, order_book_, symbol_, trade_history_, slick::sim::UNKNOWN_VENUE, and venue_.
|
inline |
Appends a trade to the tape history that serves the subscribe snapshot.
Definition at line 169 of file symbol.hpp.
References trade_history_.
Referenced by slick::sim::exch::CoinbaseExchange::onMarketTradesSnapshot(), and slick::sim::exch::Exchange::publishTradeSummary().
Returns the quantity traded at (side, price) that a level update stamped as_of does not yet reflect, and drops every credit it does reflect.
Credits are resolved individually rather than summed: an update landing between two trades at the same price reflects the earlier one and not the later one, so offsetting by both would over-reduce the level. Credits it does not reflect are kept for the next update to resolve; the ones it does are dropped, so stale credit can never survive to swallow a genuine cancel.
Definition at line 140 of file symbol.hpp.
References slick::sim::SELL.
Referenced by slick::sim::exch::Exchange::reconcilePhantomQty().
| std::shared_ptr<OrderBookObserver> slick::sim::exch::Symbol::book_observer_ |
Definition at line 53 of file symbol.hpp.
Referenced by Symbol(), Symbol(), and createOrderBook().
| symid_t slick::sim::exch::Symbol::id_ = INVALID_SYMBOL_ID |
Definition at line 42 of file symbol.hpp.
Referenced by createOrderBook(), operator=(), and slick::sim::exch::Exchange::publishTradeSummary().
| engine::MatchingEngine* slick::sim::exch::Symbol::matching_engine_ = nullptr |
Definition at line 47 of file symbol.hpp.
Referenced by addOrder(), slick::sim::exch::Exchange::assignMatching(), cancelOrder(), modifyOrder(), operator=(), slick::sim::exch::Exchange::replayMarketTrade(), and slick::sim::exch::Exchange::restMarketOrder().
| std::vector<MDLevel> slick::sim::exch::Symbol::md_level_update_cache_ |
Definition at line 51 of file symbol.hpp.
Referenced by Symbol(), addOrder(), slick::sim::exch::Exchange::flushMarketDataCaches(), onPriceLevelUpdate(), and operator=().
| std::vector<MDOrder> slick::sim::exch::Symbol::md_order_update_cache_ |
Definition at line 52 of file symbol.hpp.
Referenced by Symbol(), slick::sim::exch::Exchange::flushMarketDataCaches(), onOrderUpdate(), and operator=().
| std::atomic_uint16_t slick::sim::exch::Symbol::num_subscriptions_ = 0 |
Definition at line 49 of file symbol.hpp.
Referenced by slick::sim::exch::HyperliquidExchange::handleMdSubscription(), slick::sim::exch::HyperliquidExchange::handleMdUnsubscription(), and operator=().
| std::shared_ptr<OrderBook> slick::sim::exch::Symbol::order_book_ |
Definition at line 48 of file symbol.hpp.
Referenced by Symbol(), addOrder(), slick::sim::exch::Exchange::applyMarketOrder(), cancelOrder(), createOrderBook(), findOrder(), findOrderByClientOrderId(), findOrderByOrderId(), slick::sim::exch::HyperliquidExchange::handleMdSubscription(), modifyOrder(), operator=(), slick::sim::exch::Exchange::publishTradeSubscriptionResponse(), slick::sim::exch::Exchange::reconcilePhantomQty(), slick::sim::exch::Exchange::replayMarketTrade(), and slick::sim::exch::Exchange::restMarketOrder().
| SelfMatchPreventionMode slick::sim::exch::Symbol::smp_mode_ = SelfMatchPreventionMode::NONE |
Definition at line 50 of file symbol.hpp.
Referenced by addOrder(), slick::sim::exch::Exchange::assignMatching(), and modifyOrder().
| symbol_name_t slick::sim::exch::Symbol::symbol_ |
Stored at wire width so publishing can copy the whole field without reading past the end of a shorter string buffer.
Definition at line 46 of file symbol.hpp.
Referenced by addOrder(), cancelOrder(), createOrderBook(), slick::sim::exch::Exchange::flushMarketDataCaches(), modifyOrder(), operator=(), slick::sim::exch::Exchange::publishTradeSubscriptionResponse(), and slick::sim::exch::Exchange::publishTradeSummary().
| utils::RingBuffer<MDTrade> slick::sim::exch::Symbol::trade_history_ {TRADE_HISTORY_CAPACITY} |
Definition at line 54 of file symbol.hpp.
Referenced by clearTradeHistory(), operator=(), slick::sim::exch::Exchange::publishTradeSubscriptionResponse(), and recordTrade().
|
staticconstexpr |
Recent trades published on this instrument's tape, newest at the back.
Serves the subscribe-time snapshot on every venue. Capacity must stay a power of two - utils::RingBuffer asserts on it.
Definition at line 40 of file symbol.hpp.
Referenced by clearTradeHistory().
| Venue slick::sim::exch::Symbol::venue_ |
Definition at line 43 of file symbol.hpp.
Referenced by createOrderBook(), and operator=().