From c40eef7b03a5b577b63f307c661990e8a0c2e3d9 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Fri, 12 Jul 2019 12:04:35 -0400 Subject: [PATCH] SP-131 --- .../orders/algo/algo_orders/DormanAlgo.cpp | 5 +- .../algo/algo_orders/tests/dorman_tests.cpp | 48 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/lib/orderman/orders/algo/algo_orders/DormanAlgo.cpp b/src/lib/orderman/orders/algo/algo_orders/DormanAlgo.cpp index bddccb3df..bc0bad1fa 100644 --- a/src/lib/orderman/orders/algo/algo_orders/DormanAlgo.cpp +++ b/src/lib/orderman/orders/algo/algo_orders/DormanAlgo.cpp @@ -248,8 +248,11 @@ void DormanAlgo::on_book(SecurityKey key, const Book& book) { } // See if we need to adjust else { + if (target == me->exposed_qty) { + me->next_size = std::nullopt; + } // If target < size reduce immidiately - if (target < me->exposed_qty) { + else if (target < me->exposed_qty) { update_child(target); me->next_size = std::nullopt; } diff --git a/src/lib/orderman/orders/algo/algo_orders/tests/dorman_tests.cpp b/src/lib/orderman/orders/algo/algo_orders/tests/dorman_tests.cpp index 324dfc2d7..5b38da869 100644 --- a/src/lib/orderman/orders/algo/algo_orders/tests/dorman_tests.cpp +++ b/src/lib/orderman/orders/algo/algo_orders/tests/dorman_tests.cpp @@ -649,6 +649,54 @@ TEST_CASE("Dorman updates child", "[algo][dorman]") { // When updating the Dorman price the price of the child should also update } +TEST_CASE("Dorman market move up then back down", "[algo][dorman]") { + // Start dorman algo + // Move market up so we plan to increase the exposed qty after trail_seconds + // Move market back down before trail_seconds elapses + // check that algo does *not* increase exposure + + AlgoParams input; + input.steps.step_table = { + {500, 250}, + {1000, 450}, + {2000, 650}, + {3500, 750}, + }; + input.steps.maximum = 750; + input.steps.trail_seconds = 30; + input.clip_limit = 100; + api::orderman::OrderDefinition def; + def.set_side(api::SIDE_BUY); + def.mutable_custom_def()->mutable_dynamic()->CopyFrom(to_dynamic_order_params(input)); + // auto price = Price { some_price.price() }; + + AlgoTestDriver state(def, some_price, Quantity {1337}); + auto secid = SecurityKey(state.security().id()); + + Book book(secid); + book.bid()[0] = { some_price, 350 }; + state.update_book(book); + REQUIRE(state.before_launch().ok()); + state.launch(); + REQUIRE(state.algo().exposed_qty() == Quantity(250)); + REQUIRE(state.child_orders().size() == 1); + state.advance_time(std::chrono::seconds(1)); + + // Update book sets future quantity = 450 + book.bid()[0] = { some_price, 999 }; + state.update_book(book); + state.advance_time(std::chrono::seconds(10)); + // Algo does not increase exposure after 10 second + REQUIRE(state.algo().exposed_qty() == Quantity(250)); + + book.bid()[0] = { some_price, 425 }; + state.update_book(book); + state.advance_time(std::chrono::seconds(40)); + // Algo does not increase exposure after trail_seconds + REQUIRE(state.algo().exposed_qty() == Quantity(250)); + +} + }}}//namespace