From fe647044f80daaef6ba735c1e30db1ac3612e820 Mon Sep 17 00:00:00 2001 From: Taha Afzal Date: Mon, 9 Sep 2019 15:03:52 -0400 Subject: [PATCH] Adding comments to SpreaderUtils --- .../orders/algo/algo_orders/PyramidAlgo.cpp | 37 ++++++++++++++----- .../spreader_orders/spreader/SpreaderUtils.h | 8 ++-- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/lib/orderman/orders/algo/algo_orders/PyramidAlgo.cpp b/src/lib/orderman/orders/algo/algo_orders/PyramidAlgo.cpp index 51d9641ed..e6ef95071 100644 --- a/src/lib/orderman/orders/algo/algo_orders/PyramidAlgo.cpp +++ b/src/lib/orderman/orders/algo/algo_orders/PyramidAlgo.cpp @@ -25,6 +25,8 @@ struct LegData{ OrderKey order_key; ChildState order_state; Book book; + Quantity top_delete; + Quantity cover_payup; LegData (size_t index_a, SecurityKey sec_key_a, api::Side side_a, @@ -36,7 +38,9 @@ struct LegData{ order_template (order_template_a), order_key(null_order_key()), order_state(), - book() + book(), + top_delete(0), + cover_payup(0) { } const BookSide& opp_md() const{ @@ -131,7 +135,7 @@ void PyramidAlgo::do_update(const api::orderman::Update& update) { case PyramidAlgo::Status::WAITING_FOR_MD: me->out_price = Price(update.price()); me->out_qty = Quantity(update.quantity()); - // TODO, check is qty >= filled (filled >=0 in the case of attach) + // TODO, check if qty >= filled (filled >=0 in the case of attach) break; case PyramidAlgo::Status::WORKING: me->out_price = Price(update.price()); @@ -242,8 +246,10 @@ PyramidAlgo::_get_creation_params(const CustomOrderDefinition& cod, } std::tuple -PyramidAlgo::_get_update_params(const Update&, +PyramidAlgo::_get_update_params(const Update& update, const PyramidAlgoParams& curr_params){ + auto rv = _convert_params(update.custom()); + // TODO: compare contracts and dont allow them to change return std::make_tuple(curr_params,true,std::string("")); } @@ -307,12 +313,25 @@ bool PyramidAlgo::_working_state_met() const{ const auto& ps = l.opp_md()[0]; cover_sum += ps.price(); } - // TODO, check for delete - return !os::is_nan(cover_sum) && - ((me->side == api::Side::SIDE_BUY && - me->out_price.value() <= cover_sum) || - (me->side == api::Side::SIDE_SELL && - me->out_price.value() >= cover_sum)); + bool rv = !os::is_nan(cover_sum) && + ((me->side == api::Side::SIDE_BUY && + me->out_price.value() <= cover_sum) || + (me->side == api::Side::SIDE_SELL && + me->out_price.value() >= cover_sum)); + if (!rv){ + // price condition does not met, but if the + // cum qty at the top leg price is > threashold + // then the condition is met () + const auto& top_leg = me->legs[0]; + Quantity cumm_level_qty; + SpreaderUtils::find_qty_upto_price_level(top_leg.book, + top_leg.side, + Price(me->out_price), + 0.0, + cumm_level_qty); + rv = cumm_level_qty.value() > top_leg.top_delete.value(); + } + return rv; } api::Side PyramidAlgo::_opp (api::Side side){ diff --git a/src/lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h b/src/lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h index 0d34acfe2..559fa2c96 100644 --- a/src/lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h +++ b/src/lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h @@ -238,11 +238,9 @@ public: } } // CRITICAL PATH (for hedging) - // travserses the book to locate the target_price, - // and finds the qty at the target price and the - // cum qty upto that price. - // returns false if the target_price is not found. - // this is used to find the qty and cumm_qty + // travserses the book to locate the target_price, + // and finds the cumm qty up to that level (last our arg) + // Returns false if the target_price is not found. static bool find_qty_upto_price_level (const Book& book, api::Side book_side, Price target_price,