From 849adc5d7c91c0fd4fda2bde2958f22f575da35b Mon Sep 17 00:00:00 2001 From: taha afzal Date: Fri, 22 Oct 2021 07:47:39 -0400 Subject: [PATCH] Completed OrderGatewy inteface --- src/lib/md/emumba/OrderGateway.h | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/lib/md/emumba/OrderGateway.h b/src/lib/md/emumba/OrderGateway.h index 8b9b1e332..ee7ee3009 100644 --- a/src/lib/md/emumba/OrderGateway.h +++ b/src/lib/md/emumba/OrderGateway.h @@ -17,6 +17,8 @@ enum class TimeInForce { struct DeribitOrderDefinition {}; struct GlbxOrderDefinition {}; +// This contains the order parameters common to all exchanges. It is sent once +// when a new order is launched struct OrderDefinition { SecurityID security_id; Side side; @@ -25,51 +27,60 @@ struct OrderDefinition { std::string account; AccountID account_id; TimeInForce time_in_force; + // Exchange specific order definition (ex if a certain exchange offers + // Iceberg orders, this is where its parameters will be) const std::variant exchange_order = {DeribitOrderDefinition{}}; }; +// Sent once per order, when the order is first launched (launching an order, +// placing, firing, sending all mean the same) struct NewOrder { OrderDefinition order_def; Price price; Quantity qty; }; +// Structure for order modifications (also know as cancel-replace at some +// exchanges). struct OrderUpdate { OrderKey order_key; Price price; Quantity qty; }; -enum class ChildStatus { WORKING, COMPLETED, CANCELED }; +// Order can be in one of these states +enum class OrderStatus { WORKING, COMPLETED, CANCELED }; struct DeribitOrderState {}; struct GlbxOrderState {}; struct OrderState { - ChildStatus status; + OrderStatus status; Quantity total_fills; - Price avg_price; - Quantity last_fills; - Price last_price; + Price avg_filled_price; + // If there is any exchange specific order state std::variant exchange_order_state; }; +// Order cacllbacks are passed to this interface class IOrderListener { - virtual void on_order_update( + virtual void on_order_state( OrderKey order_key, const OrderState &order_state) = 0; }; // Anologous to the MarketDataGateway. All order interactions happen through // this class. class OrderGateway { - // This is called just once to register the client, to receive callback for - // order updates + // This is called just once to register the listening class (to get order + // callbacks) void register_once(IOrderListener *listener) noexcept; - // New orders are enterred via this function. An internal OrderKey is + // New orders are placed via this function. An internal OrderKey is // generated for every order new order. This OrderKey is used for subsequent - // API calls + // calls as well as IOrderListener callbacks OrderKey launch_new_order(const NewOrder &new_order); + // An order is changed via this method. We can start by allowing only price + // and qty changes (these are by far the most common changes) void update_order(const OrderUpdate &order_update); void cancel_order(OrderKey order_key); };