10#include <unordered_map>
11#include <unordered_set>
12#include <slick/orderbook/observer.hpp>
71 :
id_(std::exchange(other.id_, 0))
73 ,
symbol_(std::move(other.symbol_))
84 , traded_qty_credit_(std::move(other.traded_qty_credit_))
93 id_ = std::exchange(other.id_, 0);
95 symbol_ = std::move(other.symbol_);
98 num_subscriptions_.store(other.num_subscriptions_.load(std::memory_order_relaxed), std::memory_order_relaxed);
102 traded_qty_credit_ = std::move(other.traded_qty_credit_);
117 if (phantom_consumed <= 0 || side >
Side::SELL) {
120 auto &credits = traded_qty_credit_[
static_cast<size_t>(side)][price];
123 for (
auto &credit : credits) {
124 if (credit.event_time == event_time) {
125 credit.qty += phantom_consumed;
129 credits.emplace_back(phantom_consumed, event_time);
144 auto &by_price = traded_qty_credit_[
static_cast<size_t>(side)];
145 auto it = by_price.find(price);
146 if (it == by_price.end()) {
150 auto &credits = it->second;
151 qty_t unreflected = 0;
152 for (
auto credit = credits.begin(); credit != credits.end();) {
153 if (as_of < credit->event_time) {
156 unreflected += credit->qty;
159 credit = credits.erase(credit);
162 if (credits.empty()) {
179 template<OrderBookType BookType>
186 std::tuple<OrdRejectReason, std::vector<TradeSummaryInfo>>
addOrder(
Order *order,
time_t request_time);
191 return order_book_->findOrderByClientOrderId(client_order_id);
210 std::array<std::unordered_map<price_t, std::vector<TradedCredit>>, 2> traded_qty_credit_;
Helpers for a venue whose one config entry describes several independent exchange instances,...
slick::orderbook::PriceLevelUpdate PriceLevelUpdate
constexpr symid_t INVALID_SYMBOL_ID
slick::orderbook::OrderUpdate OrderUpdate
utils::fixed_string< sizeof(MarketDataUpdate::symbol)> symbol_name_t
An instrument name at its wire width.
void onOrderUpdate(const OrderUpdate &update) override
OrderBookObserver(Symbol *symbol)
void onPriceLevelUpdate(const PriceLevelUpdate &update) override
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,...
utils::RingBuffer< MDTrade > trade_history_
SelfMatchPreventionMode smp_mode_
symbol_name_t symbol_
Stored at wire width so publishing can copy the whole field without reading past the end of a shorter...
void cancelOrder(Order *order, time_t request_time)
std::tuple< OrdRejectReason, std::vector< TradeSummaryInfo > > addOrder(Order *order, time_t request_time)
Order * findOrderByOrderId(const char *order_id) const
engine::MatchingEngine * matching_engine_
static constexpr size_t TRADE_HISTORY_CAPACITY
Recent trades published on this instrument's tape, newest at the back.
std::vector< MDLevel > md_level_update_cache_
void onOrderUpdate(const OrderUpdate &update)
Called when an individual order is updated (L3 event).
Symbol()
Both caches are filled by book observers and drained by the exchange thread, which only ever clear()s...
Order * findOrderByClientOrderId(const char *client_order_id) const
Symbol(const Symbol &)=delete
std::vector< MDOrder > md_order_update_cache_
Symbol(Symbol &&other) noexcept
void recordTrade(const MDTrade &trade)
Appends a trade to the tape history that serves the subscribe snapshot.
std::shared_ptr< OrderBook > order_book_
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,...
void onPriceLevelUpdate(const PriceLevelUpdate &update)
std::atomic_uint16_t num_subscriptions_
void clearTradeHistory()
Drops the tape history, so a venue that is about to resend its own trade snapshot does not end up rep...
std::tuple< OrdRejectReason, std::vector< TradeSummaryInfo > > modifyOrder(Order *order, price_t new_price, qty_t new_qty, time_t request_time)
std::shared_ptr< OrderBookObserver > book_observer_
Symbol & operator=(const Symbol &)=delete
Order * findOrder(uint64_t order_id) const
Quantity one trade print removed from phantom liquidity at one price, kept until a level update stamp...