OrderBook - sync attached-order-params with common values from selected orders

This commit is contained in:
John Colvin committed 2019-03-14 21:13:31 -05:00
1 parent ce3a4562d9
commit 6c0dc80d43
2 files changed
+20 -45

No files matched your search

@@ -5,7 +5,6 @@ using bts.api.orderman;
using bts.shell;
using bts.spark;
using bts.utils;
using mbts.collections;
using mbts.persist;
using mbts.spark.utilities;
using mbts.ui;
@@ -86,10 +85,7 @@ namespace mbts.spark {
begin_attaching += on_begin_attaching;
end_attaching += on_end_attaching;
concat_disposable(
_selected_algo_mon.subscribe_common_algo().Subscribe(on_common_selected_algo_changed),
_selected_algo_mon.subscribe_common_sec_md().Subscribe(on_common_selected_sec_md_changed),
_selected_algo_mon.subscribe_price().Subscribe(on_common_price_changed),
_selected_algo_mon.subscribe_size().Subscribe(on_common_size_changed),
connect_common_selected_params(order_mod_vm),
_selected_algo_mon.subscribe_all_active().Subscribe(on_all_selected_orders_active_changed),
model.on_order_tuples.OnDispatcher().Subscribe(_row_collection.update),
grid_settings_manager,
@@ -126,17 +122,6 @@ namespace mbts.spark {
return ft => keys.Contains(ft.fill.OrderKey);
}
void on_filter_changed() => _row_collection.filter = _columns.get_filter();
void on_common_selected_algo_changed(CustomOrderDefinitionImmutable? newval) {
if (newval.HasValue) {
order_mod_vm.algo_vm.load_def(newval.Value);
} else {
order_mod_vm.algo_vm.algo_root = null;
}
}
void on_common_selected_sec_md_changed(SecurityMD? newval) => order_mod_vm.security_md = newval;
void on_common_price_changed(double newval) => order_mod_vm.price = newval;
void on_common_size_changed(uint? newval) => order_mod_vm.size_calculator.value = newval;
void on_all_selected_orders_active_changed(bool newval) {
order_mod_vm.algo_vm.editing_permissions_mask = newval ? AlgoEditingPermissions.AllowEditValues : AlgoEditingPermissions.None;
@@ -157,8 +142,21 @@ namespace mbts.spark {
}
}
void on_begin_attaching() => Disposable.replace(ref attach_vm_hooks, _selected_algo_mon.subscribe_common_sec_md().Subscribe(smd => attach_vm.security_md = smd));
void on_begin_attaching() => Disposable.replace(ref attach_vm_hooks, connect_common_selected_params(attach_vm));
void on_end_attaching() => Disposable.dispose(ref attach_vm_hooks);
IDisposable connect_common_selected_params(OrderParamsVM vm) =>
Disposable.Create(
_selected_algo_mon.subscribe_common_algo().Subscribe(newval => {
if (newval.HasValue) {
order_mod_vm.algo_vm.load_def(newval.Value);
} else {
order_mod_vm.algo_vm.algo_root = null;
}
}),
_selected_algo_mon.subscribe_common_sec_md().Subscribe(newval => vm.security_md = newval),
_selected_algo_mon.subscribe_price().Subscribe(newval => vm.price = newval),
_selected_algo_mon.subscribe_size().Subscribe(newval => vm.size_calculator.value = newval));
}
private void _row_collection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) {
@@ -669,4 +667,4 @@ namespace mbts.spark {
}
}
}
}
}
@@ -146,10 +146,7 @@ namespace mbts.ui.spark {
public static readonly DependencyProperty SecurityProperty =
WPFHelper.create_dp<SecurityImmutable?, OrderParamsPanel>(
nameof(Security),
(o, v) => {
if (v.HasValue)
o.SetCurrentValue(ContractSpecProperty, v.Value.ContractSpec);
});
(o, v) => o.CoerceValue(ContractSpecProperty));
public SecurityImmutable? Security {
get => GetValue(SecurityProperty) as SecurityImmutable?;
@@ -162,11 +159,7 @@ namespace mbts.ui.spark {
WPFHelper.create_dp<ContractSpecificationImmutable?, OrderParamsPanel>(
nameof(ContractSpec),
null,
(d, base_value) => {
if (d.Security is SecurityImmutable sec)
return sec.ContractSpec;
return base_value;
});
(d, base_value) => d.Security?.ContractSpec ?? base_value ?? SecurityDataHelper.Defaults.ContractSpecificationImmutable);
public ContractSpecificationImmutable? ContractSpec {
get => GetValue(ContractSpecProperty) as ContractSpecificationImmutable?;
@@ -178,17 +171,7 @@ namespace mbts.ui.spark {
public static readonly DependencyProperty AlgoVMProperty =
WPFHelper.create_dp<AlgoDefinitionVM, OrderParamsPanel>(
nameof(AlgoVM),
(o, v) => {
if (o._algo_editor != null) {
if (v != null) {
//o._algo_editor.DataContext = v;
o._algo_editor.SetCurrentValue(VisibilityProperty, Visibility.Visible);
} else {
//o._algo_editor.DataContext = null;
o._algo_editor.SetCurrentValue(VisibilityProperty, Visibility.Collapsed);
}
}
});
(o, v) => o._algo_editor?.SetCurrentValue(VisibilityProperty, v != null ? Visibility.Visible : Visibility.Collapsed));
public AlgoDefinitionVM AlgoVM {
get => GetValue(AlgoVMProperty) as AlgoDefinitionVM;
@@ -199,13 +182,7 @@ namespace mbts.ui.spark {
AlgoEditorView _algo_editor;
public override void OnApplyTemplate() {
_algo_editor = GetTemplateChild("algo_editor") as AlgoEditorView;
if (_algo_editor != null) {
var vm = AlgoVM;
if (vm == null)
_algo_editor.SetCurrentValue(VisibilityProperty, Visibility.Collapsed);
else
_algo_editor.SetCurrentValue(VisibilityProperty, Visibility.Visible);
}
_algo_editor?.SetCurrentValue(VisibilityProperty, AlgoVM != null ? Visibility.Visible : Visibility.Collapsed);
}
}
}