diff --git a/src/server/sparkd/spreader/SpreaderBase.h b/src/server/sparkd/spreader/SpreaderBase.h index 86035033a..df3ed0954 100644 --- a/src/server/sparkd/spreader/SpreaderBase.h +++ b/src/server/sparkd/spreader/SpreaderBase.h @@ -24,7 +24,8 @@ public: class Book { public: size_t n_levels() const; - std::tuple level(api::BuySell,size_t) const; + Price settlement() const; + std::tuple level(api::BuySell,size_t level) const; }; class ChildFill { @@ -45,49 +46,70 @@ class SpreaderCreate {}; // whatever is supported for spreader changes class SpreaderUpdate {}; +struct SpreaderSubscriptions +{ + std::vector securities_for_md; + AccountName account_for_limit_check; + orderman::OperatorID operator_for_limit_check; +}; + class SpreaderBase { public: // called once and only once, before any other calls - virtual void init (orderman::OrderKey my_key,SpreaderCreate const&) = 0; + virtual SpreaderSubscriptions init (orderman::OrderKey my_key,SpreaderCreate const&) = 0; // called if the execution venue is working, even if it the // connection event happened before the spreader was created. in // other words, on_connect() is always called. Spreader should - // start by assuming the venue is disconnected + // start by assuming the venue is disconnected and wait until they + // receive on_connect(). virtual void on_connect() = 0; + // called if the venue disconnects. will only be called if there // was previous on_connect() virtual void on_disconnect() = 0; // supports late join, i.e. even if there is no new market data // since the spreader was created a bootstrap market data event - // will be artifially generated. + // will be artifially generated. Only market data events for the + // securites returned in the init() will be forwarded. Market data + // subscriptionsa are automatically canceled when the spreader + // transitions to a terminal state. virtual void on_md(api::Security const&s, Book const&b) = 0; - // called whenever a child order updates + + // called whenever a child order updates, as long as the spreader + // is not in a terminal state. virtual void on_child_order ( OrderState const&state, std::vector const&fills) = 0; - // called at an unspecified rate as long as the spreader is active - // (i.e. OrderSTatus != CANCELED, REJECTED, EXPIRED, FILLED) + // called at an unspecified rate as long as the spreader is not in + // a terminal state virtual void on_time(TimeStamp const&ts) = 0; - // Called when the user hits update or cancel in the shell + // Called when the user hits update or cancel in the shell, as long + // as the spreader is not in a terminal state virtual void on_user_update (SpreaderUpdate const&) = 0; virtual void on_user_cancel () = 0; + + // called when a limit breanch affects either the operator or the + // account specified in the return value of init() , as long as the + // spreader is not in a terminal state + virtual void on_limit_breach() = 0; + + // called when a system error occurs + virtual void on_system_error() = 0; protected: // call this whenever the Spreader changes its OrderState void report_state(OrderState const&); - // call this once at the start. callbacks will continue until the - // spreader reports terminal state (CANCELED, REJECTED, EXPIRED, - // FILLED) - void subscribe_md(std::vector const &securities); - + // call this when spining a new order. for speed create a template // object before with the things that do not commonly change. orderman::OrderKey create_child(OrderTemplate const&t, Price price, Quantity quantity); + // call this to update an order you previously created void update_child(orderman::OrderKey, Price price, Quantity quantity); + // call this to cancel an order you previously created void cancel_child(orderman::OrderKey);