diff --git a/doc/user/content/release_notes/_index.md b/doc/user/content/release_notes/_index.md index 1c9a618eb..0286a8dcf 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 - Address a rare issue that could lead to an error report on UI exit ### Internal Changes - Ensure that admin logins are always allowed to login, regardless of keycode status. @@ -407,7 +408,8 @@ insert_anchor_links = "right" - This is configurable from a ladder's settings as well ### Customized settings in all windows - All windows now contain a settings page where grid settings (font color, size, etc) are applied - - These settings can be saved on a per-window basis or as a Default for newly-launched windows + - These settings can be saved on a per-window basis or as a Default for newly-launched windows + ## 1.3.1 Through 1.3.4 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 + 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. @@ -87,13 +88,14 @@ 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); } 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 +113,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 +137,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 +149,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;