From 86d8d7dafb91a2cbb19f1e87956e55aa4207aece Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Thu, 14 Jun 2018 18:35:15 -0400 Subject: [PATCH] Add seconds_to_recenter and max_open_ladders to UI.conf. Remove seconds and ticks from LadderSettings as it should not be stored per-ladder. --- .../Modules/Trading/LadderWindowFactory.cs | 3 +-- .../spark/view/Spark/Ladder/LadderSettings.cs | 12 ++-------- .../view/Spark/Ladder/RecenterCountdown.cs | 9 ++++---- .../spark/view/Spark/Utilities/WorkLoop.cs | 2 +- src/lib/config/protos/UI.proto | 22 +++++-------------- 5 files changed, 13 insertions(+), 35 deletions(-) diff --git a/src/client/spark/Modules/Trading/LadderWindowFactory.cs b/src/client/spark/Modules/Trading/LadderWindowFactory.cs index 135d2c61a..210f8b4e4 100644 --- a/src/client/spark/Modules/Trading/LadderWindowFactory.cs +++ b/src/client/spark/Modules/Trading/LadderWindowFactory.cs @@ -30,8 +30,7 @@ namespace bts.shell { _wm = wm; _settings_hub = settings_hub; _orders_model = orders_model; - var window_props = Configuration.get(); - _max_ladders_open = (int)(window_props?.ladder?.max_total_open ?? 75); + _max_ladders_open = (int)(Configuration.get().max_open_ladders); _dispose = Disposable.Create( bus.subscribe(SparkTags.SecuritiesTag).Subscribe(s => _securities = s), bus.subscribe(SparkTags.ShowLadderTag).OnDispatcher().Subscribe(s => show_windows(new[] { s })), diff --git a/src/client/spark/view/Spark/Ladder/LadderSettings.cs b/src/client/spark/view/Spark/Ladder/LadderSettings.cs index f676d98e0..0a00e54d6 100644 --- a/src/client/spark/view/Spark/Ladder/LadderSettings.cs +++ b/src/client/spark/view/Spark/Ladder/LadderSettings.cs @@ -125,8 +125,6 @@ namespace mbts.spark { last_column = last_column, calculator_buttons = new[] { 1, 5, 10, 25, 50, 100 }, scroll_bar_visible = false, - ticks_to_recenter = 10, - seconds_to_recenter = 300, default_order_type = CustomOrderDefinition.CustomOneofCase.Limit, default_time_in_force = TimeInForce.Day, animate_recenter = true, @@ -164,10 +162,8 @@ namespace mbts.spark { public int[] calculator_buttons { get; set; } [ProtoMember(10)] public bool scroll_bar_visible { get; set; } - [ProtoMember(11)] - public int ticks_to_recenter { get; set; } - [ProtoMember(12)] - public int seconds_to_recenter { get; set; } + // USED [ProtoMember(11)] + // USED [ProtoMember(12)] [ProtoMember(13)] public CustomOrderDefinition.CustomOneofCase default_order_type { get; set; } [ProtoMember(14)] @@ -198,8 +194,6 @@ namespace mbts.spark { other.price_column.safe_equals(price_column) && other.calculator_buttons.safe_equals(calculator_buttons, (a, b) => a.SequenceEqual(b)) && other.scroll_bar_visible == scroll_bar_visible && - other.ticks_to_recenter == ticks_to_recenter && - other.seconds_to_recenter == seconds_to_recenter && other.default_order_type == default_order_type && other.default_time_in_force == default_time_in_force && other.size == size && @@ -223,8 +217,6 @@ namespace mbts.spark { last_column.GetHashCode(), calculator_buttons.GetHashCode(), scroll_bar_visible.GetHashCode(), - ticks_to_recenter.GetHashCode(), - seconds_to_recenter.GetHashCode(), default_order_type.GetHashCode(), default_time_in_force.GetHashCode(), size.GetHashCode(), diff --git a/src/client/spark/view/Spark/Ladder/RecenterCountdown.cs b/src/client/spark/view/Spark/Ladder/RecenterCountdown.cs index 8faa2d466..3e97c523d 100644 --- a/src/client/spark/view/Spark/Ladder/RecenterCountdown.cs +++ b/src/client/spark/view/Spark/Ladder/RecenterCountdown.cs @@ -17,16 +17,17 @@ namespace mbts.spark { }; SecurityImmutable? _security; MDConsumerHandle _handle; - LadderSettings _settings; DateTime _last_recenter = DateTime.MaxValue; double _last_mid = 0.0; IDisposable _dispose; + readonly TimeSpan _seconds_to_center; public RecenterCountdown() { DataContextChanged += RecenterCountdown_DataContextChanged; Unloaded += (o,e) => on_unload(false); _timer.Tick += _timer_Tick; _timer.Start(); + _seconds_to_center = TimeSpan.FromSeconds(config.Configuration.get().seconds_to_recenter); } static (double,double) tick_range(double price, int tick_count, ContractSpecificationImmutable spec) { @@ -34,11 +35,10 @@ namespace mbts.spark { } private void _timer_Tick(object sender, EventArgs e) { - if (_settings != null && _security != null) { + if (_security != null) { var mid = _handle.mid(); - (double low, double high) = tick_range(_last_mid, _settings.ticks_to_recenter, _security.Value.ContractSpec); if (//mid < low || mid > high || - (_last_recenter + TimeSpan.FromSeconds(_settings.seconds_to_recenter) < DateTime.UtcNow)) { + (_last_recenter + _seconds_to_center < DateTime.UtcNow)) { trigger_recenter(mid); } } @@ -59,7 +59,6 @@ namespace mbts.spark { vm.OnDisposed += on_unload; _dispose = Disposable.Create( - vm.settings.Subscribe(s => _settings = s), Disposable.Create(() => vm.OnDisposed -= on_unload)); } } diff --git a/src/client/spark/view/Spark/Utilities/WorkLoop.cs b/src/client/spark/view/Spark/Utilities/WorkLoop.cs index df9ccc29f..35c607f8f 100644 --- a/src/client/spark/view/Spark/Utilities/WorkLoop.cs +++ b/src/client/spark/view/Spark/Utilities/WorkLoop.cs @@ -10,7 +10,7 @@ namespace mbts.spark { static readonly TimeSpan default_interval; static WorkLoop() { - var timer_params = config.Configuration.get(); + var timer_params = config.Configuration.get(); default_priority = Enum.TryParse(timer_params.priority, true, out DispatcherPriority p) ? p : DispatcherPriority.ApplicationIdle; default_interval = TimeSpan.FromMilliseconds(timer_params.interval_ms); } diff --git a/src/lib/config/protos/UI.proto b/src/lib/config/protos/UI.proto index 285e4ba54..c42cda2c9 100644 --- a/src/lib/config/protos/UI.proto +++ b/src/lib/config/protos/UI.proto @@ -28,20 +28,6 @@ message IShellModuleProps repeated ModuleProps module = 1; } -message IShellWindowProps { - // TODO: Maybe IWindowManager should be responsible for total-windows-open limits? - // To achieve that we would need to use a sort of type-windowprops map. - // However, that makes the problem more complicated, and at this point we are just aiming to limit n_ladders open. - // So for now, just let the LadderWindowFactory manage this. - message WindowProps { - // NOTE: 50 will be a dangerously high default for most other windows (than Ladder), - // so be careful if you add other WindowProps members. - optional uint32 max_total_open = 1 [default = 50]; - } - - optional WindowProps ladder = 1; -} - message GridSettings { optional string font_family = 1 [default = "Calibri"]; optional float font_size = 2 [default = 10]; @@ -62,9 +48,11 @@ message ShellLimits { optional uint64 limit_group_memory_mb = 3; } -// priorities (ordered): SystemIdle, ApplicationIdle, ContextIdle, Background, Input, Loaded, Render, DataBind, Normal, Send -// It seems like all priorities higher than ApplicationIdle choke the main thread. -message LadderTimerParams { +message LadderKnobs { + // priorities (ordered): SystemIdle, ApplicationIdle, ContextIdle, Background, Input, Loaded, Render, DataBind, Normal, Send + // It seems like all priorities higher than ApplicationIdle choke the main thread. optional string priority = 1 [default = "ApplicationIdle"]; optional double interval_ms = 2 [default = 100]; + optional uint32 seconds_to_recenter = 3 [default = 300]; + optional uint32 max_open_ladders = 4 [default = 75]; } \ No newline at end of file