diff --git a/src/lib/domain_model/Security.h b/src/lib/domain_model/Security.h index 5875271e7..1cdbea215 100644 --- a/src/lib/domain_model/Security.h +++ b/src/lib/domain_model/Security.h @@ -18,6 +18,10 @@ std::string to_str (api::Security const&); std::pair from_str(std::string const&); std::string descriptor(api::Security const&); +inline std::string const&side_name(api::Side side) { + return api::Side_Name(side) ; +} + inline api::Side other_side(api::Side side) { switch (side) { case api::SIDE_BUY: diff --git a/src/lib/orderman/orders/book_algos/LeanOrder2.cpp b/src/lib/orderman/orders/book_algos/LeanOrder2.cpp index 3e2300b9e..c6ae9d749 100644 --- a/src/lib/orderman/orders/book_algos/LeanOrder2.cpp +++ b/src/lib/orderman/orders/book_algos/LeanOrder2.cpp @@ -47,13 +47,27 @@ void LeanOrder2::do_on_ready(bool is_attached) { bts_assert(me->status == Status::WORKING); me->target_price = Price(other_side_top_of_book().price()); + + Quantity trigger_quantity = SpreaderUtils::_quantity_threshold( + jump_threshold(), Quantity(state().quantity())); + + LOG(OrderMan, Diag, + "Starting LeanOrder2 {}, {} {}@{} target price: {} trigger quantity:{}", + key().value(), securities::side_name(definition().side()), + state().quantity(), state().price(), me->target_price.value(), + trigger_quantity.value()); if (!is_attached) { api::orderman::OrderDefinition child_def = definition(); *child_def.mutable_custom_def() = definition().custom_def().lean().child(); launch_child(child_def); + + LOG(OrderMan, Diag, "LeanOrder2 {} launching child", key().value()); + return; + } else { + LOG(OrderMan, Diag, "LeanOrder2 {} attaching to child", key().value()); } try_jump(); } @@ -70,8 +84,23 @@ void LeanOrder2::try_jump() { Quantity trigger_quantity = SpreaderUtils::_quantity_threshold( jump_threshold(), Quantity(state().quantity())); - if (book_moved_away_from_me() || - other_side_top_of_book().size() <= trigger_quantity.value()) + auto book_moved_away = book_moved_away_from_me(); + auto trigger_activated = + other_side_top_of_book().size() <= trigger_quantity.value(); + + if (book_moved_away) + LOG(OrderMan, Diag, "LeanOrder2 {} book moved away from {} to {}", + key().value(), me->target_price.value(), + other_side_top_of_book().price()); + + if (trigger_activated) + LOG(OrderMan, Diag, + "LeanOrder2 {} trigger condition met. Other side size is {} " + "whichs less or equal than {} ", + key().value(), other_side_top_of_book().size(), + trigger_quantity.value()); + + if (book_moved_away || trigger_activated) payup(); } } @@ -113,22 +142,6 @@ void LeanOrder2::payup() { LOG(OrderMan, Diag, "Paying up in LeanOrder2, order: {}", key().value()); auto new_price = me->target_price; - auto limit = - securities::improve_price(my_side(), Price(state().price()), - Price(tick_size().value() * max_jump_size_ticks())); - - if (securities::is_better(my_side(), new_price, limit)) { - // We cannot go this far - LOG(OrderMan, Diag, - "Hit payup limit in LeanOrder2 {}, jump price: {} limit: {}. Order " - "is done", - key().value(), new_price.value(), limit.value()); - update_child(limit, Quantity(state().quantity())); - me->status = Status::DONE; - return; - } - - // We are still under the jump limit, lets jump LOG(OrderMan, Diag, "Payup in LeanOrder2 {}, new price: {}", key().value(), new_price.value()); update_child(new_price, Quantity(state().quantity())); @@ -142,7 +155,7 @@ void LeanOrder2::payup() { me->target_price = Price(level.price()); // If we could not find a new target, bail out_ - if (!securities::is_better(my_side(), me->target_price,new_price)) { + if (!securities::is_better(my_side(), me->target_price, new_price)) { LOG(OrderMan, Diag, "Could not find opposite market to set new target price in " "LeanOrder2, order: {} is done.", @@ -199,6 +212,15 @@ OrderOpResult LeanOrder2::do_on_update(api::orderman::Update const &update) { return OrderOpResult(); } +void LeanOrder2::done() +{ + bts_assert(me->status == Status::WORKING); + me->status = Status::DONE; + + if (parent_key() == null_order_key()) + detach(); +} + md::PriceSize LeanOrder2::other_side_top_of_book() const { return last_book().side(other_side())[0]; } @@ -221,15 +243,7 @@ api::Side LeanOrder2::other_side() const { return securities::other_side(my_side()); } -uint32_t LeanOrder2::max_jump_size_ticks() const { - // this will be changed when we can change the definition and build - // the new UI - return definition().custom_def().lean().max_chase_ticks(); -} - uint32_t LeanOrder2::max_jumps() const { - // this will be changed when we can change the definition and build - // the new UI return definition().custom_def().lean().max_chase_ticks(); } diff --git a/src/lib/orderman/orders/book_algos/LeanOrder2.h b/src/lib/orderman/orders/book_algos/LeanOrder2.h index d7317967b..103ac7b5e 100644 --- a/src/lib/orderman/orders/book_algos/LeanOrder2.h +++ b/src/lib/orderman/orders/book_algos/LeanOrder2.h @@ -24,7 +24,6 @@ private: md::PriceSize other_side_top_of_book() const; spark::QuantityMeasure jump_threshold() const; uint32_t max_jumps() const ; - uint32_t max_jump_size_ticks() const ; api::orderman::LeanOrderDefinition::OnToward on_toward_behaviour() const; bool book_moved_toward_me() const; @@ -34,6 +33,8 @@ private: void on_toward_me_move(); void payup(); + void done(); + std::unique_ptr me; };