From 96fc54ff0f33fe614b0b7458fa469db391cd3307 Mon Sep 17 00:00:00 2001 From: Pedro Pinto Date: Fri, 5 Jul 2019 14:35:18 -0400 Subject: [PATCH 1/3] Added ticks_off to top algo server side. --- src/lib/api/services/OrderService.proto | 2 +- .../orders/algo/algo_orders/TopAlgo.cpp | 31 ++++++++++++++++--- .../orders/algo/algo_orders/TopAlgo.h | 2 +- src/web/CMakeDeps.cmake | 2 +- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/lib/api/services/OrderService.proto b/src/lib/api/services/OrderService.proto index 1908ff7bf..42d7f2531 100644 --- a/src/lib/api/services/OrderService.proto +++ b/src/lib/api/services/OrderService.proto @@ -160,8 +160,8 @@ message JoinOrderDefinition { CustomOrderDefinition child = 6; } message TopOrderDefinition { - uint32 watch_level_tick_offset = 1; spark.QuantityMeasure top_threshold = 2; + uint32 ticks_off = 3; CustomOrderDefinition child = 6; } message TriggerOrderDefinition { diff --git a/src/lib/orderman/orders/algo/algo_orders/TopAlgo.cpp b/src/lib/orderman/orders/algo/algo_orders/TopAlgo.cpp index e16aaa5d8..b7fac256e 100644 --- a/src/lib/orderman/orders/algo/algo_orders/TopAlgo.cpp +++ b/src/lib/orderman/orders/algo/algo_orders/TopAlgo.cpp @@ -16,6 +16,7 @@ using namespace api::orderman; struct TopAlgo::PImpl { IAlgoServices *algo; spark::QuantityMeasure top_threshold_measure; + uint32_t ticks_off = 0; OrderKey child_key = null_order_key(); ChildTemplate *child_template = nullptr; Book last_book; @@ -41,7 +42,7 @@ OrderOpResult TopAlgo::do_before_launch(IBeforeLaunchAlgoServices &serv) { } me->top_threshold_measure = top.top_threshold(); - + me->ticks_off = top.ticks_off(); if (!serv.is_attaching()) { // if we are not attaching create a child template so we can // quickly launch our child when the time comes. @@ -93,7 +94,7 @@ void TopAlgo::do_update(api::orderman::Update const &update) { void TopAlgo::on_book(SecurityKey, Book const &b) { me->last_book = b; - ensure_min_quantity(); + ensure_order_meets_constraints(); } void TopAlgo::on_child_change(OrderKey, ChildState const &st) { @@ -111,14 +112,14 @@ void TopAlgo::on_child_change(OrderKey, ChildState const &st) { } } -bool TopAlgo::ensure_min_quantity() { +bool TopAlgo::ensure_order_meets_constraints() { LOG(OrderMan, Diag, "Top order {} received book update. Current top of book: {}@{}", algo().order_key().value(), top_of_book_quantity().value(), top_of_book_price().value()); if (better_than_top()) { - LOG(OrderMan, Diag, + LOG(OrderMan, Info, "Top order {} became better than the top of the book, canceling", algo().order_key().value()); algo().cancel("Order would become BBO"); @@ -135,7 +136,7 @@ bool TopAlgo::ensure_min_quantity() { algo().order_key().value(), total_min_quantity, top_of_book_quantity().value()); if (top_of_book_quantity() < Quantity(total_min_quantity)) { - LOG(OrderMan, Diag, + LOG(OrderMan, Info, "Top order {} is canceling because min quantiy is not met", algo().order_key().value()); algo().cancel("Top of book is below threshold"); @@ -147,6 +148,26 @@ bool TopAlgo::ensure_min_quantity() { algo().order_key().value(), algo().price().value(), top_of_book_price().value()); + if (me->ticks_off > 0) { + auto tick_diff = securities::price_diff_to_ticks( + algo().price().value(), top_of_book_price().value(), + securities::tick_size(algo().security()).value()); + if (std::abs(tick_diff) <= (int)me->ticks_off) { + LOG(OrderMan, Info, + "Top order {} price {} is less than {} ticks away from top ({}). " + "Canceling", + algo().order_key().value(), algo().price().value(), + me->ticks_off + 1, top_of_book_price().value()); + algo().cancel("Order is too close to top of the book"); + return false; + } else + LOG(OrderMan, Diag, + "Top order {} price {} is {} ticks away from top. Top: {} Ticks " + "off: {}", + algo().order_key().value(), algo().price().value(), + std::abs(tick_diff), top_of_book_price().value(), me->ticks_off); + } + return true; } diff --git a/src/lib/orderman/orders/algo/algo_orders/TopAlgo.h b/src/lib/orderman/orders/algo/algo_orders/TopAlgo.h index 3648dc50c..857f12f88 100644 --- a/src/lib/orderman/orders/algo/algo_orders/TopAlgo.h +++ b/src/lib/orderman/orders/algo/algo_orders/TopAlgo.h @@ -27,7 +27,7 @@ class TopAlgo : public IAlgoOrder { bool at_top_of_book() const; bool better_than_top() const; Quantity min_quantity_at_top() const; - bool ensure_min_quantity(); + bool ensure_order_meets_constraints(); bool has_running_child() const; Price top_of_book_price() const; Quantity top_of_book_quantity() const; diff --git a/src/web/CMakeDeps.cmake b/src/web/CMakeDeps.cmake index 40156daa9..1843aaacb 100644 --- a/src/web/CMakeDeps.cmake +++ b/src/web/CMakeDeps.cmake @@ -1 +1 @@ -set(sources ../../externals/linux/include/google/protobuf/descriptor.proto;../../externals/linux/include/google/protobuf/timestamp.proto;../lib/api/apicore.proto;../lib/api/apigateway.proto;../lib/api/apioptions.proto;../lib/api/services/AdminService.proto;../lib/api/services/AlgoDefinitionService.proto;../lib/api/services/AlgoService.proto;../lib/api/services/ApiUnitTestService.proto;../lib/api/services/AuthService.proto;../lib/api/services/ErrorReportService.proto;../lib/api/services/HelloService.proto;../lib/api/services/MBOService.proto;../lib/api/services/MarketDataAuxiliaryService.proto;../lib/api/services/MarketDataRelay.proto;../lib/api/services/OrderService.proto;../lib/api/services/OutOfProcessURLListener.proto;../lib/api/services/PersistenceService.proto;../lib/api/services/PositionService.proto;../lib/api/services/ShellDiagnosticService.proto;../lib/api/services/ShellLatencyService.proto;../lib/api/services/SyntheticSecurityService.proto;../lib/domain_model/Security.proto;../lib/md/protos/co2.proto;../lib/sparkproto/SparkProtos.proto;api/build.sh;api/node_modules/exit/test/fixtures/create-files.sh;api/node_modules/protobufjs/cli/node_modules/acorn-jsx/node_modules/acorn/bin/update_authors.sh;api/node_modules/watch/release.sh;api/quiet_build.sh;api/src/DynamicService.ts;api/src/ServiceContext.ts;api/src/bts_assert.ts;ui/src/Access.fs;ui/src/Accounts/ClipLimits.fs;ui/src/Accounts/ProductLimits.fs;ui/src/Accounts/SecurityLimits.fs;ui/src/Accounts/State.fs;ui/src/Accounts/Types.fs;ui/src/Accounts/View.fs;ui/src/App.fs;ui/src/Cmd.fs;ui/src/Controls/Button.fs;ui/src/Controls/DataGrid.fs;ui/src/Controls/Fields.fs;ui/src/Controls/Modal.fs;ui/src/Controls/ReactGrid.fs;ui/src/Controls/Table.fs;ui/src/Controls/nbsp.fs;ui/src/Global.fs;ui/src/Imports.fs;ui/src/Lens.fs;ui/src/Login/Login.fs;ui/src/Nav.fs;ui/src/State.fs;ui/src/Types.fs;ui/src/Users/State.fs;ui/src/Users/Types.fs;ui/src/Users/View.fs;ui/src/Util/EnumUtils.fs;ui/src/Util/JSMap.fs;ui/src/obj/Debug/netstandard2.0/ui.AssemblyInfo.fs) \ No newline at end of file +set(sources ../../externals/linux/include/google/protobuf/descriptor.proto;../../externals/linux/include/google/protobuf/timestamp.proto;../lib/api/apicore.proto;../lib/api/apigateway.proto;../lib/api/apioptions.proto;../lib/api/services/AdminService.proto;../lib/api/services/AlgoDefinitionService.proto;../lib/api/services/AlgoService.proto;../lib/api/services/ApiUnitTestService.proto;../lib/api/services/AuthService.proto;../lib/api/services/ErrorReportService.proto;../lib/api/services/HelloService.proto;../lib/api/services/MBOService.proto;../lib/api/services/MarketDataAuxiliaryService.proto;../lib/api/services/MarketDataRelay.proto;../lib/api/services/OrderService.proto;../lib/api/services/OutOfProcessURLListener.proto;../lib/api/services/PersistenceService.proto;../lib/api/services/PositionService.proto;../lib/api/services/ShellDiagnosticService.proto;../lib/api/services/ShellLatencyService.proto;../lib/api/services/SyntheticSecurityService.proto;../lib/domain_model/Security.proto;../lib/md/protos/co2.proto;../lib/sparkproto/SparkProtos.proto;api/build.sh;api/node_modules/exit/test/fixtures/create-files.sh;api/node_modules/protobufjs/cli/node_modules/acorn-jsx/node_modules/acorn/bin/update_authors.sh;api/node_modules/psl/scripts/ci-build.sh;api/node_modules/watch/release.sh;api/quiet_build.sh;api/src/DynamicService.ts;api/src/ServiceContext.ts;api/src/bts_assert.ts;ui/src/Access.fs;ui/src/Accounts/ClipLimits.fs;ui/src/Accounts/ProductLimits.fs;ui/src/Accounts/SecurityLimits.fs;ui/src/Accounts/State.fs;ui/src/Accounts/Types.fs;ui/src/Accounts/View.fs;ui/src/App.fs;ui/src/Cmd.fs;ui/src/Controls/Button.fs;ui/src/Controls/DataGrid.fs;ui/src/Controls/Fields.fs;ui/src/Controls/Modal.fs;ui/src/Controls/ReactGrid.fs;ui/src/Controls/Table.fs;ui/src/Controls/nbsp.fs;ui/src/Global.fs;ui/src/Imports.fs;ui/src/Lens.fs;ui/src/Login/Login.fs;ui/src/Nav.fs;ui/src/State.fs;ui/src/Types.fs;ui/src/Users/State.fs;ui/src/Users/Types.fs;ui/src/Users/View.fs;ui/src/Util/EnumUtils.fs;ui/src/Util/JSMap.fs;ui/src/obj/Debug/netstandard2.0/ui.AssemblyInfo.fs) \ No newline at end of file From f5bbc4245f7e09b8cd85a2c99e9f156e1a5b06f7 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Fri, 5 Jul 2019 16:12:32 -0500 Subject: [PATCH 2/3] SP-111 / SP-113 Add ticks off parameter to top algo UI --- src/client/spark/Orders/OrderDataHelper.cs | 4 ++-- src/client/spark/Orders/OrderTypeVMs/TopOrderVM.cs | 3 +++ .../view/Controls/Order/AlgoContentTemplateSelector.xaml | 6 +++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/client/spark/Orders/OrderDataHelper.cs b/src/client/spark/Orders/OrderDataHelper.cs index 81e342b38..e3a8179b1 100644 --- a/src/client/spark/Orders/OrderDataHelper.cs +++ b/src/client/spark/Orders/OrderDataHelper.cs @@ -715,7 +715,7 @@ namespace mbts.spark.utilities { !b.HasChild); public static bool top_equals(TopOrderDefinitionImmutable a, TopOrderDefinitionImmutable b) => - a.WatchLevelTickOffset == b.WatchLevelTickOffset && + a.TicksOff == b.TicksOff && (a.HasTopThreshold ? b.HasTopThreshold && quantity_measure_equals(a.TopThreshold, b.TopThreshold) : !b.HasTopThreshold) && @@ -906,7 +906,7 @@ namespace mbts.spark.utilities { add_component(_get_hash(_get_tick_child(tick))); break; case CustomOrderDefinition.CustomOneofCase.Top: - add_component(def.Top.WatchLevelTickOffset.GetHashCode()); + add_component(def.Top.TicksOff.GetHashCode()); add_component(def.Top.HasTopThreshold ? def.Top.TopThreshold.GetHashCode() : 0); add_component(_get_top_child(def.Top).GetHashCode()); break; diff --git a/src/client/spark/Orders/OrderTypeVMs/TopOrderVM.cs b/src/client/spark/Orders/OrderTypeVMs/TopOrderVM.cs index 984303599..8f41cbbaf 100644 --- a/src/client/spark/Orders/OrderTypeVMs/TopOrderVM.cs +++ b/src/client/spark/Orders/OrderTypeVMs/TopOrderVM.cs @@ -5,13 +5,16 @@ using TopDefi = bts.api.orderman.TopOrderDefinitionImmutable; namespace mbts.spark { static partial class OrderTypeVMFactory { class TopOrderVM : OrderTypeVMBase { + readonly Property _ticks_off; readonly Property _top_threshold; public TopOrderVM(AlgoKey key, string display_name, AlgoEditingPermissions editing_permissions) : base(key, display_name, editing_permissions) { + _ticks_off = add_nullable_property(nameof(ticks_off), TopDef.TicksOffFieldNumber); _top_threshold = add_property(nameof(top_threshold), TopDef.TopThresholdFieldNumber, new QuantityMeasureImmutable(new QuantityMeasure { Ratio = 1.0, Absolute = 1 })); } + public uint? ticks_off { get => _ticks_off.Value; set => _ticks_off.set(value); } public QuantityMeasureImmutable? top_threshold { get => _top_threshold.Value; set => _top_threshold.set(value); } } } diff --git a/src/client/spark/view/Controls/Order/AlgoContentTemplateSelector.xaml b/src/client/spark/view/Controls/Order/AlgoContentTemplateSelector.xaml index c64d29f52..a3b82fee1 100644 --- a/src/client/spark/view/Controls/Order/AlgoContentTemplateSelector.xaml +++ b/src/client/spark/view/Controls/Order/AlgoContentTemplateSelector.xaml @@ -489,6 +489,8 @@ + + @@ -503,9 +505,11 @@ + Ticks Off + Date: Mon, 8 Jul 2019 14:09:37 -0400 Subject: [PATCH 3/3] Fixed a bug in top update --- doc/user/content/release_notes/_index.md | 1 + src/lib/orderman/orders/algo/algo_orders/TopAlgo.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/doc/user/content/release_notes/_index.md b/doc/user/content/release_notes/_index.md index ffb88aee2..0bf2094a9 100644 --- a/doc/user/content/release_notes/_index.md +++ b/doc/user/content/release_notes/_index.md @@ -9,6 +9,7 @@ insert_anchor_links = "right" - In the ladder made last trade more distinctive when overlayed on the volumn column - In the ladder, corrected display of volume tool tip - In the ladder, changed the consolidation of last trade to consider only the price ignoring aggressor changes + - Added an option for the Top Algo to delete itself if within N ticks from top of book ### Internal Changes - Ensure that admin logins are always allowed to login, regardless of keycode status. diff --git a/src/lib/orderman/orders/algo/algo_orders/TopAlgo.cpp b/src/lib/orderman/orders/algo/algo_orders/TopAlgo.cpp index b7fac256e..acb3f3f29 100644 --- a/src/lib/orderman/orders/algo/algo_orders/TopAlgo.cpp +++ b/src/lib/orderman/orders/algo/algo_orders/TopAlgo.cpp @@ -88,6 +88,7 @@ void TopAlgo::do_update(api::orderman::Update const &update) { auto &top_update = update.custom().top(); *child_update.mutable_custom() = top_update.child(); me->top_threshold_measure = top_update.top_threshold(); + me->ticks_off = top_update.ticks_off(); } algo().update_child(me->child_key, child_update); }