10 slick::queue<OrderResponse> &response_queue
21 return std::make_tuple(*done, std::vector<TradeSummaryInfo>{});
28 while (order_qty > 0) {
29 auto best_level = book.getBestLevel<
static_cast<slick::orderbook::Side
>(SIDE)>();
37 auto& orders = best_level->orders;
38 assert(!orders.empty() &&
"Price level has no orders");
41 auto &book_order = *orders.begin();
44 auto* full_book_order = book.
findOrder(book_order.order_id);
47 bool should_continue =
handleSelfMatch(engine, order, full_book_order, book,
48 request_time, event_time, seq_num, smp_mode);
50 if (!should_continue) [[unlikely]] {
60 qty_t trade_qty = std::min<qty_t>(order_qty, book_order.quantity);
61 order_qty -= trade_qty;
62 if (!
fillResting<SIDE>(ctx, order, book_order.order_id, full_book_order, best_level->price, trade_qty, order_qty)) [[unlikely]] {
73 MatchContext ctx{engine, book, event_time, seq_num};
76 auto best_level = book.getBestLevel<
static_cast<slick::orderbook::Side
>(SIDE)>();
84 auto& orders = best_level->orders;
85 assert(!orders.empty() &&
"Price level has no orders");
87 auto &book_order = *orders.begin();
89 std::min<qty_t>(qty, book_order.quantity), qty)) [[unlikely]] {
101 ? matchOrder<Side::SELL>(*
this, order, order_price, order_qty, book, request_time, event_time, seq_num, smp_mode)
102 : matchOrder<Side::BUY>(*
this, order, order_price, order_qty, book, request_time, event_time, seq_num, smp_mode);
107 ? matchFeed<Side::SELL>(*
this, order_id, price, qty, book, event_time, seq_num)
108 : matchFeed<Side::BUY>(*
this, order_id, price, qty, book, event_time, seq_num);
Order * findOrder(uint64_t id)
std::tuple< OrdRejectReason, std::vector< TradeSummaryInfo > > match(Order *order, price_t order_price, qty_t order_qty, OrderBook &book, time_t request_time, time_t event_time, uint64_t seq_num=0, SelfMatchPreventionMode smp_mode=SelfMatchPreventionMode::NONE) override
FifoMatchingEngine(slick::queue< OrderResponse > &response_queue)
MatchingEngine(slick::queue< OrderResponse > &response_queue)
bool isSelfMatch(const Order *incoming_order, const Order *book_order)
bool fillRestingFromFeed(MatchContext &ctx, uint64_t aggressor_id, uint64_t book_order_id, price_t price, qty_t trade_qty, qty_t &qty)
One fill of market-data liquidity against a resting order.
void cancelUnrestableRemainder(MatchingEngine &engine, const Order *order, qty_t remaining, slick::sim::time_t request_time)
What cannot rest is cancelled: an IOC's remainder, and a market order's, which would otherwise rest a...
bool handleSelfMatch(MatchingEngine &engine, const Order *incoming_order, Order *book_order, OrderBook &book, slick::sim::time_t request_time, uint64_t event_time, uint64_t seq_num, SelfMatchPreventionMode smp_mode)
bool fillResting(MatchContext &ctx, Order *order, uint64_t book_order_id, Order *full_book_order, price_t price, qty_t trade_qty, qty_t remaining)
One fill of a client order against a resting order.
std::optional< OrdRejectReason > prepareOrder(MatchingEngine &engine, Order *order, price_t order_price, qty_t order_qty, OrderBook &book, slick::sim::time_t request_time, SelfMatchPreventionMode smp_mode)
Everything a client order goes through before it matches: the CANCEL_NEWEST pre-check,...
Conversions between wire decimals with a constant exponent of -9 (CME PRICE9, ICE Decimal9) and the s...
bool isPriceBetterOrEqual(price_t a, price_t b)
constexpr price_t NULL_PRICE
State one match() call carries through its fills.
std::vector< TradeSummaryInfo > summaries