diff --git a/src/server/sparkd/exchange_sim/book/OrderMatcher.h b/src/server/sparkd/exchange_sim/book/OrderMatcher.h index 4e4301762..f5d58ac43 100644 --- a/src/server/sparkd/exchange_sim/book/OrderMatcher.h +++ b/src/server/sparkd/exchange_sim/book/OrderMatcher.h @@ -14,27 +14,56 @@ namespace bts { namespace ex_sim { +// An order matcher maintains a book of same security orders +// and generates matches as the sides cross class OrderMatcher { public: OrderMatcher(); ~OrderMatcher(); + // Add a new order, returning any updates to the new order or + // existing ones resulting from matching void add_new(Order const &, std::vector *out); + + // Add a new order or, if a threshold of existing orders at same + // level from the same owner is met, merge its quantity with the + // last similar order. The merge is usefull to keep memory growth + // in check. Return any changes resulting from matching on the new + // order. void add_or_merge(Order const &, std::vector *out); + // Change an existing order, returning any changed orders that + // resulted matches made possible by the update. void update(std::string const &clorid, Price, Quantity, std::vector *out); + + // Cancel an existing order, removing it from the book void cancel(std::string const &clorid); + // Try to reduce the quantity available at the specified level, + // side by the specified owner, by the specified amount. The + // updated orders are not returned. void try_reduce_quantity_at_level(api::Side, Price level, Quantity by_quantity, std::string const& order_owner); + + // Take the all the orders and consolidated their quantities, per + // level, in a book structure Book get_book() const; - OrderBook get_order_book(const char*) const; - + + // Copy all the orders *not* owned by owner to a PB type that can + // be stored on disk + OrderBook get_order_book(const char* owner) const; + + // Get a single order Order const *get_order(std::string const &clorid); - + + // Orders are kept in two multisets (one for bids, one for + // offers). Each multiset uses a comparison operator that uses + // first the price and then the time_changed of each order to sort + // the orders. FIFO matching is a matter of peeling off matching + // entries from bid and offer. using OrdersSide = std::multiset; struct Trade {