diff --git a/src/client/spark/Modules/Spreader/ExecutionStrategyEditor.xaml.cs b/src/client/spark/Modules/Spreader/ExecutionStrategyEditor.xaml.cs index ae43ba468..578f9ba04 100644 --- a/src/client/spark/Modules/Spreader/ExecutionStrategyEditor.xaml.cs +++ b/src/client/spark/Modules/Spreader/ExecutionStrategyEditor.xaml.cs @@ -70,14 +70,19 @@ namespace mbts.ui.spark public static readonly DependencyProperty ParameterRowsProperty = DependencyProperty.Register("ParameterRows", typeof(IEnumerable), typeof(ExecutionStrategyEditor), new PropertyMetadata(Enumerable.Empty(), OnParameterRowsChanged)); static void OnParameterRowsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { - var rows = e.NewValue as IEnumerable; - if (rows != null) { - var prv = CollectionViewSource.GetDefaultView(rows); - int n_groups = rows.Max(r => r.section_path.Length); - for (int i = 0; i < n_groups; i++) prv.GroupDescriptions.Add(new PropertyGroupDescription($"[{i}]")); + var new_rows = e.NewValue as IEnumerable ?? Enumerable.Empty(); + var target = (ExecutionStrategyEditor)d; + if (target._rows == null) { + target._rows = new ObservableCollection(new_rows); + var prv = CollectionViewSource.GetDefaultView(target._rows); + int n_groups = target._rows.Max(r => r.section_path.Length); + for (int i = 0; i < n_groups; i++) + prv.GroupDescriptions.Add(new PropertyGroupDescription($"[{i}]")); d.SetValue(ParameterRowsViewPropertyKey, prv); - } else d.SetValue(ParameterRowsViewPropertyKey, null); + } else + target._rows.SetItems(new_rows); } + ObservableCollection _rows; public IEnumerable ParameterRows { get => GetValue(ParameterRowsProperty) as IEnumerable; set => SetValue(ParameterRowsProperty, value); } #endregion diff --git a/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs b/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs index 69d246549..9057f17fd 100644 --- a/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs +++ b/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs @@ -4,6 +4,7 @@ using mbts.spark.utilities; using mbts.ui; using mbts.ui.shell; using mbts.ui.spark; +using mbts.utils; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -17,6 +18,16 @@ namespace mbts.spark { /// partial class SyntheticEditorVM : ViewModelBase, IDisposable { readonly Security _synthetic; + readonly ExecutionStrategyImmutable _strategy; + /// + /// Inititalizes a new instance of SyntheticEditorVM class. This constructor may only be used for already-existing synthetic securities. + /// + /// The already-existing synthetic security who's strategy may be modified + /// The already-existing strategy that may be modified + public SyntheticEditorVM(SpreaderModel model, SecurityImmutable synthetic, ExecutionStrategyImmutable strategy) + : this(null, model, synthetic, strategy) { + ExceptionAssert.InvalidOperation.That(synthetic.Id != 0, "This constructor may only be used for already-existing synthetic securities."); + } /// /// Initializes a new instance of SyntheticEditorVM class. The commit command will create a new Synthetic if synthetic's Id is 0, otherwise it will modify the existing synthetic's strategy. /// @@ -26,11 +37,11 @@ namespace mbts.spark { public SyntheticEditorVM(IBus bus, SpreaderModel model, SecurityImmutable synthetic, ExecutionStrategyImmutable strategy) { _synthetic = synthetic.CloneToMutable(); _synthetic.Exchange = Venue.Bts; - var mutable_strategy = strategy.CloneToMutable(); + _strategy = strategy; leg_tuples = new ObservableCollection( _synthetic.Synthetic.Legs .OrderBy(l => l.Security, SecurityHelper.Comparer.Instance) - .Select(l => new LegSpreaderParamsTuple(l, mutable_strategy.LegParamsMap[l.Security.Id])) + .Select(l => new LegSpreaderParamsTuple(l, _strategy.LegParamsMap[l.Security.Id].Clone())) ); is_new = synthetic.Id == 0; if (is_new) { @@ -49,15 +60,13 @@ namespace mbts.spark { _synthetic.Synthetic.Legs.Clear(); _synthetic.Synthetic.Legs.AddRange(leg_tuples.Select(l => l.leg).OrderBy(l => l.Security, SecurityHelper.Comparer.Instance)); _synthetic.Symbol = _deduce_symbol(_synthetic); - mutable_strategy.LegParamsMap.Clear(); - foreach (var lt in leg_tuples) mutable_strategy.LegParamsMap.Add(lt.leg.Security.Id, lt.leg_params); uint? id = await model.create_synthetic(_synthetic); - if (id.HasValue && id != 0) await model.save_strategy(id.Value, new ExecutionStrategyImmutable(mutable_strategy)); + if (id.HasValue && id != 0) await model.save_strategy(id.Value, create_strategy()); }); } else { title = $"Edit '{synthetic.Synthetic.Name}'"; icon = Icons.Knight; - commit = new DelegateCommand(async () => await model.save_strategy(_synthetic.Id, new ExecutionStrategyImmutable(mutable_strategy))); + commit = new DelegateCommand(async () => await model.save_strategy(_synthetic.Id, create_strategy())); } rows = new IRowModel [] { new SizeModel(!is_new), @@ -96,6 +105,13 @@ namespace mbts.spark { public ICommand remove_leg { get; } public ContractPickerModel contract_picker_model { get; } + public ExecutionStrategyImmutable create_strategy() { + var mutable_strategy = _strategy.CloneToMutable(); + mutable_strategy.LegParamsMap.Clear(); + foreach (var lt in leg_tuples) mutable_strategy.LegParamsMap.Add(lt.leg.Security.Id, lt.leg_params); + return new ExecutionStrategyImmutable(mutable_strategy); + } + public void Dispose() { foreach (var r in rows) r.Dispose(); contract_picker_model?.Dispose(); diff --git a/src/client/spark/view/Controls/Order/OrderDetailsPopupControl.xaml b/src/client/spark/view/Controls/Order/OrderDetailsPopupControl.xaml index 8662d6f30..f55a15ff0 100644 --- a/src/client/spark/view/Controls/Order/OrderDetailsPopupControl.xaml +++ b/src/client/spark/view/Controls/Order/OrderDetailsPopupControl.xaml @@ -1,6 +1,5 @@  +