Slick Sim 0.10.1
Exchange simulator that shadows real venues for risk-free strategy testing
Loading...
Searching...
No Matches
slick::sim::exch::Symbol Struct Reference

#include <exchange/symbol.hpp>

Collaboration diagram for slick::sim::exch::Symbol:

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.

Detailed Description

Definition at line 36 of file symbol.hpp.

Constructor & Destructor Documentation

◆ Symbol() [1/3]

slick::sim::exch::Symbol::Symbol ( )
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=().

◆ ~Symbol()

slick::sim::exch::Symbol::~Symbol ( )
default

◆ Symbol() [2/3]

slick::sim::exch::Symbol::Symbol ( const Symbol & )
delete

References Symbol().

◆ Symbol() [3/3]

slick::sim::exch::Symbol::Symbol ( Symbol && other)
inlinenoexcept

Definition at line 70 of file symbol.hpp.

References Symbol(), book_observer_, order_book_, and slick::sim::UNKNOWN_VENUE.

Member Function Documentation

◆ addOrder()

◆ cancelOrder()

◆ clearTradeHistory()

void slick::sim::exch::Symbol::clearTradeHistory ( )
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.

◆ createOrderBook()

template<OrderBookType BookType>
void slick::sim::exch::Symbol::createOrderBook ( )
inline

Definition at line 180 of file symbol.hpp.

References book_observer_, id_, order_book_, symbol_, and venue_.

◆ creditTradedQty()

void slick::sim::exch::Symbol::creditTradedQty ( Side side,
price_t price,
qty_t phantom_consumed,
time_t event_time )
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.

◆ findOrder()

Order * slick::sim::exch::Symbol::findOrder ( uint64_t order_id) const
inline

Definition at line 198 of file symbol.hpp.

References order_book_.

Referenced by slick::sim::exch::Exchange::reconcilePhantomQty().

◆ findOrderByClientOrderId()

Order * slick::sim::exch::Symbol::findOrderByClientOrderId ( const char * client_order_id) const
inline

Definition at line 190 of file symbol.hpp.

References order_book_.

◆ findOrderByOrderId()

Order * slick::sim::exch::Symbol::findOrderByOrderId ( const char * order_id) const
inline

Definition at line 194 of file symbol.hpp.

References order_book_.

◆ modifyOrder()

◆ onOrderUpdate()

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_.

◆ onPriceLevelUpdate()

void Symbol::onPriceLevelUpdate ( const PriceLevelUpdate & update)

◆ operator=() [1/2]

Symbol & slick::sim::exch::Symbol::operator= ( const Symbol & )
delete

References Symbol().

◆ operator=() [2/2]

Symbol & slick::sim::exch::Symbol::operator= ( Symbol && other)
inline

◆ recordTrade()

void slick::sim::exch::Symbol::recordTrade ( const MDTrade & trade)
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().

◆ takeTradedQty()

qty_t slick::sim::exch::Symbol::takeTradedQty ( Side side,
price_t price,
time_t as_of )
inline

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().

Member Data Documentation

◆ book_observer_

std::shared_ptr<OrderBookObserver> slick::sim::exch::Symbol::book_observer_

Definition at line 53 of file symbol.hpp.

Referenced by Symbol(), Symbol(), and createOrderBook().

◆ id_

symid_t slick::sim::exch::Symbol::id_ = INVALID_SYMBOL_ID

◆ matching_engine_

◆ md_level_update_cache_

std::vector<MDLevel> slick::sim::exch::Symbol::md_level_update_cache_

◆ md_order_update_cache_

std::vector<MDOrder> slick::sim::exch::Symbol::md_order_update_cache_

◆ num_subscriptions_

std::atomic_uint16_t slick::sim::exch::Symbol::num_subscriptions_ = 0

◆ order_book_

◆ smp_mode_

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_

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().

◆ trade_history_

◆ TRADE_HISTORY_CAPACITY

size_t slick::sim::exch::Symbol::TRADE_HISTORY_CAPACITY = 64
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_

Venue slick::sim::exch::Symbol::venue_

Definition at line 43 of file symbol.hpp.

Referenced by createOrderBook(), and operator=().


The documentation for this struct was generated from the following files: