Clean up ContractPicker (model and view)
This commit is contained in:
1 parent
092f8fc371
commit
6d1bad8b8c
7 files changed
+857
-621
No files matched your search
@@ -31,16 +31,16 @@ namespace bts {
|
||||
Disposable.dispose(ref _dispose);
|
||||
|
||||
void show_pick_one(PartialCommand<SecurityMD> message) =>
|
||||
_show_picker(message, _fmt_pick_one_title, new ContractPickerModel(_bus, false, null), vm => vm.result);
|
||||
_show_picker(message, _fmt_pick_one_title, new ContractPickerModel(_bus, false, null), vm => vm.result.Value);
|
||||
|
||||
void show_filtered_pick_one((PartialCommand<SecurityMD> message, SecurityCriteria global_filter) message_and_filter) =>
|
||||
_show_picker(message_and_filter.message, _fmt_pick_one_title, new ContractPickerModel(_bus, false, null, message_and_filter.global_filter), vm => vm.result);
|
||||
_show_picker(message_and_filter.message, _fmt_pick_one_title, new ContractPickerModel(_bus, false, null, message_and_filter.global_filter), vm => vm.result.Value);
|
||||
|
||||
void show_pick_multiple(PartialCommand<SecurityCriteria> message) =>
|
||||
_show_picker(message, _fmt_pick_multiple_title, new ContractPickerModel(_bus, true, null), vm => vm.result_criteria);
|
||||
_show_picker(message, _fmt_pick_multiple_title, new ContractPickerModel(_bus, true, null), vm => vm.criteria);
|
||||
|
||||
void show_and_edit_pick_multiple((PartialCommand<SecurityCriteria> message, SecurityCriteria existing_criteria) message_and_data) =>
|
||||
_show_picker(message_and_data.message, _fmt_pick_multiple_title, new ContractPickerModel(_bus, true, message_and_data.existing_criteria), vm => vm.result_criteria);
|
||||
_show_picker(message_and_data.message, _fmt_pick_multiple_title, new ContractPickerModel(_bus, true, message_and_data.existing_criteria), vm => vm.criteria);
|
||||
|
||||
static string _fmt_pick_one_title(string message_title) => $"Select a Security for {message_title}";
|
||||
static string _fmt_pick_multiple_title(string message_title) => $"Select Securities for {message_title}";
|
||||
|
||||
@@ -92,9 +92,10 @@ namespace mbts.spark {
|
||||
}));
|
||||
contract_picker_model.cancel_action += _close_new_leg_popup;
|
||||
contract_picker_model.ok_action += () => {
|
||||
if (!leg_tuples.Any(l => l.leg.Security.Id == contract_picker_model.result.security.Id)) {
|
||||
var selected_sec = contract_picker_model.result.Value.security;
|
||||
if (!leg_tuples.Any(l => l.leg.Security.Id == selected_sec.Id)) {
|
||||
leg_tuples.Add(new LegSpreaderParamsTuple(
|
||||
SyntheticDataHelper.Defaults.ContractLeg(contract_picker_model.result.security),
|
||||
SyntheticDataHelper.Defaults.ContractLeg(selected_sec),
|
||||
SyntheticDataHelper.Defaults.LegSpreaderParams
|
||||
));
|
||||
_close_new_leg_popup();
|
||||
|
||||
@@ -9,14 +9,14 @@ namespace mbts.spark.filters {
|
||||
public SecurityCriteriaFilter(ContractPickerModel model, Func<TRow, SecurityImmutable> get_row_val, string prop_name)
|
||||
: base(get_row_val, prop_name) {
|
||||
this.model = model;
|
||||
_security_criteria = this.model.result_criteria;
|
||||
this.model.security_criteria_clause_changed += _on_security_criteria_clause_changed;
|
||||
_security_criteria = this.model.criteria;
|
||||
this.model.criteria_changed += _on_criteria_changed;
|
||||
}
|
||||
|
||||
public ContractPickerModel model { get; }
|
||||
|
||||
public void Dispose() =>
|
||||
model.security_criteria_clause_changed -= _on_security_criteria_clause_changed;
|
||||
model.criteria_changed -= _on_criteria_changed;
|
||||
|
||||
protected override void _clear() {
|
||||
_close();
|
||||
@@ -36,12 +36,12 @@ namespace mbts.spark.filters {
|
||||
protected override void _load_state_internal(SecurityCriteria state) =>
|
||||
_security_criteria = state;
|
||||
|
||||
void _on_security_criteria_clause_changed(object sender, SecurityCriteriaClauseChangedEventsArgs e) {
|
||||
_security_criteria = model.result_criteria;
|
||||
void _on_criteria_changed() {
|
||||
_security_criteria = model.criteria;
|
||||
_raise_filter_changed();
|
||||
}
|
||||
|
||||
void _set_default_values() =>
|
||||
_security_criteria = model.result_criteria;
|
||||
_security_criteria = model.criteria;
|
||||
}
|
||||
}
|
||||
@@ -7,25 +7,40 @@ using mbts.ui.shell;
|
||||
using mbts.ui.utility;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
|
||||
using static mbts.spark.SparkTags;
|
||||
|
||||
namespace mbts.spark {
|
||||
internal class ContractPickerModel : ViewModelBase, IEditableObject, IDisposable {
|
||||
private const string dot = "•";
|
||||
class ContractPickerModel : DisposableViewModelBase, IEditableObject {
|
||||
readonly SecurityCriteria _world_view_filter;
|
||||
readonly DeferrableActionWrapper _on_criteria_changed;
|
||||
readonly DeferrableActionWrapper _on_clause_candidate_changed;
|
||||
readonly PropertyUpdateGate _selected_strikes_gate = new();
|
||||
readonly PropertyUpdateGate _selected_callputs_gate = new();
|
||||
readonly IRaiseCanExecuteChangedCommand _add_clause_command;
|
||||
readonly IRaiseCanExecuteChangedCommand _remove_clause_command;
|
||||
readonly IRaiseCanExecuteChangedCommand _ok_button_command;
|
||||
readonly IRaiseCanExecuteChangedCommand _toggle_all_strikes_selected_cmd;
|
||||
readonly IRaiseCanExecuteChangedCommand _toggle_all_callputs_selected_cmd;
|
||||
readonly IRaiseCanExecuteChangedCommand _toggle_all_securities_selected_cmd;
|
||||
|
||||
readonly IRaiseCanExecuteChangedCommand _add_criteria_command, _remove_criteria_command, _ok_button_command;
|
||||
|
||||
bool _allow_empty, _is_edit_mode;
|
||||
IReadOnlyDictionary<uint, SecurityMD> _all_security_mds = new Dictionary<uint, SecurityMD>();
|
||||
Venue? _selected_exchange;
|
||||
Security.ContractOneofCase? _selected_security_type;
|
||||
string _selected_symbol;
|
||||
ImmutableSortedSet<double> _selected_strikes = ImmutableSortedSet<double>.Empty;
|
||||
ImmutableSortedSet<uint> _selected_securities = ImmutableSortedSet<uint>.Empty;
|
||||
ImmutableSortedSet<PutOrCall> _selected_callputs = ImmutableSortedSet<PutOrCall>.Empty;
|
||||
bool _allow_empty;
|
||||
bool _is_edit_mode;
|
||||
uint? _pending_sec_key;
|
||||
(SecurityCriteria criteria, uint? sec, SecurityMD? md)? _snapshot;
|
||||
|
||||
@@ -33,55 +48,84 @@ namespace mbts.spark {
|
||||
: this(bus.subscribe(SecuritiesTag), edit_mode, existing_criteria, world_view_filter) { }
|
||||
|
||||
public ContractPickerModel(IObservable<IReadOnlyDictionary<uint, SecurityMD>> source, bool edit_mode, SecurityCriteria existing_criteria, SecurityCriteria world_view_filter = null) {
|
||||
if (existing_criteria?.clauses?.Length > 0) {
|
||||
security_criteria_clauses.AddRange(existing_criteria.clauses);
|
||||
}
|
||||
_on_criteria_changed = new(() => {
|
||||
_add_clause_command.RaiseCanExecuteChanged();
|
||||
_remove_clause_command.RaiseCanExecuteChanged();
|
||||
_ok_button_command.RaiseCanExecuteChanged();
|
||||
criteria_changed?.Invoke();
|
||||
});
|
||||
_on_clause_candidate_changed = new(() => {
|
||||
_add_clause_command.RaiseCanExecuteChanged();
|
||||
_remove_clause_command.RaiseCanExecuteChanged();
|
||||
_toggle_all_strikes_selected_cmd.RaiseCanExecuteChanged();
|
||||
_toggle_all_callputs_selected_cmd.RaiseCanExecuteChanged();
|
||||
RaisePropertyChanged(nameof(is_all_strikes_selected), nameof(is_all_callputs_selected));
|
||||
clause_candidate_changed?.Invoke();
|
||||
});
|
||||
clauses = (existing_criteria?.clauses)?.empty_if_null();
|
||||
is_edit_mode = edit_mode;
|
||||
_world_view_filter = world_view_filter;
|
||||
securities_view = CollectionViewSource.GetDefaultView(securities);
|
||||
(securities_view as ListCollectionView).CustomSort = SecurityComparer.instance_immutable.to_non_generic();
|
||||
_subs.Add(source.OnDispatcher().Subscribe(on_securities_changed));
|
||||
((ListCollectionView)securities_view).CustomSort = SecurityComparer.instance_immutable.to_non_generic();
|
||||
|
||||
_add_criteria_command = new DelegateCommand(
|
||||
execute: _ => {
|
||||
if (is_edit_mode && selected_securities.Count > 1) {
|
||||
_add_clause_command = new DelegateCommand(
|
||||
() => {
|
||||
if (is_edit_mode && _selected_securities.Count > 1) {
|
||||
// make separate entries in case multiple securities are selected
|
||||
foreach (var smd in selected_securities.KeyJoin(all_securities)) {
|
||||
try_add_clause(_get_clause(security_keys: new[] { smd.security.Id }, pretty_name: smd.security.ToString()));
|
||||
foreach (var smd in _selected_securities.KeyJoin(all_security_mds)) {
|
||||
try_add_clause(_get_clause_candidate(security_keys: new[] { smd.security.Id }, pretty_name: smd.security.ToString()));
|
||||
}
|
||||
} else {
|
||||
try_add_clause(_get_clause(pretty_name: criteria_input_name));
|
||||
try_add_clause(_get_clause_candidate());
|
||||
}
|
||||
_ok_button_command.RaiseCanExecuteChanged();
|
||||
_remove_criteria_command.RaiseCanExecuteChanged();
|
||||
},
|
||||
can_execute: _ => !string.IsNullOrEmpty(criteria_input_name)
|
||||
&& !selected_security_criteria_clauses.Any(c => c.pretty_name == criteria_input_name));
|
||||
() => {
|
||||
var clause = _get_clause_candidate();
|
||||
return clause.is_defined && !clauses.Contains(clause);
|
||||
});
|
||||
|
||||
_remove_criteria_command = new DelegateCommand(
|
||||
execute: _ => {
|
||||
security_criteria_clauses.removeRange(selected_security_criteria_clauses);
|
||||
_ok_button_command.RaiseCanExecuteChanged();
|
||||
_remove_criteria_command.RaiseCanExecuteChanged();
|
||||
},
|
||||
can_execute: _ => security_criteria_clauses.Count > 0);
|
||||
_remove_clause_command = new DelegateCommand(
|
||||
() => clause_items.RemoveWhere(ci => ci.is_selected),
|
||||
() => selected_clauses.Any());
|
||||
|
||||
_ok_button_command = new DelegateCommand(
|
||||
execute: _ => ok_action?.Invoke(),
|
||||
can_execute: _ => _allow_empty || (is_edit_mode ?
|
||||
security_criteria_clauses.Count > 0 :
|
||||
selected_securities.Count > 0));
|
||||
() => ok_action?.Invoke(),
|
||||
() => _allow_empty || (is_edit_mode ?
|
||||
clause_items.Count > 0 :
|
||||
_selected_securities.Count > 0));
|
||||
|
||||
cancel_button_command = new DelegateCommand(() => cancel_action?.Invoke());
|
||||
|
||||
add_callput_command = new DelegateCommand<PutOrCall>(callput => try_add_clause(get_callput_clause(callput)));
|
||||
add_strike_command = new DelegateCommand<double>(strike => try_add_clause(get_strike_clause(strike)));
|
||||
add_symbol_command = new DelegateCommand<string>(symbol => try_add_clause(get_symbol_clause(symbol)));
|
||||
add_security_type_command = new DelegateCommand<SecurityType>(sec_type => try_add_clause(get_security_type_clause(sec_type)));
|
||||
add_security_type_command = new DelegateCommand<Security.ContractOneofCase>(sec_type => try_add_clause(get_security_type_clause(sec_type)));
|
||||
add_exchange_command = new DelegateCommand<Venue>(exchange => try_add_clause(get_exchange_clause(exchange)));
|
||||
_toggle_all_strikes_selected_cmd = new DelegateCommand(
|
||||
() => request_select_all_strikes?.Invoke(!(is_all_strikes_selected ?? false)),
|
||||
() => strikes.Any());
|
||||
_toggle_all_callputs_selected_cmd = new DelegateCommand(
|
||||
() => request_select_all_callputs?.Invoke(!(is_all_callputs_selected ?? false)),
|
||||
() => strikes.Any());
|
||||
_toggle_all_securities_selected_cmd = new DelegateCommand(
|
||||
() => request_select_all_securities?.Invoke(!(is_all_securities_selected ?? false)),
|
||||
() => _all_security_mds.Any());
|
||||
|
||||
_dispose = Disposable.Create(
|
||||
ObservableAutoWrapper.connect_item_hooks(clause_items, cvm => {
|
||||
cvm.is_selected_changed += on_is_selected_changed;
|
||||
_on_criteria_changed.execute();
|
||||
return Disposable.Create(() => {
|
||||
cvm.is_selected_changed -= on_is_selected_changed;
|
||||
_on_criteria_changed.execute();
|
||||
});
|
||||
void on_is_selected_changed(bool value) =>
|
||||
_on_criteria_changed.execute();
|
||||
}),
|
||||
source.OnDispatcher().Subscribe(_on_securities_changed));
|
||||
|
||||
SecurityCriteriaClause get_callput_clause(params PutOrCall[] callputs) =>
|
||||
_get_clause(security_keys: Array.Empty<uint>(), callputs: callputs);
|
||||
_get_clause_candidate(security_keys: Array.Empty<uint>(), callputs: callputs);
|
||||
|
||||
SecurityCriteriaClause get_strike_clause(params double[] strikes) =>
|
||||
get_callput_clause().with(strikes: strikes);
|
||||
@@ -89,145 +133,186 @@ namespace mbts.spark {
|
||||
SecurityCriteriaClause get_symbol_clause(params string[] symbols) =>
|
||||
get_strike_clause().with(symbols: symbols);
|
||||
|
||||
SecurityCriteriaClause get_security_type_clause(params SecurityType[] security_types) =>
|
||||
get_symbol_clause().with(security_types: security_types);
|
||||
SecurityCriteriaClause get_security_type_clause(params Security.ContractOneofCase[] security_types) =>
|
||||
get_symbol_clause().with(security_types: Array.ConvertAll(security_types, t => t.security_type()));
|
||||
|
||||
SecurityCriteriaClause get_exchange_clause(params Venue[] exchanges) =>
|
||||
get_security_type_clause().with(exchanges: exchanges);
|
||||
|
||||
bool try_add_clause(SecurityCriteriaClause clause) {
|
||||
if (security_criteria_clauses.Any(x => x.pretty_name == clause.pretty_name)) {
|
||||
if (clauses.Contains(clause)) {
|
||||
return false;
|
||||
}
|
||||
security_criteria_clauses.Insert(0, clause);
|
||||
ok_button_command.TryRaiseCanExecuteChanged();
|
||||
remove_criteria_command.TryRaiseCanExecuteChanged();
|
||||
clause_items.Insert(0, new(clause));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private IList<IDisposable> _subs = new List<IDisposable>();
|
||||
|
||||
internal void exchange_selection_changed(IEnumerable<Venue> exchanges) {
|
||||
selected_exchanges = exchanges.ToList();
|
||||
_update_symbols();
|
||||
_update_securities();
|
||||
criteria_input_name = _get_clause().pretty_name;
|
||||
}
|
||||
|
||||
internal void security_type_selection_changed(IEnumerable<SecurityType> security_types) {
|
||||
selected_security_types = security_types.ToList();
|
||||
_update_symbols();
|
||||
_update_securities();
|
||||
_update_strikes();
|
||||
criteria_input_name = _get_clause().pretty_name;
|
||||
}
|
||||
|
||||
internal void symbol_selection_changed(IEnumerable<string> symbols) {
|
||||
selected_symbols = symbols.ToList();
|
||||
_update_securities();
|
||||
_update_strikes();
|
||||
criteria_input_name = _get_clause().pretty_name;
|
||||
}
|
||||
|
||||
internal void security_selection_changed(IEnumerable<SecurityImmutable> secs) {
|
||||
selected_securities = secs.Select(s => s.Id).ToList();
|
||||
ok_button_command.TryRaiseCanExecuteChanged();
|
||||
criteria_input_name = _get_clause().pretty_name;
|
||||
}
|
||||
|
||||
SecurityCriteriaClause _get_clause(
|
||||
Venue[] exchanges = null,
|
||||
SecurityType[] security_types = null,
|
||||
string[] symbols = null,
|
||||
uint[] security_keys = null,
|
||||
double[] strikes = null,
|
||||
PutOrCall[] callputs = null,
|
||||
string pretty_name = null) {
|
||||
var clause = new SecurityCriteriaClause(
|
||||
exchanges: exchanges ?? selected_exchanges.ToArray(),
|
||||
security_types: security_types ?? selected_security_types.ToArray(),
|
||||
symbols: symbols ?? selected_symbols.ToArray(),
|
||||
security_keys: security_keys ?? selected_securities.ToArray(),
|
||||
strikes: strikes ?? selected_strikes.ToArray(),
|
||||
callputs: callputs ?? selected_callputs.ToArray(),
|
||||
pretty_name: pretty_name);
|
||||
if (clause.pretty_name is null) {
|
||||
clause = clause.with(pretty_name: clause.fmt_pretty(
|
||||
sec_key => all_securities.TryGetValue(sec_key, out var smd) ? smd.security.ToString() : "?"));
|
||||
}
|
||||
return clause;
|
||||
}
|
||||
|
||||
private void on_securities_changed(IReadOnlyDictionary<uint, SecurityMD> changed_securities) {
|
||||
if (_world_view_filter != null) {
|
||||
all_securities = changed_securities
|
||||
.Where(x => _world_view_filter.includes(x.Value.security))
|
||||
.ToReadOnlyDictionary(x => x.Key, v => v.Value);
|
||||
} else {
|
||||
all_securities = changed_securities;
|
||||
}
|
||||
|
||||
_update_exchanges();
|
||||
_update_symbols();
|
||||
_update_strikes();
|
||||
_update_securities();
|
||||
if (_pending_sec_key.HasValue && changed_securities.TryGetValue(_pending_sec_key.Value, out var smd)) {
|
||||
select_security_request?.Invoke(smd.security);
|
||||
_pending_sec_key = null;
|
||||
}
|
||||
}
|
||||
internal void criteria_selection_changed(IEnumerable<SecurityCriteriaClause> selected_clauses) {
|
||||
selected_security_criteria_clauses = selected_clauses.ToList();
|
||||
//if (changed_clause != null) {
|
||||
// SecurityCriteriaClauseChangedEventsArgs args = new SecurityCriteriaClauseChangedEventsArgs();
|
||||
// args.securities = all_securities.Where(s => changed_clause.security_keys.no_null().Contains(s.Key)).Select(sec => sec.Value.security).ToArray();
|
||||
// args.clause = changed_clause;
|
||||
|
||||
// on_security_criteria_clause_changed(args);
|
||||
//}
|
||||
}
|
||||
|
||||
protected virtual void on_security_criteria_clause_changed(SecurityCriteriaClauseChangedEventsArgs e) {
|
||||
security_criteria_clause_changed?.Invoke(this, e);
|
||||
}
|
||||
public event Action ok_action;
|
||||
public event Action cancel_action;
|
||||
public event Action criteria_changed;
|
||||
public event Action clause_candidate_changed;
|
||||
public event Action<IEnumerable<double>> request_select_strikes;
|
||||
public event Action<bool> request_select_all_strikes;
|
||||
public event Action<IEnumerable<PutOrCall>> request_select_callputs;
|
||||
public event Action<bool> request_select_all_callputs;
|
||||
public event Action<SecurityImmutable> request_select_security;
|
||||
public event Action<bool> request_select_all_securities;
|
||||
public event Action<IEnumerable<SecurityImmutable>> request_select_securities;
|
||||
|
||||
public bool is_editing => _snapshot.HasValue;
|
||||
|
||||
public ObservableCollection<Venue> all_exchanges { get; } = new ObservableCollection<Venue>();
|
||||
|
||||
public List<Venue> selected_exchanges = new List<Venue>();
|
||||
|
||||
public ObservableCollection<SecurityType> security_types { get; } = new (){
|
||||
SecurityType.Stock,
|
||||
SecurityType.Future,
|
||||
SecurityType.Option,
|
||||
SecurityType.Spread,
|
||||
SecurityType.Synthetic
|
||||
};
|
||||
public List<SecurityType> selected_security_types = new List<SecurityType>();
|
||||
|
||||
public ObservableCollection<string> symbols { get; } = new ObservableCollection<string>();
|
||||
public List<string> selected_symbols = new List<string>();
|
||||
|
||||
public ObservableCollection<double> strikes { get; } = new ObservableCollection<double>();
|
||||
public List<double> selected_strikes = new List<double>();
|
||||
|
||||
public ObservableCollection<PutOrCall> callputs { get; } = new ObservableCollection<PutOrCall>();
|
||||
public List<PutOrCall> selected_callputs = new List<PutOrCall>();
|
||||
|
||||
IReadOnlyDictionary<uint, SecurityMD> _all_securities = new Dictionary<uint, SecurityMD>();
|
||||
|
||||
public IReadOnlyDictionary<uint, SecurityMD> all_securities {
|
||||
get => _all_securities;
|
||||
set => Set(ref _all_securities, value);
|
||||
public Venue? selected_exchange {
|
||||
get => _selected_exchange;
|
||||
set {
|
||||
if (Set(ref _selected_exchange, value)) {
|
||||
using var _ = _on_clause_candidate_changed.defer_execution(true);
|
||||
_update_symbols();
|
||||
_update_strikes();
|
||||
_update_securities();
|
||||
}
|
||||
}
|
||||
}
|
||||
public ObservableCollection<Security.ContractOneofCase> security_types { get; } = new(EnumHelper.get_values_except(Security.ContractOneofCase.None).OrderBy(e => e.ToString()));
|
||||
public Security.ContractOneofCase? selected_security_type {
|
||||
get => _selected_security_type;
|
||||
set {
|
||||
if (Set(ref _selected_security_type, value)) {
|
||||
using var _ = _on_clause_candidate_changed.defer_execution(true);
|
||||
_update_symbols();
|
||||
_update_strikes();
|
||||
_update_securities();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<uint> selected_securities = new List<uint>();
|
||||
public ObservableCollection<SecurityImmutable> securities { get; } = new ObservableCollection<SecurityImmutable>();
|
||||
public ObservableCollection<string> symbols { get; } = new ObservableCollection<string>();
|
||||
public string selected_symbol {
|
||||
get => _selected_symbol;
|
||||
set {
|
||||
if (Set(ref _selected_symbol, value)) {
|
||||
using var _ = _on_clause_candidate_changed.defer_execution(true);
|
||||
_update_strikes();
|
||||
_update_securities();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand add_criteria_command => _add_criteria_command;
|
||||
public ICommand remove_criteria_command => _remove_criteria_command;
|
||||
public ObservableCollection<double> strikes { get; } = new ObservableCollection<double>();
|
||||
public IEnumerable<double> selected_strikes {
|
||||
get => _selected_strikes;
|
||||
set => _selected_strikes_gate.try_update(() => {
|
||||
using var _ = _on_clause_candidate_changed.defer_execution(true);
|
||||
_selected_strikes = _selected_strikes.SetItems(value.empty_if_null());
|
||||
_update_securities();
|
||||
request_select_strikes?.Invoke(value.empty_if_null());
|
||||
});
|
||||
}
|
||||
public bool? is_all_strikes_selected => _is_all_selected(strikes.Count, _selected_strikes.Count);
|
||||
|
||||
public ObservableCollection<PutOrCall> callputs { get; } = new(EnumHelper.get_values<PutOrCall>().OrderBy(cp => cp.ToString()));
|
||||
public IEnumerable<PutOrCall> selected_callputs {
|
||||
get => _selected_callputs;
|
||||
set => _selected_callputs_gate.try_update(() => {
|
||||
using var _ = _on_clause_candidate_changed.defer_execution(true);
|
||||
_selected_callputs = _selected_callputs.SetItems(value.empty_if_null());
|
||||
_update_securities();
|
||||
request_select_callputs?.Invoke(value.empty_if_null());
|
||||
});
|
||||
}
|
||||
public bool? is_all_callputs_selected => _is_all_selected(callputs.Count, _selected_callputs.Count);
|
||||
|
||||
public IReadOnlyDictionary<uint, SecurityMD> all_security_mds {
|
||||
get => _all_security_mds;
|
||||
set => Set(ref _all_security_mds, value);
|
||||
}
|
||||
public IReadOnlyDictionary<uint, SecurityImmutable> all_securities => MappedDictionary.create(_all_security_mds, smd => smd.security);
|
||||
public ObservableCollection<SecurityImmutable> securities { get; } = new ObservableCollection<SecurityImmutable>();
|
||||
public ICollectionView securities_view { get; }
|
||||
|
||||
public IEnumerable<SecurityMD> selected_security_mds {
|
||||
get => _selected_securities.KeyJoin(all_security_mds);
|
||||
set => selected_security_keys = value.empty_if_null().Select(s => s.security.Id);
|
||||
}
|
||||
|
||||
public IEnumerable<SecurityImmutable> selected_securities {
|
||||
get => _selected_securities.KeyJoin(all_securities);
|
||||
set => selected_security_keys = value.empty_if_null().Select(s => s.Id);
|
||||
}
|
||||
|
||||
public IEnumerable<uint> selected_security_keys {
|
||||
get => selected_securities.Select(s => s.Id);
|
||||
set {
|
||||
using var _ = _on_clause_candidate_changed.defer_execution(true);
|
||||
_selected_securities = _selected_securities.SetItems(value.empty_if_null());
|
||||
request_select_securities?.Invoke(value.empty_if_null().KeyJoin(all_securities));
|
||||
}
|
||||
}
|
||||
public bool? is_all_securities_selected => _is_all_selected(_all_security_mds.Count, _selected_securities.Count);
|
||||
|
||||
public ObservableCollection<SelectableViewModelBase<SecurityCriteriaClause>> clause_items { get; } = new();
|
||||
public IEnumerable<SecurityCriteriaClause> clauses {
|
||||
get => clause_items.Select(ci => ci.value);
|
||||
set {
|
||||
using var _ = _on_criteria_changed.defer_execution();
|
||||
clause_items.sync_with_models(value.empty_if_null(),
|
||||
c => new SelectableViewModelBase<SecurityCriteriaClause>(c),
|
||||
(vm, c) => {
|
||||
vm.value = c;
|
||||
return vm;
|
||||
});
|
||||
}
|
||||
}
|
||||
public IEnumerable<SecurityCriteriaClause> selected_clauses => clause_items.Where(ci => ci.is_selected).Select(ci => ci.value);
|
||||
|
||||
public bool allow_empty {
|
||||
get => _allow_empty;
|
||||
set {
|
||||
if (Set(ref _allow_empty, value)) {
|
||||
_ok_button_command.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool is_edit_mode {
|
||||
get => _is_edit_mode;
|
||||
set => Set(ref _is_edit_mode, value);
|
||||
}
|
||||
|
||||
public SecurityMD? selected_security_md {
|
||||
get => _selected_securities.Count == 1 && all_security_mds.TryGetValue(_selected_securities[0], out var smd) ? smd : null;
|
||||
set => selected_security_key = (value?.security)?.Id;
|
||||
}
|
||||
|
||||
public SecurityImmutable? selected_security {
|
||||
get => selected_security_md?.security;
|
||||
set => selected_security_key = value?.Id;
|
||||
}
|
||||
|
||||
public uint? selected_security_key {
|
||||
get => (selected_security_md?.security)?.Id;
|
||||
set {
|
||||
if (value == selected_security_key || !value.HasValue) {
|
||||
return;
|
||||
}
|
||||
if (all_security_mds.TryGetValue(value.Value, out var smd)) {
|
||||
request_select_security?.Invoke(smd.security);
|
||||
} else {
|
||||
_pending_sec_key = value.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SecurityMD? result =>
|
||||
_selected_securities.KeyJoin(all_security_mds).TryGetSingle(out var smd) ? smd : null;
|
||||
|
||||
public SecurityCriteria criteria {
|
||||
get => new(clauses);
|
||||
set => clauses = (value?.clauses).empty_if_null();
|
||||
}
|
||||
|
||||
public ICommand add_clause_command => _add_clause_command;
|
||||
public ICommand remove_clause_command => _remove_clause_command;
|
||||
public ICommand ok_button_command => _ok_button_command;
|
||||
public ICommand cancel_button_command { get; }
|
||||
public ICommand add_symbol_command { get; }
|
||||
@@ -235,185 +320,175 @@ namespace mbts.spark {
|
||||
public ICommand add_exchange_command { get; }
|
||||
public ICommand add_strike_command { get; }
|
||||
public ICommand add_callput_command { get; }
|
||||
public ObservableCollection<SecurityCriteriaClause> security_criteria_clauses { get; } = new ObservableCollection<SecurityCriteriaClause>();
|
||||
public ICommand toggle_all_strikes_selected_cmd => _toggle_all_strikes_selected_cmd;
|
||||
public ICommand toggle_all_callputs_selected_cmd => _toggle_all_callputs_selected_cmd;
|
||||
public ICommand toggle_all_securities_selected_cmd => _toggle_all_securities_selected_cmd;
|
||||
|
||||
public List<SecurityCriteriaClause> selected_security_criteria_clauses = new List<SecurityCriteriaClause>();
|
||||
|
||||
private string _criteria_input_name;
|
||||
public string criteria_input_name {
|
||||
get { return _criteria_input_name; }
|
||||
set {
|
||||
_criteria_input_name = value;
|
||||
RaisePropertyChanged("criteria_input_name");
|
||||
add_criteria_command.TryRaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private SecurityCriteria _world_view_filter;
|
||||
|
||||
public event Action ok_action;
|
||||
public event Action cancel_action;
|
||||
|
||||
public bool allow_empty {
|
||||
get => _allow_empty;
|
||||
set {
|
||||
if (_allow_empty != value) {
|
||||
_allow_empty = value;
|
||||
_ok_button_command.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
public bool is_edit_mode { get => _is_edit_mode; set => Set(ref _is_edit_mode, value); }
|
||||
|
||||
public event EventHandler<SecurityCriteriaClauseChangedEventsArgs> security_criteria_clause_changed;
|
||||
public event Action<SecurityImmutable> select_security_request;
|
||||
|
||||
public SecurityMD? selected_security_md {
|
||||
get => selected_securities.Count == 1 && all_securities.TryGetValue(selected_securities[0], out var smd) ? smd : (SecurityMD?)null;
|
||||
set {
|
||||
if (value != selected_security_md) {
|
||||
if (value.HasValue) {
|
||||
if (all_securities.ContainsKey(value.Value.security.Id)) {
|
||||
select_security_request?.Invoke(value.Value.security);
|
||||
} else {
|
||||
_pending_sec_key = value.Value.security.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public uint? selected_security_key {
|
||||
get => selected_securities.Count == 1 && all_securities.TryGetValue(selected_securities[0], out var smd) ? smd.security.Id : (uint?)null;
|
||||
set {
|
||||
if (value != selected_security_key) {
|
||||
if (value.HasValue) {
|
||||
if (all_securities.TryGetValue(value.Value, out var smd)) {
|
||||
select_security_request?.Invoke(smd.security);
|
||||
} else {
|
||||
_pending_sec_key = value.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SecurityImmutable? selected_security {
|
||||
get => (selected_securities.Count == 1 && all_securities.TryGetValue(selected_securities[0], out var smd) ? smd : (SecurityMD?)null)?.security;
|
||||
set {
|
||||
if (value != selected_security) {
|
||||
if (value.HasValue) {
|
||||
if (all_securities.ContainsKey(value.Value.Id)) {
|
||||
select_security_request?.Invoke(value.Value);
|
||||
} else {
|
||||
_pending_sec_key = value.Value.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: this should return a nullable (if no specific security is selected, the result should be null)
|
||||
public SecurityMD result {
|
||||
get {
|
||||
if (selected_securities.Count == 0)
|
||||
throw new InvalidOperationException("No securities selected.");
|
||||
foreach (var k in selected_securities) {
|
||||
if (all_securities.TryGetValue(k, out var smd))
|
||||
return smd;
|
||||
}
|
||||
throw new InvalidOperationException("None of the selected security keys are present in the security map.");
|
||||
}
|
||||
}
|
||||
|
||||
public SecurityCriteria result_criteria {
|
||||
get {
|
||||
return new SecurityCriteria(security_criteria_clauses);
|
||||
}
|
||||
}
|
||||
public IEditableObject as_editable_object() =>
|
||||
this;
|
||||
|
||||
#region IEditableObject
|
||||
public void BeginEdit() => _snapshot = (result_criteria, _pending_sec_key ?? selected_security_key, selected_security_md);
|
||||
public void EndEdit() => _snapshot = null;
|
||||
public void CancelEdit() {
|
||||
if (_snapshot.HasValue) {
|
||||
var (criteria, sec, md) = _snapshot.Value;
|
||||
security_criteria_clauses.SetItems(criteria.clauses);
|
||||
selected_security_key = sec;
|
||||
/// A <see cref="_pending_sec"/> may have been used to create the snapshot when <see cref="BeginEdit"/> was called (this happens when securities are loaded lazily).
|
||||
/// If this is the case, pending sec was assigned to the <see cref="_snapshot"/> security;
|
||||
/// check if the security is now present in <see cref="all_securities"/>, if so, use that value instead of the null.
|
||||
selected_security_md = sec.HasValue && !md.HasValue && all_securities.TryGetValue(sec.Value, out var md_match) ? md_match : md;
|
||||
_snapshot = null;
|
||||
RaisePropertyChanged(nameof(selected_security));
|
||||
_add_criteria_command.RaiseCanExecuteChanged();
|
||||
_remove_criteria_command.RaiseCanExecuteChanged();
|
||||
void IEditableObject.BeginEdit() =>
|
||||
_snapshot = (criteria, _pending_sec_key ?? selected_security_key, selected_security_md);
|
||||
|
||||
void IEditableObject.EndEdit() =>
|
||||
_snapshot = null;
|
||||
|
||||
void IEditableObject.CancelEdit() {
|
||||
if (!_snapshot.HasValue) {
|
||||
return;
|
||||
}
|
||||
var (criteria, sec, md) = _snapshot.Value;
|
||||
clause_items.sync_with_models(criteria.clauses,
|
||||
c => new SelectableViewModelBase<SecurityCriteriaClause>(c),
|
||||
(cvm, c) => {
|
||||
if (!cvm.value.Equals(c)) {
|
||||
cvm.is_selected = false;
|
||||
cvm.value = c;
|
||||
}
|
||||
return cvm;
|
||||
});
|
||||
|
||||
selected_security_key = sec;
|
||||
/// A <see cref="_pending_sec"/> may have been used to create the
|
||||
/// snapshot when <see cref="BeginEdit"/> was called (this happens
|
||||
/// when securities are loaded lazily). If this is the case, pending
|
||||
/// sec was assigned to the <see cref="_snapshot"/> security; check
|
||||
/// if the security is now present in <see cref="all_security_mds"/>,
|
||||
/// if so, use that value instead of the null.
|
||||
_snapshot = null;
|
||||
RaisePropertyChanged(nameof(selected_security));
|
||||
_add_clause_command.RaiseCanExecuteChanged();
|
||||
_remove_clause_command.RaiseCanExecuteChanged();
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void _update_exchanges() {
|
||||
all_exchanges.sync_with(all_securities
|
||||
.Select(s => s.Value.security.Exchange)
|
||||
.Distinct()
|
||||
);
|
||||
static bool? _is_all_selected(int num_items, int num_selected) {
|
||||
if (num_items == 0 || num_selected == 0) {
|
||||
return false;
|
||||
}
|
||||
if (num_items == num_selected) {
|
||||
return true;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void _update_symbols() {
|
||||
symbols.sync_with(all_securities
|
||||
.Where(s => selected_exchanges
|
||||
.Any(exchange => exchange == s.Value.security.Exchange))
|
||||
.Where(s => selected_security_types
|
||||
.Any(s_type => s_type == s.Value.security.security_type()))
|
||||
.Select(s => s.Value.security.Symbol)
|
||||
.Distinct()
|
||||
.OrderBy(x => x)
|
||||
);
|
||||
SecurityCriteriaClause _get_clause_candidate(
|
||||
Venue[] exchanges = null,
|
||||
Security.ContractOneofCase[] security_types = null,
|
||||
string[] symbols = null,
|
||||
uint[] security_keys = null,
|
||||
double[] strikes = null,
|
||||
PutOrCall[] callputs = null,
|
||||
string pretty_name = null) {
|
||||
var clause = new SecurityCriteriaClause(
|
||||
exchanges: exchanges ?? (_selected_exchange.HasValue ? new[] { _selected_exchange.Value } : Array.Empty<Venue>()),
|
||||
security_types: Array.ConvertAll(security_types ??
|
||||
(selected_security_type.HasValue ?
|
||||
new[] { selected_security_type.Value } :
|
||||
Array.Empty<Security.ContractOneofCase>()),
|
||||
t => t.security_type()),
|
||||
symbols: symbols ?? new[] { selected_symbol },
|
||||
security_keys: security_keys ?? _selected_securities.ToArray(),
|
||||
strikes: strikes ?? _selected_strikes.ToArray(),
|
||||
callputs: callputs ?? (new[] { PutOrCall.Call, PutOrCall.Put }.All(_selected_callputs.Contains) ? null : _selected_callputs.ToArray()),
|
||||
pretty_name: pretty_name);
|
||||
if (clause.pretty_name is null) {
|
||||
clause = clause.with(pretty_name: clause.fmt_pretty(
|
||||
sec_key => all_security_mds.TryGetValue(sec_key, out var smd) ? smd.security.ToString() : "?"));
|
||||
}
|
||||
return clause;
|
||||
}
|
||||
|
||||
private void _update_securities() {
|
||||
securities.sync_with(all_securities
|
||||
.Select(all => all.Value.security)
|
||||
// exchange filtering
|
||||
.Where(sec => selected_exchanges
|
||||
.Any(exchange => exchange == sec.Exchange))
|
||||
// type filtering
|
||||
.Where(sec => selected_security_types
|
||||
.Any(sec_type => sec_type == sec.security_type()))
|
||||
// symbol filtering
|
||||
.Where(sec => selected_symbols
|
||||
.Any(sym => sym == sec.Symbol))
|
||||
);
|
||||
void _on_securities_changed(IReadOnlyDictionary<uint, SecurityMD> changed_securities) {
|
||||
bool init = !_all_security_mds.Any() && changed_securities.Any();
|
||||
if (_world_view_filter != null) {
|
||||
all_security_mds = changed_securities
|
||||
.Where(x => _world_view_filter.includes(x.Value.security))
|
||||
.ToReadOnlyDictionary(x => x.Key, v => v.Value);
|
||||
} else {
|
||||
all_security_mds = changed_securities;
|
||||
}
|
||||
|
||||
_update_exchanges();
|
||||
_update_symbols();
|
||||
_update_strikes();
|
||||
_update_securities();
|
||||
if (_pending_sec_key.HasValue && changed_securities.TryGetValue(_pending_sec_key.Value, out var smd)) {
|
||||
request_select_security?.Invoke(smd.security);
|
||||
_pending_sec_key = null;
|
||||
} else if (init) {
|
||||
if (!_selected_exchange.HasValue) {
|
||||
selected_exchange = all_exchanges.Cast<Venue?>().FirstOrDefault();
|
||||
}
|
||||
if (!_selected_security_type.HasValue) {
|
||||
selected_security_type = security_types
|
||||
.Cast<Security.ContractOneofCase?>()
|
||||
.FirstOrDefault(t => _all_security_mds.Values.Any(smd => smd.security.ContractCase == t));
|
||||
}
|
||||
if (_selected_symbol.is_null_or_empty()) {
|
||||
selected_symbol = symbols.FirstOrDefault();
|
||||
}
|
||||
if (_selected_strikes.is_null_or_empty()) {
|
||||
selected_strikes = strikes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _update_exchanges() {
|
||||
all_exchanges.sync_with(all_securities.Values
|
||||
.Select(sec => sec.Exchange)
|
||||
.Distinct()
|
||||
.OrderBy(exch => exch.ToString()));
|
||||
}
|
||||
|
||||
void _update_symbols() {
|
||||
if (!_selected_exchange.HasValue) {
|
||||
symbols.Clear();
|
||||
return;
|
||||
}
|
||||
symbols.sync_with(all_securities.Values
|
||||
.Where(sec => sec.Exchange == _selected_exchange && sec.ContractCase == _selected_security_type)
|
||||
.Select(sec => sec.Symbol)
|
||||
.Distinct()
|
||||
.Ordered());
|
||||
}
|
||||
|
||||
void _update_strikes() {
|
||||
if (!selected_security_types.Contains(SecurityType.Option)) {
|
||||
if (_selected_security_type != Security.ContractOneofCase.Option) {
|
||||
strikes.Clear();
|
||||
callputs.Clear();
|
||||
return;
|
||||
}
|
||||
strikes.sync_with(all_securities.Values
|
||||
.Select(smd => smd.security)
|
||||
.Where(sec => sec.ContractCase == Security.ContractOneofCase.Option
|
||||
&& selected_exchanges.Contains(sec.Exchange)
|
||||
&& selected_symbols.Contains(sec.Symbol))
|
||||
.Where(sec =>
|
||||
sec.Exchange == _selected_exchange &&
|
||||
sec.ContractCase == Security.ContractOneofCase.Option &&
|
||||
sec.Symbol == _selected_symbol)
|
||||
.Select(sec => sec.Option.Strike)
|
||||
.Distinct()
|
||||
.Ordered());
|
||||
if (strikes.Any()) {
|
||||
callputs.sync_with(new[] { PutOrCall.Call, PutOrCall.Put});
|
||||
callputs.sync_with(new[] { PutOrCall.Call, PutOrCall.Put });
|
||||
} else {
|
||||
callputs.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public ICollectionView securities_view { get; }
|
||||
|
||||
public void Dispose() {
|
||||
Disposable.dispose(_subs);
|
||||
void _update_securities() {
|
||||
if (!_selected_exchange.HasValue || !_selected_security_type.HasValue || _selected_symbol.is_null_or_empty()) {
|
||||
securities.Clear();
|
||||
return;
|
||||
}
|
||||
var new_secs = all_securities.Values
|
||||
.Where(sec => sec.Exchange == _selected_exchange &&
|
||||
sec.ContractCase == _selected_security_type &&
|
||||
sec.Symbol == _selected_symbol);
|
||||
if (_selected_security_type == Security.ContractOneofCase.Option) {
|
||||
new_secs = new_secs.Where(sec =>
|
||||
_selected_strikes.Contains(sec.Option.Strike) && _selected_callputs.Contains(sec.Option.CallPut));
|
||||
}
|
||||
securities.sync_with(new_secs);
|
||||
}
|
||||
}
|
||||
|
||||
internal class SecurityCriteriaClauseChangedEventsArgs : EventArgs {
|
||||
public SecurityCriteriaClause clause { get; set; }
|
||||
public SecurityImmutable[] securities { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ using mbts.ui.utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
@@ -255,12 +256,12 @@ namespace mbts.ui.controls {
|
||||
|
||||
protected override void OnClosed(EventArgs e) {
|
||||
if (ShowDialogSkirt)
|
||||
_controller.model.CancelEdit();
|
||||
_controller.model.as_editable_object().CancelEdit();
|
||||
}
|
||||
|
||||
protected override void OnOpened(EventArgs e) {
|
||||
if (ShowDialogSkirt)
|
||||
_controller.model.BeginEdit();
|
||||
_controller.model.as_editable_object().BeginEdit();
|
||||
}
|
||||
|
||||
void _close() => SetCurrentValue(IsOpenProperty, false);
|
||||
@@ -271,7 +272,7 @@ namespace mbts.ui.controls {
|
||||
public ContractPickerPopupController(ContractPickerPopup owner, ContractPickerModel model) {
|
||||
_selected_criteria = backing<SecurityCriteria>(nameof(selected_criteria));
|
||||
model.allow_empty = owner._allow_empty;
|
||||
model.security_criteria_clauses.CollectionChanged += on_clauses_collection_changed;
|
||||
model.clause_items.CollectionChanged += on_clauses_collection_changed;
|
||||
model.ok_action += on_ok;
|
||||
model.cancel_action += on_cancel;
|
||||
owner._allow_empty_changed += on_allow_empty_changed;
|
||||
@@ -284,11 +285,11 @@ namespace mbts.ui.controls {
|
||||
// ---------------OLD COMMENT/CODE--------------------------------------------
|
||||
// must check equality for both the model.result_criteria and selected_criteria
|
||||
// bc selected_criteria is only updated when the user clicks 'OK,' and can therefore be out of sync with the model.
|
||||
if (!model.result_criteria.safe_equals(criteria)) {
|
||||
using (model.security_criteria_clauses.SuspendHandler(on_clauses_collection_changed)) {
|
||||
model.security_criteria_clauses.Clear();
|
||||
if (criteria != null)
|
||||
model.security_criteria_clauses.AddRange(criteria.clauses.empty_if_null());
|
||||
if (!model.criteria.safe_equals(criteria)) {
|
||||
model.clause_items.Clear();
|
||||
if (criteria != null) {
|
||||
model.clause_items.AddRange(criteria.clauses.empty_if_null()
|
||||
.Select(c => new SelectableViewModelBase<SecurityCriteriaClause>(c)));
|
||||
}
|
||||
}
|
||||
_selected_criteria.set(criteria ?? new SecurityCriteria());
|
||||
@@ -297,22 +298,22 @@ namespace mbts.ui.controls {
|
||||
void on_allow_empty_changed(bool value) => model.allow_empty = value;
|
||||
void on_clauses_collection_changed(object sender, NotifyCollectionChangedEventArgs e) {
|
||||
owner._selected_criteria_changed -= on_selected_criteria_changed;
|
||||
_selected_criteria.set(model.result_criteria);
|
||||
_selected_criteria.set(model.criteria);
|
||||
WPFHelper.set_current_if_changed(owner, SelectedCriteriaProperty, selected_criteria);
|
||||
owner._selected_criteria_changed += on_selected_criteria_changed;
|
||||
}
|
||||
void on_ok() {
|
||||
model.EndEdit();
|
||||
model.as_editable_object().EndEdit();
|
||||
propagate_to_owner();
|
||||
owner.OKClick?.Invoke(owner, EventArgs.Empty);
|
||||
}
|
||||
void on_cancel() {
|
||||
model.CancelEdit();
|
||||
model.as_editable_object().CancelEdit();
|
||||
owner.CancelClick?.Invoke(owner, EventArgs.Empty);
|
||||
}
|
||||
void propagate_to_owner() {
|
||||
owner.set_current_if_changed(SelectedSecurityKeyProperty, owner.Controller.model.selected_security_key);
|
||||
owner.set_current_if_changed(SelectedCriteriaProperty, owner.Controller.model.result_criteria);
|
||||
owner.set_current_if_changed(SelectedCriteriaProperty, owner.Controller.model.criteria);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,137 +1,186 @@
|
||||
<UserControl x:Class="mbts.spark.ContractPickerView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:sp="clr-namespace:mbts.spark"
|
||||
xmlns:converters="clr-namespace:mbts.ui.converters"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:ui="clr-namespace:mbts.ui"
|
||||
x:ClassModifier="internal"
|
||||
mc:Ignorable="d" d:DesignWidth="560" Height="500" Width="560">
|
||||
<UserControl.Resources>
|
||||
<converters:BooleanToObjectConverter x:Key="bool_to_selectmode" ValueForTrue="Extended" ValueForFalse="Single" />
|
||||
<converters:BooleanToObjectConverter x:Key="bool_to_margin">
|
||||
<converters:BooleanToObjectConverter.ValueForTrue>
|
||||
<Thickness Left="2" Top="0" Right="0" Bottom="2" />
|
||||
</converters:BooleanToObjectConverter.ValueForTrue>
|
||||
<converters:BooleanToObjectConverter.ValueForFalse>
|
||||
<Thickness Left="2" Top="0" Right="12" Bottom="2" />
|
||||
</converters:BooleanToObjectConverter.ValueForFalse>
|
||||
</converters:BooleanToObjectConverter>
|
||||
<converters:EnumCharacterCasingConverter x:Key="casing_converter"/>
|
||||
<Style x:Key="listbox_add_criteria_double_click" TargetType="ListBoxItem">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding DataContext.is_edit_mode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}" Value="True">
|
||||
<Setter Property="ui:AttachedCommands.DoubleClick" Value="{Binding DataContext.add_criteria_command, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<UserControl
|
||||
x:Class="mbts.spark.ContractPickerView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:sp="clr-namespace:mbts.spark"
|
||||
xmlns:cv="clr-namespace:mbts.ui.converters"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:api="clr-namespace:bts.api;assembly=spark_api"
|
||||
x:ClassModifier="internal"
|
||||
Height="500"
|
||||
Width="580">
|
||||
<UserControl.Resources>
|
||||
<Style
|
||||
x:Key="IsAllSelectedCheckBox"
|
||||
TargetType="CheckBox">
|
||||
<Setter
|
||||
Property="IsThreeState"
|
||||
Value="True" />
|
||||
<Setter
|
||||
Property="Content"
|
||||
Value="(All)" />
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid
|
||||
Grid.Row="0"
|
||||
Grid.IsSharedSizeScope="True"
|
||||
Margin="12,0,0,0"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition
|
||||
SharedSizeGroup="share_col_width"
|
||||
Width="85" />
|
||||
<ColumnDefinition SharedSizeGroup="share_col_width" />
|
||||
<ColumnDefinition SharedSizeGroup="share_col_width" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid Grid.Row="0" Grid.IsSharedSizeScope="True" Margin="12,0,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition SharedSizeGroup="share_col_width" Width="85"/>
|
||||
<ColumnDefinition SharedSizeGroup="share_col_width" />
|
||||
<ColumnDefinition SharedSizeGroup="share_col_width" />
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Row ="0" Grid.Column="0" Content="Exchanges"></Label>
|
||||
<Label Grid.Row ="0" Grid.Column="1" Content="Security Types"></Label>
|
||||
<Label Grid.Row ="0" Grid.Column="2" Content="Symbols"></Label>
|
||||
<Label Grid.Row ="0" Grid.Column="3" Content="Strikes"></Label>
|
||||
<Label Grid.Row ="0" Grid.Column="4" Content="C/P"></Label>
|
||||
<Label Grid.Row ="0" Grid.Column="5" Content="Securities"></Label>
|
||||
<ListBox x:Name="_exchanges" Grid.Row ="1" Grid.Column="0" Margin="2,0,2,2"
|
||||
SelectionMode="{Binding is_edit_mode, Converter={StaticResource bool_to_selectmode}}"
|
||||
ItemsSource="{Binding all_exchanges}" SelectedIndex="0">
|
||||
<ListBox.ItemContainerStyle>
|
||||
<Style TargetType="ListBoxItem">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding DataContext.is_edit_mode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}" Value="True">
|
||||
<Setter Property="ui:AttachedCommands.DoubleClick"
|
||||
Value="{Binding DataContext.add_exchange_command, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}"/>
|
||||
<Setter Property="ui:AttachedCommands.DoubleClickParameter"
|
||||
Value="{Binding}" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ListBox.ItemContainerStyle>
|
||||
<Label
|
||||
Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Content="Exchanges" />
|
||||
<Label
|
||||
Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
Content="Security Types" />
|
||||
<Label
|
||||
Grid.Row="0"
|
||||
Grid.Column="2"
|
||||
Content="Symbols" />
|
||||
<Label
|
||||
Grid.Row="0"
|
||||
Grid.Column="3"
|
||||
Content="Strikes" />
|
||||
<Label
|
||||
Grid.Row="0"
|
||||
Grid.Column="4"
|
||||
Content="C/P" />
|
||||
<Label
|
||||
Grid.Row="0"
|
||||
Grid.Column="5"
|
||||
Content="Securities" />
|
||||
<ListBox
|
||||
x:Name="_exchanges"
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Margin="2,0,2,2"
|
||||
ItemsSource="{Binding all_exchanges}"
|
||||
ItemTemplate="{StaticResource EnumDescriptionTemplate}"
|
||||
SelectedItem="{Binding selected_exchange}">
|
||||
<ListBox.ItemContainerStyle>
|
||||
<Style TargetType="ListBoxItem">
|
||||
<Style.Triggers>
|
||||
<DataTrigger
|
||||
Binding="{Binding DataContext.is_edit_mode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}"
|
||||
Value="True">
|
||||
<Setter
|
||||
Property="u:AttachedCommands.DoubleClick"
|
||||
Value="{Binding DataContext.add_exchange_command, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}" />
|
||||
<Setter
|
||||
Property="u:AttachedCommands.DoubleClickParameter"
|
||||
Value="{Binding}" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ListBox.ItemContainerStyle>
|
||||
</ListBox>
|
||||
<ListBox
|
||||
x:Name="_security_types"
|
||||
Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
Margin="2,0,2,2"
|
||||
ItemsSource="{Binding security_types}"
|
||||
ItemTemplate="{StaticResource EnumDescriptionTemplate}"
|
||||
SelectedItem="{Binding selected_security_type}">
|
||||
<ListBox.ItemContainerStyle>
|
||||
<Style TargetType="ListBoxItem">
|
||||
<Style.Triggers>
|
||||
<DataTrigger
|
||||
Binding="{Binding DataContext.is_edit_mode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}"
|
||||
Value="True">
|
||||
<Setter
|
||||
Property="u:AttachedCommands.DoubleClick"
|
||||
Value="{Binding DataContext.add_security_type_command, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}" />
|
||||
<Setter
|
||||
Property="u:AttachedCommands.DoubleClickParameter"
|
||||
Value="{Binding}" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ListBox.ItemContainerStyle>
|
||||
</ListBox>
|
||||
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Converter={StaticResource casing_converter}, ConverterParameter=Upper}"></TextBlock>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<ListBox x:Name="_security_types" Grid.Row ="1" Grid.Column="1" Margin="2,0,2,2"
|
||||
ItemsSource="{Binding security_types}" SelectedIndex="0">
|
||||
<ListBox.ItemContainerStyle>
|
||||
<Style TargetType="ListBoxItem">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding DataContext.is_edit_mode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}" Value="True">
|
||||
<Setter Property="ui:AttachedCommands.DoubleClick"
|
||||
Value="{Binding DataContext.add_security_type_command, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}"/>
|
||||
<Setter Property="ui:AttachedCommands.DoubleClickParameter"
|
||||
Value="{Binding}" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ListBox.ItemContainerStyle>
|
||||
|
||||
</ListBox>
|
||||
<ListBox x:Name="_symbols" Grid.Row ="1" Grid.Column="2" Margin="2,0,2,2"
|
||||
ItemsSource="{Binding symbols}"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Visible"
|
||||
SelectedIndex="0">
|
||||
<ListBox.ItemContainerStyle>
|
||||
<Style TargetType="ListBoxItem">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding DataContext.is_edit_mode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}" Value="True">
|
||||
<Setter Property="ui:AttachedCommands.DoubleClick"
|
||||
Value="{Binding DataContext.add_symbol_command, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}"/>
|
||||
<Setter Property="ui:AttachedCommands.DoubleClickParameter"
|
||||
Value="{Binding}" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ListBox.ItemContainerStyle>
|
||||
|
||||
<!--
|
||||
<TextBlock Text="{Binding}">
|
||||
<TextBlock.InputBindings>
|
||||
<MouseBinding MouseAction="LeftDoubleClick"
|
||||
Command="{Binding DataContext.add_symbol_command, RelativeSource={RelativeSource AncestorType={x:Type ListBox}}}"
|
||||
CommandParameter="{Binding}" />
|
||||
</TextBlock.InputBindings>
|
||||
</TextBlock>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
-->
|
||||
</ListBox>
|
||||
<ListBox
|
||||
x:Name="_symbols"
|
||||
Grid.Row="1"
|
||||
Grid.Column="2"
|
||||
Margin="2,0,2,2"
|
||||
ItemsSource="{Binding symbols}"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Visible"
|
||||
SelectedItem="{Binding selected_symbol}">
|
||||
<ListBox.ItemContainerStyle>
|
||||
<Style TargetType="ListBoxItem">
|
||||
<Style.Triggers>
|
||||
<DataTrigger
|
||||
Binding="{Binding DataContext.is_edit_mode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}"
|
||||
Value="True">
|
||||
<Setter
|
||||
Property="u:AttachedCommands.DoubleClick"
|
||||
Value="{Binding DataContext.add_symbol_command, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}" />
|
||||
<Setter
|
||||
Property="u:AttachedCommands.DoubleClickParameter"
|
||||
Value="{Binding}" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ListBox.ItemContainerStyle>
|
||||
</ListBox>
|
||||
|
||||
<Grid
|
||||
Grid.Row="1"
|
||||
Grid.Column="3"
|
||||
Margin="2,0,2,2">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<CheckBox
|
||||
Margin="0,0,0,2"
|
||||
IsChecked="{Binding is_all_strikes_selected, Mode=OneWay}"
|
||||
Command="{Binding toggle_all_strikes_selected_cmd}"
|
||||
Style="{StaticResource IsAllSelectedCheckBox}" />
|
||||
<ListBox
|
||||
x:Name="_strikes"
|
||||
Grid.Row="1"
|
||||
Grid.Column="3"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Visible"
|
||||
Margin="2,0,2,2"
|
||||
MinWidth="57"
|
||||
ItemsSource="{Binding strikes}"
|
||||
SelectedIndex="0">
|
||||
SelectionMode="Extended">
|
||||
<ListBox.IsEnabled>
|
||||
<Binding Path="strikes">
|
||||
<Binding.Converter>
|
||||
<cv:IntGreaterThanConverter Value="0" />
|
||||
</Binding.Converter>
|
||||
</Binding>
|
||||
</ListBox.IsEnabled>
|
||||
<ListBox.ItemContainerStyle>
|
||||
<Style TargetType="ListBoxItem">
|
||||
<Style.Triggers>
|
||||
@@ -139,104 +188,207 @@
|
||||
Binding="{Binding DataContext.is_edit_mode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}"
|
||||
Value="True">
|
||||
<Setter
|
||||
Property="ui:AttachedCommands.DoubleClick"
|
||||
Property="u:AttachedCommands.DoubleClick"
|
||||
Value="{Binding DataContext.add_strike_command, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}" />
|
||||
<Setter
|
||||
Property="ui:AttachedCommands.DoubleClickParameter"
|
||||
Property="u:AttachedCommands.DoubleClickParameter"
|
||||
Value="{Binding}" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ListBox.ItemContainerStyle>
|
||||
</ListBox>
|
||||
|
||||
<ListBox x:Name="_callputs" Grid.Row ="1" Grid.Column="4" Margin="2,0,2,2"
|
||||
ItemsSource="{Binding callputs}" SelectedIndex="0">
|
||||
<ListBox.ItemContainerStyle>
|
||||
<Style TargetType="ListBoxItem">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding DataContext.is_edit_mode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}" Value="True">
|
||||
<Setter Property="ui:AttachedCommands.DoubleClick"
|
||||
Value="{Binding DataContext.add_callput_command, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}"/>
|
||||
<Setter Property="ui:AttachedCommands.DoubleClickParameter"
|
||||
Value="{Binding}" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ListBox.ItemContainerStyle>
|
||||
</ListBox>
|
||||
|
||||
<ListBox x:Name="_securities" Grid.Row ="1" Grid.Column="5" Margin="{Binding is_edit_mode, Converter={StaticResource bool_to_margin}}"
|
||||
SelectionMode="{Binding is_edit_mode, Converter={StaticResource bool_to_selectmode}}"
|
||||
ItemsSource="{Binding securities_view}"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Visible"
|
||||
HorizontalAlignment="Stretch"
|
||||
SelectedIndex="0">
|
||||
<ListBox.ItemContainerStyle>
|
||||
<Style TargetType="ListBoxItem">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding DataContext.is_edit_mode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}" Value="False">
|
||||
<Setter Property="ui:AttachedCommands.DoubleClick" Value="{Binding DataContext.ok_button_command, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding DataContext.is_edit_mode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}" Value="True">
|
||||
<Setter Property="ui:AttachedCommands.DoubleClick" Value="{Binding DataContext.add_criteria_command, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ListBox.ItemContainerStyle>
|
||||
</ListBox>
|
||||
<Button x:Name="_add_criteria_button" Grid.Row="1" Grid.Column="6" Command="{Binding add_criteria_command}" HorizontalAlignment="Left" VerticalAlignment="Top" Width="60" Margin="5,0,7,0" Visibility="{Binding is_edit_mode, Converter={StaticResource BoolToVisibility}}">
|
||||
<AccessText>_Add</AccessText>
|
||||
</Button>
|
||||
</Grid>
|
||||
<Grid Grid.Row="1" Margin="0,10,0,0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid Grid.Row="0" >
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="72"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Row="0" Grid.Column="0" Content="{Binding criteria_input_name}" Visibility="Collapsed" Margin="12,0,0,0" VerticalAlignment="Top"></Label>
|
||||
<Label Grid.Row="1" Content="Selected Securities" Visibility="{Binding is_edit_mode, Converter={StaticResource BoolToVisibility}}" Margin="12,0,0,0"></Label>
|
||||
<ListBox x:Name="_criteria" Grid.Row="2" Grid.Column="0" ScrollViewer.VerticalScrollBarVisibility="Visible"
|
||||
ItemsSource="{Binding security_criteria_clauses}"
|
||||
Visibility="{Binding is_edit_mode, Converter={StaticResource BoolToVisibility}}"
|
||||
SelectionMode="Extended"
|
||||
Margin="12,0,0,10" VerticalAlignment="Stretch" Height="90">
|
||||
<ListBox.ItemContainerStyle>
|
||||
<Style TargetType="ListBoxItem">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding DataContext.is_edit_mode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}" Value="True">
|
||||
<Setter Property="ui:AttachedCommands.DoubleClick" Value="{Binding DataContext.remove_criteria_command, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ListBox.ItemContainerStyle>
|
||||
</ListBox>
|
||||
<Button Grid.Row="2" Grid.Column="1" Command="{Binding remove_criteria_command}" HorizontalAlignment="Left" VerticalAlignment="Top" Width="60" Margin="5,0,0,10" Visibility="{Binding is_edit_mode, Converter={StaticResource BoolToVisibility}}">
|
||||
<AccessText>_Remove</AccessText>
|
||||
</Button>
|
||||
<c:DialogSkirtOKCancel
|
||||
Grid.Row="3" Grid.ColumnSpan="2"
|
||||
Visibility="{Binding ShowDialogSkirt, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource AncestorType=sp:ContractPickerView}}"
|
||||
OKCommand="{Binding ok_button_command}"
|
||||
CancelCommand="{Binding cancel_button_command}"
|
||||
CloseOnOK="{Binding CloseOnOK, RelativeSource={RelativeSource AncestorType=sp:ContractPickerView}}"
|
||||
CloseOnCancel="{Binding CloseOnCancel, RelativeSource={RelativeSource AncestorType=sp:ContractPickerView}}"
|
||||
/>
|
||||
</Grid>
|
||||
|
||||
<Grid
|
||||
Grid.Row="1"
|
||||
Grid.Column="4"
|
||||
Margin="2,0,2,2">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<CheckBox
|
||||
Margin="0,0,0,2"
|
||||
IsChecked="{Binding is_all_callputs_selected, Mode=OneWay}"
|
||||
Command="{Binding toggle_all_callputs_selected_cmd}"
|
||||
Style="{StaticResource IsAllSelectedCheckBox}" />
|
||||
<ListBox
|
||||
x:Name="_callputs"
|
||||
Grid.Row="1"
|
||||
MinWidth="41"
|
||||
ItemsSource="{Binding callputs}"
|
||||
SelectionMode="Extended">
|
||||
<ListBox.IsEnabled>
|
||||
<Binding Path="strikes">
|
||||
<Binding.Converter>
|
||||
<cv:IntGreaterThanConverter Value="0" />
|
||||
</Binding.Converter>
|
||||
</Binding>
|
||||
</ListBox.IsEnabled>
|
||||
<ListBox.ItemContainerStyle>
|
||||
<Style TargetType="ListBoxItem">
|
||||
<Style.Triggers>
|
||||
<DataTrigger
|
||||
Binding="{Binding DataContext.is_edit_mode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}"
|
||||
Value="True">
|
||||
<Setter
|
||||
Property="u:AttachedCommands.DoubleClick"
|
||||
Value="{Binding DataContext.add_callput_command, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}" />
|
||||
<Setter
|
||||
Property="u:AttachedCommands.DoubleClickParameter"
|
||||
Value="{Binding}" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ListBox.ItemContainerStyle>
|
||||
</ListBox>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
<Grid
|
||||
Grid.Row="1"
|
||||
Grid.Column="5"
|
||||
Margin="2,0,2,2">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<CheckBox
|
||||
Margin="0,0,0,2"
|
||||
IsChecked="{Binding is_all_securities_selected, Mode=OneWay}"
|
||||
Visibility="{Binding is_edit_mode, Converter={x:Static cv:BooleanToVisibilityConverter.Instance}}"
|
||||
Command="{Binding toggle_all_securities_selected_cmd}"
|
||||
Style="{StaticResource IsAllSelectedCheckBox}" />
|
||||
|
||||
<ListBox
|
||||
x:Name="_securities"
|
||||
Grid.Row="1"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Visible"
|
||||
HorizontalAlignment="Stretch"
|
||||
ItemsSource="{Binding securities_view}">
|
||||
<ListBox.SelectionMode>
|
||||
<Binding Path="is_edit_mode">
|
||||
<Binding.Converter>
|
||||
<cv:BooleanToObjectConverter
|
||||
ValueForFalse="{x:Static SelectionMode.Single}"
|
||||
ValueForTrue="{x:Static SelectionMode.Extended}" />
|
||||
</Binding.Converter>
|
||||
</Binding>
|
||||
</ListBox.SelectionMode>
|
||||
<ListBox.ItemContainerStyle>
|
||||
<Style TargetType="ListBoxItem">
|
||||
<Setter
|
||||
Property="HorizontalAlignment"
|
||||
Value="Stretch" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger
|
||||
Binding="{Binding DataContext.is_edit_mode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}"
|
||||
Value="False">
|
||||
<Setter
|
||||
Property="u:AttachedCommands.DoubleClick"
|
||||
Value="{Binding DataContext.ok_button_command, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}" />
|
||||
</DataTrigger>
|
||||
<DataTrigger
|
||||
Binding="{Binding DataContext.is_edit_mode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}"
|
||||
Value="True">
|
||||
<Setter
|
||||
Property="u:AttachedCommands.DoubleClick"
|
||||
Value="{Binding DataContext.add_clause_command, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ListBox.ItemContainerStyle>
|
||||
</ListBox>
|
||||
</Grid>
|
||||
<Button
|
||||
x:Name="_add_criteria_button"
|
||||
Grid.Row="1"
|
||||
Grid.Column="6"
|
||||
Command="{Binding add_clause_command}"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top"
|
||||
Width="60"
|
||||
Margin="5,0,7,0"
|
||||
Visibility="{Binding is_edit_mode, Converter={StaticResource BoolToVisibility}}">
|
||||
<AccessText>_Add</AccessText>
|
||||
</Button>
|
||||
</Grid>
|
||||
<Grid
|
||||
Grid.Row="1"
|
||||
Margin="0,10,0,0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid Grid.Row="0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="72" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label
|
||||
Grid.Row="0"
|
||||
Content="Selected Securities"
|
||||
Visibility="{Binding is_edit_mode, Converter={StaticResource BoolToVisibility}}"
|
||||
Margin="12,0,0,0" />
|
||||
<ListBox
|
||||
x:Name="_criteria"
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Visible"
|
||||
ItemsSource="{Binding clause_items}"
|
||||
Visibility="{Binding is_edit_mode, Converter={StaticResource BoolToVisibility}}"
|
||||
SelectionMode="Extended"
|
||||
SelectedValuePath="value"
|
||||
DisplayMemberPath="value"
|
||||
Margin="12,0,0,10"
|
||||
VerticalAlignment="Stretch"
|
||||
Height="90">
|
||||
<ListBox.ItemContainerStyle>
|
||||
<Style TargetType="ListBoxItem">
|
||||
<Setter
|
||||
Property="IsSelected"
|
||||
Value="{Binding is_selected}" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger
|
||||
Binding="{Binding DataContext.is_edit_mode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}"
|
||||
Value="True">
|
||||
<Setter
|
||||
Property="u:AttachedCommands.DoubleClick"
|
||||
Value="{Binding DataContext.remove_clause_command, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ListBox.ItemContainerStyle>
|
||||
</ListBox>
|
||||
<Button
|
||||
Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
Command="{Binding remove_clause_command}"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top"
|
||||
Width="60"
|
||||
Margin="5,0,0,10"
|
||||
Visibility="{Binding is_edit_mode, Converter={StaticResource BoolToVisibility}}">
|
||||
<AccessText>_Remove</AccessText>
|
||||
</Button>
|
||||
<c:DialogSkirtOKCancel
|
||||
Grid.Row="2"
|
||||
Grid.ColumnSpan="2"
|
||||
Visibility="{Binding ShowDialogSkirt, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource AncestorType=sp:ContractPickerView}}"
|
||||
OKCommand="{Binding ok_button_command}"
|
||||
CancelCommand="{Binding cancel_button_command}"
|
||||
CloseOnOK="{Binding CloseOnOK, RelativeSource={RelativeSource AncestorType=sp:ContractPickerView}}"
|
||||
CloseOnCancel="{Binding CloseOnCancel, RelativeSource={RelativeSource AncestorType=sp:ContractPickerView}}" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -1,8 +1,13 @@
|
||||
using bts.api;
|
||||
|
||||
using mbts.ui;
|
||||
using mbts.ui.extensions;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.utility;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
@@ -12,94 +17,96 @@ namespace mbts.spark {
|
||||
/// Interaction logic for ContractPickerView.xaml
|
||||
/// </summary>
|
||||
partial class ContractPickerView : UserControl {
|
||||
|
||||
// Do not remove empty constructor (otherwise it cannot be used in xaml files)
|
||||
// Do not remove empty constructor (otherwise this class can't be used in xaml files)
|
||||
public ContractPickerView() : this(null) { }
|
||||
public ContractPickerView(ContractPickerModel context) {
|
||||
public ContractPickerView(ContractPickerModel vm) {
|
||||
InitializeComponent();
|
||||
IDisposable vm_sub = null;
|
||||
DataContextChanged += on_data_context_changed;
|
||||
if (context != null) this.DataContext = context;
|
||||
SetCurrentValue(DataContextProperty, vm);
|
||||
|
||||
_exchanges.SelectionChanged += exchanges_changed;
|
||||
_security_types.SelectionChanged += security_types_changed;
|
||||
_symbols.SelectionChanged += symbols_changed;
|
||||
_securities.SelectionChanged += securities_changed;
|
||||
_criteria.SelectionChanged += criteria_changed;
|
||||
_add_criteria_button.Click += _add_criteria_button_Click;
|
||||
//context.security_criteria_clause_changed += security_criteria_clause_changed;
|
||||
void on_data_context_changed(object sender, DependencyPropertyChangedEventArgs e) {
|
||||
if (e.OldValue is ContractPickerModel old_cpm)
|
||||
old_cpm.select_security_request -= on_select_security_request;
|
||||
if (e.NewValue is ContractPickerModel new_cpm)
|
||||
new_cpm.select_security_request += on_select_security_request;
|
||||
Disposable.dispose(ref vm_sub);
|
||||
if (e.NewValue is not ContractPickerModel vm) {
|
||||
return;
|
||||
}
|
||||
|
||||
var strike_gate = new PropertyUpdateGate();
|
||||
var callput_gate = new PropertyUpdateGate();
|
||||
var security_gate = new PropertyUpdateGate();
|
||||
vm.request_select_strikes += on_request_select_strikes;
|
||||
vm.request_select_all_strikes += on_request_select_all_strikes;
|
||||
vm.request_select_callputs += on_request_select_callputs;
|
||||
vm.request_select_all_callputs += on_request_select_all_callputs;
|
||||
vm.request_select_security += on_request_select_security;
|
||||
vm.request_select_securities += on_request_select_securities;
|
||||
vm.request_select_all_securities += on_request_select_all_securities;
|
||||
|
||||
vm_sub = Disposable.Create(
|
||||
_strikes.SubscribeSelectionChanged((s, e) =>
|
||||
strike_gate.try_update(() => vm.selected_strikes = _strikes.SelectedItems.OfType<double>())),
|
||||
_callputs.SubscribeSelectionChanged((s, e) =>
|
||||
callput_gate.try_update(() => vm.selected_callputs = _callputs.SelectedItems.OfType<PutOrCall>())),
|
||||
_securities.SubscribeSelectionChanged((s, e) =>
|
||||
security_gate.try_update(() => vm.selected_security_keys = _securities.SelectedItems.OfType<SecurityImmutable>().Select(s => s.Id))),
|
||||
Disposable.Create(() => {
|
||||
vm.request_select_strikes -= on_request_select_strikes;
|
||||
vm.request_select_all_strikes -= on_request_select_all_strikes;
|
||||
vm.request_select_callputs -= on_request_select_callputs;
|
||||
vm.request_select_all_callputs -= on_request_select_all_callputs;
|
||||
vm.request_select_security -= on_request_select_security;
|
||||
vm.request_select_securities -= on_request_select_securities;
|
||||
vm.request_select_all_securities -= on_request_select_all_securities;
|
||||
}));
|
||||
|
||||
void on_request_select_strikes(IEnumerable<double> values) =>
|
||||
strike_gate.try_update(() => select_items(_strikes, values));
|
||||
|
||||
void on_request_select_callputs(IEnumerable<PutOrCall> values) =>
|
||||
callput_gate.try_update(() => select_items(_callputs, values));
|
||||
|
||||
void on_request_select_securities(IEnumerable<SecurityImmutable> values) =>
|
||||
security_gate.try_update(() => select_items(_securities, values));
|
||||
}
|
||||
void on_select_security_request(SecurityImmutable security) {
|
||||
|
||||
void on_request_select_security(SecurityImmutable security) {
|
||||
select_item(_exchanges, security.Exchange);
|
||||
select_item(_security_types, security.ContractCase);
|
||||
select_item(_symbols, security.Symbol);
|
||||
select_item(_securities, security);
|
||||
}
|
||||
void select_item(ListBox view, object value) =>
|
||||
view.SetCurrentValue(ListBox.SelectedItemProperty, value);
|
||||
}
|
||||
|
||||
private void _add_criteria_button_Click(object sender, RoutedEventArgs e) {
|
||||
if (sender is Button button && button.Command.CanExecute(button.CommandParameter)) { button.Command.Execute(button.CommandParameter); }
|
||||
|
||||
//_exchanges.SelectedItem = null;
|
||||
//_security_types.SelectedItem = null;
|
||||
//_symbols.SelectedItem = null;
|
||||
//_securities.SelectedItems.Clear();
|
||||
}
|
||||
|
||||
//private void security_criteria_clause_changed(object sender, SecurityCriteriaClauseChangedEventsArgs e) {
|
||||
// if (e != null) {
|
||||
// _exchanges.SelectedItems.Clear();
|
||||
// foreach (var exch in e.clause.exchanges) {
|
||||
// _exchanges.SelectedItems.Add(exch);
|
||||
// }
|
||||
// _exchanges.ScrollIntoView(e.clause.exchanges.FirstOrDefault());
|
||||
|
||||
// _security_types.SelectedItems.Clear();
|
||||
// foreach (var sec_type in e.clause.security_types) {
|
||||
// _security_types.SelectedItems.Add(sec_type);
|
||||
// }
|
||||
// _security_types.ScrollIntoView(e.clause.security_types.FirstOrDefault());
|
||||
|
||||
// _symbols.SelectedItems.Clear();
|
||||
// foreach (var sym in e.clause.symbols) {
|
||||
// _symbols.SelectedItems.Add(sym);
|
||||
// }
|
||||
// _symbols.ScrollIntoView(e.clause.symbols.FirstOrDefault());
|
||||
|
||||
// _securities.SelectedItems.Clear();
|
||||
// foreach (var sec in e.securities) {
|
||||
// _securities.SelectedItems.Add(sec);
|
||||
// }
|
||||
// _securities.ScrollIntoView(e.securities.FirstOrDefault());
|
||||
// }
|
||||
//}
|
||||
|
||||
private void exchanges_changed(object sender, SelectionChangedEventArgs e) {
|
||||
((ContractPickerModel)DataContext).exchange_selection_changed(_exchanges.SelectedItems.Cast<Venue>());
|
||||
}
|
||||
|
||||
private void security_types_changed(object sender, SelectionChangedEventArgs e) {
|
||||
((ContractPickerModel)DataContext).security_type_selection_changed(_security_types.SelectedItems.Cast<SecurityType>());
|
||||
}
|
||||
|
||||
private void securities_changed(object sender, SelectionChangedEventArgs e) {
|
||||
((ContractPickerModel)DataContext).security_selection_changed(_securities.SelectedItems.Cast<SecurityImmutable>());
|
||||
}
|
||||
private void symbols_changed(object sender, SelectionChangedEventArgs e) {
|
||||
if (_securities.SelectionMode != SelectionMode.Single) {
|
||||
_securities.SelectedItems.Clear();
|
||||
void on_request_select_all_strikes(bool value) {
|
||||
if (value) {
|
||||
_strikes.SelectAll();
|
||||
return;
|
||||
}
|
||||
select_items(_strikes, Enumerable.Empty<double>());
|
||||
}
|
||||
((ContractPickerModel)DataContext).symbol_selection_changed(_symbols.SelectedItems.Cast<string>());
|
||||
}
|
||||
|
||||
private void criteria_changed(object sender, SelectionChangedEventArgs e) {
|
||||
((ContractPickerModel)DataContext).criteria_selection_changed(_criteria.SelectedItems.Cast<SecurityCriteriaClause>());
|
||||
void on_request_select_all_callputs(bool value) {
|
||||
if (value) {
|
||||
_callputs.SelectAll();
|
||||
return;
|
||||
}
|
||||
select_items(_callputs, Enumerable.Empty<PutOrCall>());
|
||||
}
|
||||
|
||||
void on_request_select_all_securities(bool value) {
|
||||
if (value) {
|
||||
_securities.SelectAll();
|
||||
return;
|
||||
}
|
||||
select_items(_securities, Enumerable.Empty<SecurityImmutable>());
|
||||
}
|
||||
|
||||
static void select_item(ListBox view, object value) =>
|
||||
view.SetCurrentValue(ListBox.SelectedItemProperty, value);
|
||||
|
||||
static void select_items(ListBox view, IEnumerable values) {
|
||||
var mi = typeof(ListBox).GetMethod("SetSelectedItems", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
|
||||
mi.Invoke(view, new object[] { values });
|
||||
}
|
||||
}
|
||||
|
||||
#region CloseOnOK
|
||||
|
||||
Reference in new issue
Block a user