From 99621eecb60de85b2d0484f06a70f6a4f879b3ca Mon Sep 17 00:00:00 2001 From: John Colvin Date: Mon, 12 Nov 2018 18:23:18 -0600 Subject: [PATCH] Algo Popups open by default --- .../Modules/Trading/LadderWindowFactory.cs | 13 ++++++++++-- .../Orders/OrderTypeVMs/OrderTypeVMFactory.cs | 10 +++++++-- .../Orders/OrderTypeVMs/SpreaderOrderVM.cs | 21 ++++++++++++++----- .../Orders/OrderTypeVMs/StopLimitOrderVM.cs | 2 +- src/client/spark/Themes/generic.xaml | 1 + 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/client/spark/Modules/Trading/LadderWindowFactory.cs b/src/client/spark/Modules/Trading/LadderWindowFactory.cs index ff6a809de..bb64a6d2f 100644 --- a/src/client/spark/Modules/Trading/LadderWindowFactory.cs +++ b/src/client/spark/Modules/Trading/LadderWindowFactory.cs @@ -25,6 +25,8 @@ namespace bts.shell { readonly OrdersModel _orders_model; readonly MarketDataAuxiliaryModel _md_auxiliary_model; readonly int _max_ladders_open; + readonly int _thread_count = Configuration.get().enabled ? Environment.ProcessorCount : 1; + IReadOnlyDictionary _securities = new Dictionary(); public LadderWindowFactory(IShellModule owner, IBus bus, IWindowManager wm, UserSettingsHub settings_hub, OrdersModel orders_model, MarketDataAuxiliaryModel md_auxiliary_model) @@ -36,6 +38,14 @@ namespace bts.shell { _md_auxiliary_model = md_auxiliary_model; var knobs = Configuration.get(); _max_ladders_open = (int)(knobs.max_open_ladders); +#if DEBUG + string thread_count_arg = Environment.GetCommandLineArgs() + .Select(a => a.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries)) + .Where(a => a.Length == 2 && a[0].iequals("ladderthreads")) + .FirstOrDefault()?[1]; + if (thread_count_arg != null) + _thread_count = int.TryParse(thread_count_arg, out int i) ? Math.Max(i, 1) : Environment.ProcessorCount; +#endif _security_timeout = TimeSpan.FromSeconds(Math.Max(15, knobs.security_timeout_secs)); _dispose = Disposable.Create( bus.subscribe(SparkTags.SecuritiesTag).Subscribe(s => _securities = s), @@ -57,7 +67,6 @@ namespace bts.shell { int _ladder_count = 0; IShellWindow create_ladder_window(SecurityMD md, LadderSettings state_settings) { - var id = Interlocked.Increment(ref _ladder_count) % Environment.ProcessorCount; var view = new Lazy(() => { var model = new LadderModel(md, _orders_model, _md_auxiliary_model); var settings_manager = new WindowSettingsManager( @@ -67,7 +76,7 @@ namespace bts.shell { var vm = new LadderVM(_bus, model, settings_manager); return new LadderView(vm); }); - string thread = Configuration.get().enabled ? $"Ladder{id:00}" : ""; + string thread = _thread_count > 1 ? $"Ladder{Interlocked.Increment(ref _ladder_count) % _thread_count:00}" : ""; return ShellWindow.create( module, md.security.ToString(), _window_type, view, (v,s) => save(_get_state(((LadderView)v).vm), s), diff --git a/src/client/spark/Orders/OrderTypeVMs/OrderTypeVMFactory.cs b/src/client/spark/Orders/OrderTypeVMs/OrderTypeVMFactory.cs index 81f5914cb..f244af628 100644 --- a/src/client/spark/Orders/OrderTypeVMs/OrderTypeVMFactory.cs +++ b/src/client/spark/Orders/OrderTypeVMs/OrderTypeVMFactory.cs @@ -117,8 +117,14 @@ namespace mbts.spark { public SecurityImmutable? security => security_md?.security ?? (SecurityImmutable?)null; public ContractSpecificationImmutable spec => security.spec_or_default(); - public ICollection child_order_types => _child_order_choices ?? (_child_order_choices = - ObservableAutoWrapper.Create(_order_types, ot => create(ot.key.type, ot.key.name, ot.display_name, model, _security_md_source))); + public ICollection child_order_types => _child_order_choices ?? (_child_order_choices = + ObservableAutoWrapper.Create(_order_types, ot => { + var ovm = create(ot.key.type, ot.key.name, ot.display_name, model, _security_md_source); + ovm.init(); + if (ovm.has_editable_properties) + ovm.editable_properties_open = true; + return ovm; + })); public IOrderTypeVM child_order { get { diff --git a/src/client/spark/Orders/OrderTypeVMs/SpreaderOrderVM.cs b/src/client/spark/Orders/OrderTypeVMs/SpreaderOrderVM.cs index 7ac53dcc6..0b8764727 100644 --- a/src/client/spark/Orders/OrderTypeVMs/SpreaderOrderVM.cs +++ b/src/client/spark/Orders/OrderTypeVMs/SpreaderOrderVM.cs @@ -5,6 +5,7 @@ using mbts.ui.controls; using System; using System.Collections.Generic; using System.Reactive.Linq; +using System.Windows.Input; namespace mbts.spark { static partial class OrderTypeVMFactory { @@ -93,17 +94,27 @@ namespace mbts.spark { _owner._template.Changed -= _order_template_changed; } + static SyntheticEditorVM _mk_vm(OrdersModel model, SpreaderOrderDefinitionImmutable def) => + new SyntheticEditorVM(model.spreader, def.Security, def.ExecutionStrategy, model.security_has_working_orders(def.Security.Id)); + + static DialogSkirtItem _mk_save_item(ICommand commit) => + new DialogSkirtItem("Save Strategy", commit); + void _init() { if (_vm == null && _owner.template.HasValue) { - var def = _owner.template.Value; - _vm = new SyntheticEditorVM(_owner.model.spreader, def.Security, def.ExecutionStrategy, _owner.model.security_has_working_orders(def.Security.Id)); - _save_strategy_item = new DialogSkirtItem("Save Strategy", _vm.commit); + _vm = _mk_vm(_owner.model, _owner.template.Value); + _save_strategy_item = _mk_save_item(_vm.commit); } } void _order_template_changed(SpreaderOrderDefinitionImmutable? oldval, SpreaderOrderDefinitionImmutable? newval) { - if (_vm != null && newval.HasValue) - _vm.set_synthetic(newval.Value.Security, newval.Value.ExecutionStrategy); + if (newval.HasValue) { + if (_vm == null) { + _vm = _mk_vm(_owner.model, newval.Value); + _save_strategy_item = _mk_save_item(_vm.commit); + _owner.RaisePropertyChanged(nameof(strategy_editor), nameof(skirt_items)); + } else _vm.set_synthetic(newval.Value.Security, newval.Value.ExecutionStrategy); + } } } } diff --git a/src/client/spark/Orders/OrderTypeVMs/StopLimitOrderVM.cs b/src/client/spark/Orders/OrderTypeVMs/StopLimitOrderVM.cs index 0af2b19ec..edb40f0ba 100644 --- a/src/client/spark/Orders/OrderTypeVMs/StopLimitOrderVM.cs +++ b/src/client/spark/Orders/OrderTypeVMs/StopLimitOrderVM.cs @@ -26,7 +26,7 @@ namespace mbts.spark { private class StopLimitOrderVM : OrderTypeVMBase, IDisposable { UserProperty _stop_price; - InlineStopLimitOrderProperties _inline_props; + InlineStopLimitOrderProperties _inline_props = new InlineStopLimitOrderProperties(() => new InlineUserProperty(double.NaN)); IDisposable _dispose; internal StopLimitOrderVM(OrdersModel model, IObservable security_md_source, string id, string display_name) diff --git a/src/client/spark/Themes/generic.xaml b/src/client/spark/Themes/generic.xaml index 65f1bb5a1..7807bae7b 100644 --- a/src/client/spark/Themes/generic.xaml +++ b/src/client/spark/Themes/generic.xaml @@ -35,6 +35,7 @@ +