Improved comments on order plugin example.

This commit is contained in:
Pedro Pinto committed 2019-04-26 13:29:26 -04:00
1 parent 992b64c08a
commit 23bec87ad0
1 file changed
+16 -14
+16 -14
View File
@@ -39,13 +39,13 @@ class DynamicJoin : public IAlgoOrder {
void try_to_join();
};
// The tree stages our algo goes through. We start by waiting to
// The three stages our algo goes through. We start by waiting to
// observe the book for our security (WAITING_FOR_MD). Once we have a
// book we use it to derive our target price and we continue to
// monitor the book to see if we should join the market
// (WAITING_TO_JOIN). Once the size and price constraints are met we
// jump to the target price and (JOINED). We remain in the JOINED
// state until our order is filled or canceled.
// jump to the target price (JOINED). We remain in the JOINED state
// until our order is filled or canceled.
enum class DynamicJoin::Status { WAITING_FOR_MD, WAITING_TO_JOIN, JOINED };
// All state information needed for this algo
@@ -64,7 +64,7 @@ DynamicJoin::~DynamicJoin() {}
IAlgoServices &DynamicJoin::algo_services() const { return *me->algo_services; }
// This is called outside of the latency sensitive path
// once. Expensive initialization should be done here, rather than the
// once. Expensive initialization should be done here, rather than
// in do_launch()
OrderOpResult DynamicJoin::do_before_launch(IBeforeLaunchAlgoServices &serv) {
auto &def = serv.definition();
@@ -97,11 +97,12 @@ OrderOpResult DynamicJoin::do_before_launch(IBeforeLaunchAlgoServices &serv) {
// (i.e. beyond what we obtained through serv.definition()) so
// we can just use a default constructed LimitOrderDefinition.
*child_def.mutable_custom_def()->mutable_limit() = LimitOrderDefinition{};
// Now just build and cache the order template for future use
// Now just build the child template and cache it for future use
me->child_template = &(serv.make_child_template(child_def));
} else {
// If we are attaching to an existing order then we do not need
// to spawn a new child, so there is nothing to do here.
// to spawn a new child, so there is no need to setup a child
// template
}
// All is good, return a default constructed OrderOpResult which
@@ -133,7 +134,7 @@ void DynamicJoin::do_launch(IAlgoServices &services) {
void DynamicJoin::do_launch_attached(IAlgoServices &services,
OrderKey attached_order, ChildState st) {
// The order was launched and attached to an existing order, with
// key k and current state st
// key 'attached_order' and current state 'st'
// Cache our algo services
me->algo_services = &services;
@@ -151,14 +152,15 @@ void DynamicJoin::do_launch_attached(IAlgoServices &services,
// Simulate a child change so we can update our own state to
// reflect that of the child order we attached to. From this point
// forward there is no distinction between an algo instance that
// spawned a child and one that attached to an existing order.
// spawned a new child order and one that attached to an existing
// order.
on_child_change(attached_order, st);
}
// Called when a human (or a supervising algo) updates a parameter for
// this algo. The implementation should validate the update and
// depending on the validation outcome either apply the update or
// terminate the algo.
// this algo. The implementation validates the update and depending on
// the validation outcome either applies the update or terminates the
// algo.
void DynamicJoin::do_update(api::orderman::Update const &update) {
LOG(OrderMan, Diag, "DynamicJoin k: {} receiving update: {}",
algo_services().order_key().value(), utils::pb::to_string(update));
@@ -222,7 +224,7 @@ void DynamicJoin::on_book(SecurityKey, Book const &b) {
if (other_side_top.size() > 0) {
// First time we get the opposite side market, we will use
// this price as the target price to join at
// this price as the target price for the join
me->status = Status::WAITING_TO_JOIN;
me->book_at_inception = b;
LOG(OrderMan, Diag,
@@ -236,14 +238,14 @@ void DynamicJoin::on_book(SecurityKey, Book const &b) {
// Nothing to do at this point
break;
case Status::WAITING_TO_JOIN:
// Check if reached the target
// Check if we reached the target and join if so
try_to_join();
break;
}
}
// Given the current book, our target price and our min quantity
// parameter, check if its time to join
// parameter, join if appropriate
void DynamicJoin::try_to_join() {
bts_assert(me->status == Status::WAITING_TO_JOIN);