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

Classes

struct  MatchContext
 State one match() call carries through its fills. More...

Enumerations

enum class  Reach : uint8_t { Queue , Level }
 How far into a price level an aggressor reaches. More...

Functions

bool isSelfMatch (const Order *incoming_order, const Order *book_order)
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)
template<Side SIDE, Reach REACH>
bool wouldSelfMatch (const Order *order, price_t order_price, qty_t order_qty, OrderBook &book)
template<Side SIDE>
bool canFillCompletely (const Order *order, price_t order_price, qty_t order_qty, OrderBook &book, SelfMatchPreventionMode smp_mode)
template<Side SIDE, Reach REACH>
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, the ack, the FOK pre-check, and applying a pending replace.
template<Side SIDE>
void recordTrade (MatchContext &ctx, uint64_t aggressor_id, uint64_t book_order_id, price_t price, qty_t trade_qty, qty_t phantom_qty)
 Adds one fill to the trade summaries, which are aggregated per price level: a new summary when the price changes, otherwise one more leg on the current one.
template<Side SIDE>
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.
template<Side SIDE>
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 at NULL_PRICE.

Enumeration Type Documentation

◆ Reach

enum class slick::sim::engine::detail::Reach : uint8_t
strong

How far into a price level an aggressor reaches.

FIFO trades the queue front to back until its quantity runs out. Pro-rata allocates across the whole level, so every order on a level it reaches may trade.

Enumerator
Queue 
Level 

Definition at line 21 of file match_common.hpp.

Function Documentation

◆ cancelUnrestableRemainder()

void slick::sim::engine::detail::cancelUnrestableRemainder ( MatchingEngine & engine,
const Order * order,
qty_t remaining,
slick::sim::time_t request_time )
inline

What cannot rest is cancelled: an IOC's remainder, and a market order's, which would otherwise rest at NULL_PRICE.

Definition at line 366 of file match_common.hpp.

References slick::sim::Order::id, slick::sim::Order::restsRemainder(), slick::sim::OrderIdentity::symbol, and slick::sim::utils::fixed_string< N >::view().

◆ canFillCompletely()

template<Side SIDE>
bool slick::sim::engine::detail::canFillCompletely ( const Order * order,
price_t order_price,
qty_t order_qty,
OrderBook & book,
SelfMatchPreventionMode smp_mode )

◆ fillResting()

template<Side SIDE>
bool slick::sim::engine::detail::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.

remaining is the aggressor's quantity after this fill, so reaching 0 closes the book's batch. full_book_order is the resting order's Order, or nullptr for phantom liquidity. Returns false when the book declines the execution: the aggressor has already been filled and reported by then, so the caller stops rather than unwinding.

Definition at line 288 of file match_common.hpp.

References slick::sim::engine::detail::MatchContext::book, slick::sim::OrderBook::deleteOrder(), slick::sim::engine::detail::MatchContext::engine, slick::sim::engine::detail::MatchContext::event_time, slick::sim::OrderBook::executeOrder(), slick::sim::utils::executeOrder(), slick::sim::Order::id, slick::sim::Order::leaves_quantity, slick::sim::engine::MatchingEngine::publishOrderExecution(), recordTrade(), slick::sim::engine::detail::MatchContext::seq_num, slick::sim::OrderIdentity::symbol, and slick::sim::utils::fixed_string< N >::view().

◆ fillRestingFromFeed()

template<Side SIDE>
bool slick::sim::engine::detail::fillRestingFromFeed ( MatchContext & ctx,
uint64_t aggressor_id,
uint64_t book_order_id,
price_t price,
qty_t trade_qty,
qty_t & qty )

◆ handleSelfMatch()

◆ isSelfMatch()

bool slick::sim::engine::detail::isSelfMatch ( const Order * incoming_order,
const Order * book_order )
inline

Definition at line 25 of file match_common.hpp.

References slick::sim::Order::client_id.

Referenced by canFillCompletely(), and wouldSelfMatch().

◆ prepareOrder()

template<Side SIDE, Reach REACH>
std::optional< OrdRejectReason > slick::sim::engine::detail::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, the ack, the FOK pre-check, and applying a pending replace.

Returns the reject reason when the order is finished here, or nullopt when it goes on to match its leaves_quantity.

Definition at line 174 of file match_common.hpp.

References slick::sim::CANCEL_NEWEST, canFillCompletely(), slick::sim::Order::cum_quantity, slick::sim::FILL_OR_KILL, slick::sim::FOK_CANNOT_FILL, slick::sim::Order::id, slick::sim::Order::leaves_quantity, slick::sim::NONE, slick::sim::PENDING_NEW, slick::sim::PENDING_REPLACE, slick::sim::Order::price, slick::sim::Order::quantity, slick::sim::SMP, slick::sim::Order::status, slick::sim::OrderIdentity::symbol, slick::sim::Order::time_in_force, slick::sim::utils::fixed_string< N >::view(), and wouldSelfMatch().

◆ recordTrade()

template<Side SIDE>
void slick::sim::engine::detail::recordTrade ( MatchContext & ctx,
uint64_t aggressor_id,
uint64_t book_order_id,
price_t price,
qty_t trade_qty,
qty_t phantom_qty )

◆ wouldSelfMatch()

template<Side SIDE, Reach REACH>
bool slick::sim::engine::detail::wouldSelfMatch ( const Order * order,
price_t order_price,
qty_t order_qty,
OrderBook & book )