OrderBook - modify/revert buttons are not enabled until user changes a param
This commit is contained in:
1 parent
455515f658
commit
42ce4f1bf8
2 files changed
+56
-12
No files matched your search
@@ -83,9 +83,9 @@ namespace mbts.spark {
|
||||
_columns.filter_changed += on_filter_changed;
|
||||
collapse_all_rows_command = new DelegateCommand(_row_collection.collapse_all);
|
||||
expand_all_rows_command = new DelegateCommand(_row_collection.expand_all);
|
||||
var modify_selected_orders_async_cmd = new AsyncCommand(_modify_selected_orders_async, () => _selected_params_mon.all_active);
|
||||
var modify_selected_orders_async_cmd = new AsyncCommand(_modify_selected_orders_async, () => _selected_params_mon.all_active && order_mod_vm.is_dirty);
|
||||
modify_selected_orders_cmd = modify_selected_orders_async_cmd;
|
||||
var revert_selected_orders_cmd = new DelegateCommand(revert_selected_orders, () => _selected_params_mon.all_active);
|
||||
var revert_selected_orders_cmd = new DelegateCommand(order_mod_vm.revert, () => _selected_params_mon.all_active && order_mod_vm.is_dirty);
|
||||
this.revert_selected_orders_cmd = revert_selected_orders_cmd;
|
||||
var send_attached_orders_async_cmd = new AsyncCommand(send_attached_orders_async, () => _selected_params_mon.all_active);
|
||||
send_attached_orders_cmd = send_attached_orders_async_cmd;
|
||||
@@ -181,11 +181,8 @@ namespace mbts.spark {
|
||||
modify_selected_orders_async_cmd.RaiseCanExecuteChanged();
|
||||
revert_selected_orders_cmd.RaiseCanExecuteChanged();
|
||||
send_attached_orders_async_cmd.RaiseCanExecuteChanged();
|
||||
}
|
||||
|
||||
void revert_selected_orders() {
|
||||
foreach (var p in order_mod_vm.algo_vm.algo_root?.enumerate_all_params().empty_if_null())
|
||||
p.revert();
|
||||
can_user_modify_selected_orders = newval;
|
||||
RaisePropertyChanged(nameof(can_user_modify_selected_orders));
|
||||
}
|
||||
|
||||
async Task send_attached_orders_async() {
|
||||
@@ -225,13 +222,17 @@ namespace mbts.spark {
|
||||
IDisposable connect_order_mod_vm() =>
|
||||
Disposable.Create(
|
||||
_selected_params_mon.subscribe_algos().Subscribe(order_mod_vm.algo_vm.load_many),
|
||||
order_mod_vm.subscribe_is_dirty().Subscribe(_ => {
|
||||
modify_selected_orders_async_cmd.RaiseCanExecuteChanged();
|
||||
revert_selected_orders_cmd.RaiseCanExecuteChanged();
|
||||
}),
|
||||
connect_common_selected_params(order_mod_vm));
|
||||
|
||||
IDisposable connect_common_selected_params(OrderParamsVM vm) =>
|
||||
Disposable.Create(
|
||||
_selected_params_mon.subscribe_security_md().Subscribe(newval => vm.security_md = newval),
|
||||
_selected_params_mon.subscribe_price().Subscribe(newval => vm.price = newval),
|
||||
_selected_params_mon.subscribe_size().Subscribe(newval => vm.size_calculator.value = newval),
|
||||
_selected_params_mon.subscribe_price().Subscribe(vm.on_common_price),
|
||||
_selected_params_mon.subscribe_size().Subscribe(vm.on_common_size),
|
||||
_selected_params_mon.subscribe_account().Subscribe(newval => vm.selected_account = newval));
|
||||
}
|
||||
|
||||
@@ -315,6 +316,7 @@ namespace mbts.spark {
|
||||
public bool show_ladder { get => _show_ladder.Value; set => _show_ladder.set(value); }
|
||||
public bool show_fills { get => _show_fills.Value; set => _show_fills.set(value); }
|
||||
public bool show_order_params { get => _show_order_params.Value; set => _show_order_params.set(value); }
|
||||
public bool can_user_modify_selected_orders { get; private set; }
|
||||
public Plurality security_plurality { get; private set; }
|
||||
|
||||
public IObservable<bool> subscribe_show_fills() => _show_fills.observe_current(true);
|
||||
@@ -634,10 +636,12 @@ namespace mbts.spark {
|
||||
public class OrderParamsVM : DisposableViewModelBase {
|
||||
readonly SelectorProperty<AccountTuple, AccountTuple?> _accounts;
|
||||
readonly OrderBookVM _owner;
|
||||
readonly DelegateProperty<bool> _is_dirty;
|
||||
uint? _committed_size;
|
||||
double _committed_price, _price;
|
||||
HashSet<uint> _selected_order_tree = new HashSet<uint>();
|
||||
LadderVM _ladder_vm;
|
||||
SecurityMD? _security_md;
|
||||
double _price = 0;
|
||||
|
||||
public OrderParamsVM(OrderBookVM owner)
|
||||
: this(owner,
|
||||
@@ -662,8 +666,22 @@ namespace mbts.spark {
|
||||
bbo = new BBOVM { security_md = security_md };
|
||||
var param_rows = new ObservableAggregateCollection<AlgoParamRowVM>();
|
||||
this.param_rows = param_rows;
|
||||
var dirty_rows = new HashSet<AlgoParamRowVM>();
|
||||
_is_dirty = backing(nameof(is_dirty), () => !_committed_price.Equals(_price) || _committed_size != size_calculator.value || dirty_rows.Count > 0);
|
||||
_dispose = new CompositeDisposable(bbo, algo_vm,
|
||||
AlgoParamRowsHelper.connect(algo_vm, param_rows, false),
|
||||
size_calculator.value_observable.Subscribe(_ => _is_dirty.refresh()),
|
||||
ObservableAutoWrapper.connect_item_hooks(param_rows, r => {
|
||||
r.param.is_dirty_changed += on_is_dirty_changed;
|
||||
return Disposable.Create(() => r.param.is_dirty_changed -= on_is_dirty_changed);
|
||||
void on_is_dirty_changed(bool is_dirty) {
|
||||
if (is_dirty) {
|
||||
if (dirty_rows.Add(r) && dirty_rows.Count == 1)
|
||||
_is_dirty.refresh();
|
||||
} else if (dirty_rows.Remove(r) && dirty_rows.Count == 0)
|
||||
_is_dirty.refresh();
|
||||
}
|
||||
}),
|
||||
owner._subscribe_throttled_selected_rows().OnDispatcher().Subscribe(_ => {
|
||||
_selected_order_tree = new HashSet<uint>(_owner.selected_hierarchical_rows.Select(r => r.order_key));
|
||||
_reset_ladder_vm();
|
||||
@@ -672,6 +690,8 @@ namespace mbts.spark {
|
||||
};
|
||||
}
|
||||
|
||||
public bool is_dirty => _is_dirty.Value;
|
||||
|
||||
public ReadOnlyObservableCollection<AccountTuple> accounts => _accounts.items;
|
||||
public AccountTuple? selected_account { get => _accounts.selected_item; set => _accounts.selected_item = value; }
|
||||
public SecurityImmutable? security => _owner._selected_params_mon.security;
|
||||
@@ -686,7 +706,13 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
public ContractSpecificationImmutable? spec => security?.ContractSpec;
|
||||
public double price { get => _price; set => Set(ref _price, value); }
|
||||
public double price {
|
||||
get => _price;
|
||||
set {
|
||||
if (Set(ref _price, value))
|
||||
_is_dirty.refresh();
|
||||
}
|
||||
}
|
||||
public CalculatorLogic size_calculator { get; }
|
||||
public AlgoDefinitionVM algo_vm { get; }
|
||||
public IReadOnlyObservableCollection<AlgoParamRowVM> param_rows { get; }
|
||||
@@ -697,6 +723,24 @@ namespace mbts.spark {
|
||||
|
||||
OrdersModel _model => _owner._model;
|
||||
|
||||
public void on_common_price(double price) {
|
||||
this.price = (_committed_price = price);
|
||||
_is_dirty.refresh();
|
||||
}
|
||||
|
||||
public void on_common_size(uint? size) {
|
||||
size_calculator.value = (_committed_size = size);
|
||||
_is_dirty.refresh();
|
||||
}
|
||||
|
||||
public void revert() {
|
||||
price = _committed_price;
|
||||
size_calculator.value = _committed_size;
|
||||
foreach (var r in param_rows)
|
||||
r.param.revert();
|
||||
}
|
||||
public IObservable<bool> subscribe_is_dirty() => _is_dirty.observe_current(true);
|
||||
|
||||
void _reset_ladder_vm() {
|
||||
if (_ladder_vm == null && !_security_md.HasValue)
|
||||
return;
|
||||
|
||||
@@ -438,7 +438,7 @@
|
||||
AlgoRoots="{Binding algo_vm.algo_roots}"
|
||||
SelectedAlgoRoot="{Binding algo_vm.algo_root}"
|
||||
AlgoParamRows="{Binding param_rows}"
|
||||
IsReadOnly="{Binding IsEnabled, ElementName=modify_orders_button, Converter={StaticResource NotConverter}}"
|
||||
IsReadOnly="{Binding can_user_modify_selected_orders, Converter={StaticResource NotConverter}}"
|
||||
>
|
||||
<usp:OrderParamsPanel.CommandBindings>
|
||||
<CommandBinding Command="{x:Static usp:OrderParamsPanel.SetPriceCommand}" Executed="{x:Static usp:OrderParamsPanel.SetPriceExecuted}"/>
|
||||
|
||||
Reference in new issue
Block a user