From 4180b9a8ec91c7570f75c41b79358b07b5d5502f Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 6 Nov 2019 11:45:42 -0600 Subject: [PATCH 01/36] removing price and quantity special case when legs = 3 --- src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs b/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs index d6e81bb99..b9c676d9e 100644 --- a/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs +++ b/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs @@ -357,19 +357,13 @@ namespace mbts.spark { if (leg_tuples.Count == 2) { _is_setting_price_mults = true; _price_mult_model.override_value(leg_tuples[1], -1); - } else if (leg_tuples.Count == 3) { - _is_setting_price_mults = true; - _price_mult_model.override_value(leg_tuples[1], -2); - } + } } void _deduce_quantities() { if (leg_tuples.Count == 2) { _is_setting_quantities = true; _quantity_model.override_value(leg_tuples[1], -1); - } else if (leg_tuples.Count == 3) { - _is_setting_quantities = true; - _quantity_model.override_value(leg_tuples[1], -2); } } From 09679ff49451a5711e85be398d4685d2d73b3152 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Fri, 8 Nov 2019 10:38:10 -0600 Subject: [PATCH 02/36] adding enforce_max_clip and max_clip to proto --- .../spark/Modules/Trading/Ladder/LadderSettings.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/client/spark/Modules/Trading/Ladder/LadderSettings.cs b/src/client/spark/Modules/Trading/Ladder/LadderSettings.cs index c025e90ed..1a19037cc 100644 --- a/src/client/spark/Modules/Trading/Ladder/LadderSettings.cs +++ b/src/client/spark/Modules/Trading/Ladder/LadderSettings.cs @@ -249,6 +249,7 @@ namespace mbts.spark { const double _default_order_entry_panel_width = 110.0; const double _default_zoom_factor = 1.0; const bool _default_show_warn_on_cross = true; + const bool _default_enforce_max_clip = false; public static readonly IEqualityComparer profile_equality_comparer = EqualityComparer.Create(profile_equals); // this class is 100% mutable (there are literally 0 readonly members), @@ -282,6 +283,7 @@ namespace mbts.spark { use_defaults = true; favorite_algos = new LadderFavoriteAlgosSettings(null, 2, null); show_warn_on_cross = _default_show_warn_on_cross; + enforce_max_clip = _default_enforce_max_clip; } public static LadderSettings Default { @@ -347,6 +349,7 @@ namespace mbts.spark { zoom_factor = _default_zoom_factor, net_change = NetChangeTerms.None, mini_ob = new LadderMiniOrderBookSettings(bts.shell.orderbook.OrderBookStartupData.default_mini_grid.general), + max_clip = 0, }; rv.row_height = LadderRender.measure_row_height(rv); return rv; @@ -499,6 +502,12 @@ namespace mbts.spark { [ProtoMember(57)] public double left_panel_scroll_position { get; set; } + [ProtoMember(58), DefaultValue(_default_enforce_max_clip)] + public bool enforce_max_clip { get; set; } + + [ProtoMember(59)] + public uint max_clip { get; set; } + public void sanitize() => sanitize(this); @@ -600,7 +609,9 @@ namespace mbts.spark { a.favorite_algos == b.favorite_algos && a.net_change == b.net_change && a.show_warn_on_cross == b.show_warn_on_cross && - a.mini_ob == b.mini_ob; + a.mini_ob == b.mini_ob && + a.enforce_max_clip == b.enforce_max_clip && + a.max_clip == b.max_clip; public bool Equals(LadderSettings other) => profile_equals(this, other) && From 12d532a17ff29667f58dc16087586e1e3862cd97 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Fri, 8 Nov 2019 10:39:38 -0600 Subject: [PATCH 03/36] adding enforce_max_clip and max_clip to settings vm --- .../Modules/Trading/Ladder/VM/LadderSettingsVM.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/client/spark/Modules/Trading/Ladder/VM/LadderSettingsVM.cs b/src/client/spark/Modules/Trading/Ladder/VM/LadderSettingsVM.cs index 68fffdeb8..69154edee 100644 --- a/src/client/spark/Modules/Trading/Ladder/VM/LadderSettingsVM.cs +++ b/src/client/spark/Modules/Trading/Ladder/VM/LadderSettingsVM.cs @@ -29,7 +29,7 @@ using TextUtils = mbts.ui.utility.text.TextUtils; namespace mbts.spark { class LadderSettingsVM : DisposableViewModelBase, IWindowSettingsVM, IValueFactory, IObservable, ITemplateSelectorKey { readonly Property _badge_style; - readonly Property _alternate_order_size; + readonly Property _alternate_order_size, _max_clip; readonly DelegateProperty _row_height; readonly UserProperty _default_account; readonly UserProperty _default_algo; @@ -42,7 +42,7 @@ namespace mbts.spark { TimeInForce _default_time_in_force; LadderSettings.NetChangeTerms _price_format; double _order_entry_panel_width, _zoom_factor; - bool _auto_clear, _show_warn_on_cross; + bool _auto_clear, _show_warn_on_cross, _enforce_max_clip; LadderSettings _current; LadderColumnSettingsVM _orders = new OrdersColumnSettingsVM(), @@ -91,6 +91,7 @@ namespace mbts.spark { _alternate_order_size = backing(nameof(alternate_order_size)); _default_account = user_backing(nameof(default_account)); _default_algo = user_backing(nameof(default_algo)); + _max_clip = backing(nameof(max_clip)); // be sure to initialize backings before this measure_row_height call _row_height = backing(nameof(row_height), () => LadderRender.measure_row_height(get_result())); _orders.font_size_changed += on_font_size_changed; @@ -182,6 +183,8 @@ namespace mbts.spark { public double zoom_factor { get => _zoom_factor; set => Set(ref _zoom_factor, value); } // safety checks public bool show_warn_on_cross { get => _show_warn_on_cross; set => Set(ref _show_warn_on_cross, value); } + public bool enforce_max_clip { get => _enforce_max_clip; set => Set(ref _enforce_max_clip, value); } + public uint max_clip { get => _max_clip.Value; set => _max_clip.Value = value; } // favorites public FavoriteAlgosVM favorite_algos_vm { get; } @@ -356,6 +359,8 @@ namespace mbts.spark { price_format = settings.net_change; // safety checks show_warn_on_cross = settings.show_warn_on_cross; + enforce_max_clip = settings.enforce_max_clip; + max_clip = settings.max_clip; } } @@ -430,6 +435,8 @@ namespace mbts.spark { clone.net_change = price_format; // safety checks clone.show_warn_on_cross = show_warn_on_cross; + clone.enforce_max_clip = enforce_max_clip; + clone.max_clip = max_clip; return clone; } From b6b33f14ef3b3987fece92a452529c6fc4680f5a Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Fri, 8 Nov 2019 10:40:43 -0600 Subject: [PATCH 04/36] enforce max clip at order entry --- src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs b/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs index 174a14b69..28a0ec70a 100644 --- a/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs +++ b/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs @@ -397,6 +397,8 @@ namespace mbts.spark { public uint volume_column_width { get => _volume_column_width.Value; set => _volume_column_width.set(value); } public uint alternate_order_size_from_settings => current_settings.alternate_order_size; public bool show_warn_on_cross_from_settings => current_settings.show_warn_on_cross; + public bool enforce_max_clip_from_settings => current_settings.enforce_max_clip; + public uint max_clip_from_settings => current_settings.max_clip; internal LadderModel model => _model; internal IObservable settings { get; } @@ -470,6 +472,10 @@ namespace mbts.spark { size_calculator.flash_error(); } else { uint size = size_from_alternate ? current_settings.alternate_order_size : (uint)Math.Abs(size_calculator.value ?? 0); + // enforce max clip + if (enforce_max_clip_from_settings && size > max_clip_from_settings) { + size = max_clip_from_settings; + } return send_order_async(args.side.Value, size, args.price); } } From 55134bf172c558dc08bb32929aa405c4be9096ec Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Fri, 8 Nov 2019 10:42:23 -0600 Subject: [PATCH 05/36] check max clip for crossing market dialog as well --- .../Modules/Trading/Ladder/View/LadderGridHost.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/client/spark/Modules/Trading/Ladder/View/LadderGridHost.cs b/src/client/spark/Modules/Trading/Ladder/View/LadderGridHost.cs index b78519f62..ef5975766 100644 --- a/src/client/spark/Modules/Trading/Ladder/View/LadderGridHost.cs +++ b/src/client/spark/Modules/Trading/Ladder/View/LadderGridHost.cs @@ -350,6 +350,17 @@ namespace mbts.spark { } } else if (_vm != null) { uint size = e.ChangedButton == MouseButton.Right ? _vm.alternate_order_size_from_settings : _vm.size_calculator.value ?? 0; + + // does the size violate the local max clip + if (_vm.enforce_max_clip_from_settings && size > _vm.max_clip_from_settings) { + // note this size is only used for the cross market message, not the actual order command + size = _vm.max_clip_from_settings; + // only update the calculator value when it's a standard left-click order + if (e.ChangedButton == MouseButton.Left) { + _vm.size_calculator.value = _vm.max_clip_from_settings; + } + } + // if warning enabled && (buy above opposite inside market || ask below opposite inside market) // when 1-sided market, _get_top_price will return NaN, and so the price comparison is false // meaning show no warning == correct From 24f366491b375bdf3af50d0d684fa43b65c2c0e2 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Fri, 8 Nov 2019 10:44:03 -0600 Subject: [PATCH 06/36] update view with appropriate controls for enforce_max_clip and max_clip --- .../Ladder/View/LadderSettingsView.xaml | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/client/spark/Modules/Trading/Ladder/View/LadderSettingsView.xaml b/src/client/spark/Modules/Trading/Ladder/View/LadderSettingsView.xaml index 92ab62e4d..badf93008 100644 --- a/src/client/spark/Modules/Trading/Ladder/View/LadderSettingsView.xaml +++ b/src/client/spark/Modules/Trading/Ladder/View/LadderSettingsView.xaml @@ -178,6 +178,14 @@ + + @@ -991,21 +999,45 @@ + + + - + + + + + + + + + + + From dfb673bd63735e45e987fd047ca66659d34fe071 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Fri, 8 Nov 2019 13:43:29 -0600 Subject: [PATCH 07/36] recenters all ladders via posting to appropriate tag to bus when spacebar is pressed over a ladder --- src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs b/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs index 174a14b69..199530408 100644 --- a/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs +++ b/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs @@ -447,6 +447,9 @@ namespace mbts.spark { public void key_down(KeyEventArgs e) { if (order_properties_vm == null) return; + if (KeyboardExtensions.IsDown(Key.Space)) { + _bus?.post(SparkTags.RequestRecenterLadder, null); + } // the ctrl modifier requirement helps avoid keyboard-input collisions w/ algo-templates popup if (!KeyboardExtensions.IsCtrlDown()) return; var new_algo = order_properties_vm.algo_definitions.FirstOrDefault(o => o.algo_root.key_match(e)); From a357d978ca39e029e206e947fc7017da83200f64 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Fri, 8 Nov 2019 13:45:03 -0600 Subject: [PATCH 08/36] misc string formatting fix; this is only used for debugging focus issues --- src/client/spark/core/Utility/MiscUtils.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/spark/core/Utility/MiscUtils.cs b/src/client/spark/core/Utility/MiscUtils.cs index 047eff9f3..4aa6074c8 100644 --- a/src/client/spark/core/Utility/MiscUtils.cs +++ b/src/client/spark/core/Utility/MiscUtils.cs @@ -102,14 +102,14 @@ namespace mbts.utils string identifier = ((felem.Name != null) && (felem.Name.Length > 0)) ? felem.Name : felem.GetType().ToString(); - return "$FrameworkElement [{identifier}]"; + return $"FrameworkElement [{identifier}]"; } else { // Maybe a FrameworkContentElement has focus if (elem is FrameworkContentElement fcelem) { string identifier = ((fcelem.Name != null) && (fcelem.Name.Length > 0)) ? fcelem.Name : fcelem.GetType().ToString(); - return "$FrameworkContentElement [{identifier}]"; + return $"FrameworkContentElement [{identifier}]"; } return $"Element of type [{elem.GetType().ToString()}] has focus"; } From 8b091b39ebb1730dcf5478f89a2fe643cc6d8f6d Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 13 Nov 2019 10:37:24 -0600 Subject: [PATCH 09/36] adding PriceDisplayFormat enum to proto --- .../spark/Modules/Trading/Ladder/LadderSettings.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/client/spark/Modules/Trading/Ladder/LadderSettings.cs b/src/client/spark/Modules/Trading/Ladder/LadderSettings.cs index c025e90ed..e407de632 100644 --- a/src/client/spark/Modules/Trading/Ladder/LadderSettings.cs +++ b/src/client/spark/Modules/Trading/Ladder/LadderSettings.cs @@ -347,6 +347,7 @@ namespace mbts.spark { zoom_factor = _default_zoom_factor, net_change = NetChangeTerms.None, mini_ob = new LadderMiniOrderBookSettings(bts.shell.orderbook.OrderBookStartupData.default_mini_grid.general), + price_display_format = PriceDisplayFormat.Default, }; rv.row_height = LadderRender.measure_row_height(rv); return rv; @@ -365,6 +366,13 @@ namespace mbts.spark { Ticks } + public enum PriceDisplayFormat { + [Description("Default")] + Default, + [Description("Integer")] + Integer + } + [ProtoMember(1)] public double row_height { get; set; } [ProtoMember(2)] @@ -499,6 +507,9 @@ namespace mbts.spark { [ProtoMember(57)] public double left_panel_scroll_position { get; set; } + [ProtoMember(60)] + public PriceDisplayFormat price_display_format { get; set; } + public void sanitize() => sanitize(this); @@ -600,7 +611,8 @@ namespace mbts.spark { a.favorite_algos == b.favorite_algos && a.net_change == b.net_change && a.show_warn_on_cross == b.show_warn_on_cross && - a.mini_ob == b.mini_ob; + a.mini_ob == b.mini_ob && + a.price_display_format == b.price_display_format; public bool Equals(LadderSettings other) => profile_equals(this, other) && From 99f2ab7c8acdca9a56ebff45a571d450af584ee3 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 13 Nov 2019 10:37:46 -0600 Subject: [PATCH 10/36] adding price_display_format to vm --- .../spark/Modules/Trading/Ladder/VM/LadderSettingsVM.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/client/spark/Modules/Trading/Ladder/VM/LadderSettingsVM.cs b/src/client/spark/Modules/Trading/Ladder/VM/LadderSettingsVM.cs index 68fffdeb8..a4e5c3f1c 100644 --- a/src/client/spark/Modules/Trading/Ladder/VM/LadderSettingsVM.cs +++ b/src/client/spark/Modules/Trading/Ladder/VM/LadderSettingsVM.cs @@ -41,6 +41,7 @@ namespace mbts.spark { AlgoID? _desired_algo; TimeInForce _default_time_in_force; LadderSettings.NetChangeTerms _price_format; + LadderSettings.PriceDisplayFormat _price_display_format; double _order_entry_panel_width, _zoom_factor; bool _auto_clear, _show_warn_on_cross; LadderSettings _current; @@ -166,7 +167,9 @@ namespace mbts.spark { public SimpleGridSettingsVM mini_ob { get; } = new SimpleGridSettingsVM(OrderBookGridSettingsManager.hard_column_flags); // price format public LadderSettings.NetChangeTerms price_format { get => _price_format; set => Set(ref _price_format, value); } + public LadderSettings.PriceDisplayFormat price_display_format { get => _price_display_format; set => Set(ref _price_display_format, value); } public IEnumerable price_format_options => EnumHelper.get_values(); + public IEnumerable price_display_format_options => EnumHelper.get_values(); // time in force public TimeInForce default_time_in_force { get => _default_time_in_force; set => Set(ref _default_time_in_force, value); } public IEnumerable time_in_force_options => EnumHelper.get_values_except(TimeInForce.Undefined); @@ -354,6 +357,7 @@ namespace mbts.spark { _cancel_sells_visibility.show = settings.cancel_sells_visible; _cancel_all_visibility.show = settings.cancel_all_visible; price_format = settings.net_change; + price_display_format = settings.price_display_format; // safety checks show_warn_on_cross = settings.show_warn_on_cross; } @@ -428,6 +432,7 @@ namespace mbts.spark { clone.cancel_all_visible = _cancel_all_visibility.show; clone.zoom_slider_visible = _zoom_slider_visbility.show; clone.net_change = price_format; + clone.price_display_format = price_display_format; // safety checks clone.show_warn_on_cross = show_warn_on_cross; return clone; From 367d9be72428b95399f64295a6de6b27fbe6083c Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 13 Nov 2019 10:38:04 -0600 Subject: [PATCH 11/36] adding price_display_format to settings view --- .../Trading/Ladder/View/LadderSettingsView.xaml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/client/spark/Modules/Trading/Ladder/View/LadderSettingsView.xaml b/src/client/spark/Modules/Trading/Ladder/View/LadderSettingsView.xaml index 92ab62e4d..233067904 100644 --- a/src/client/spark/Modules/Trading/Ladder/View/LadderSettingsView.xaml +++ b/src/client/spark/Modules/Trading/Ladder/View/LadderSettingsView.xaml @@ -630,7 +630,11 @@ - + + + + + @@ -710,6 +714,7 @@ + + + From 58d39c48339473cb23cae8c30a25fd482bee7ced Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 13 Nov 2019 10:38:26 -0600 Subject: [PATCH 12/36] rendering ladder prices approparitely based on price_display_format --- .../Trading/Ladder/View/LadderGridHost.cs | 5 +++-- .../Trading/Ladder/View/LadderRender.cs | 21 ++++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/client/spark/Modules/Trading/Ladder/View/LadderGridHost.cs b/src/client/spark/Modules/Trading/Ladder/View/LadderGridHost.cs index b78519f62..bb808ea2d 100644 --- a/src/client/spark/Modules/Trading/Ladder/View/LadderGridHost.cs +++ b/src/client/spark/Modules/Trading/Ladder/View/LadderGridHost.cs @@ -588,7 +588,8 @@ namespace mbts.spark { _settings.row_height, _price_list, column.settings, - security.ContractSpec); + security.ContractSpec, + _settings.price_display_format); } break; case ColumnType.Ask: render_market_col(_asks); break; @@ -911,7 +912,7 @@ namespace mbts.spark { var prev_price_list = _price_list; _price_list = (!(_settings.net_change == LadderSettings.NetChangeTerms.None)) ? LadderRender.render_prices(_price_vis_tup.visual, _price_vis_tup.glyph_context, _mkt_break_lines.origin, _vm.md.settlement_price, _settings.net_change == LadderSettings.NetChangeTerms.Ticks, _row_count, _settings.row_height, _settings.price_column, security.ContractSpec) : - LadderRender.render_prices(_price_vis_tup.visual, _price_vis_tup.glyph_context, _mkt_break_lines.origin, _row_count, _settings.row_height, _settings.price_column, security.ContractSpec); + LadderRender.render_prices(_price_vis_tup.visual, _price_vis_tup.glyph_context, _mkt_break_lines.origin, _row_count, _settings.row_height, _settings.price_column, security.ContractSpec, _settings.price_display_format); _ordershost.update_settings(_price_list, _price_comparer, _settings.row_height, _settings.orders_column); if (prev_price_list != null) { // maintain previous visible price range if possible diff --git a/src/client/spark/Modules/Trading/Ladder/View/LadderRender.cs b/src/client/spark/Modules/Trading/Ladder/View/LadderRender.cs index d12c79a6c..c6d5e6a2e 100644 --- a/src/client/spark/Modules/Trading/Ladder/View/LadderRender.cs +++ b/src/client/spark/Modules/Trading/Ladder/View/LadderRender.cs @@ -40,6 +40,8 @@ namespace mbts.spark { // Note: the orders-column has a separate "row_padding" value: Badge.DefaultMargin // (see how it is incorporated in measure_row_height() below) public static readonly Thickness row_padding = new Thickness(6); + const string tick_separator_period = "."; + const string tick_separator_dash = "-"; // IMPORTANT: this method ONLY WORKS if Badges use the BadgeRender.margin/border_thickness/padding values. // TODO: elminate the dependency on BadgeRender.margin/border_thickness/padding by integrating them into settings. @@ -52,8 +54,11 @@ namespace mbts.spark { public static int index_of(double[] prices, double price, IComparer comparer) => Array.BinarySearch(prices, price, comparer); - public static GlyphRun format_text(string text, int row, double row_height, LadderColumnSettings settings, GlyphContext glyph_context) => - glyph_context.get_glyph_run(text, settings.font_size, settings.width, row_height, HorizontalAlignment.Center, 0, VerticalAlignment.Center, row * row_height, true); + public static GlyphRun format_text(string text, int row, double row_height, LadderColumnSettings settings, GlyphContext glyph_context, LadderSettings.PriceDisplayFormat price_display_format = LadderSettings.PriceDisplayFormat.Default) => + glyph_context.get_glyph_run( + // long term there is probably a better way to get rid of the separator, such as in the TickExtensions._format_tick + price_display_format == LadderSettings.PriceDisplayFormat.Integer ? text.Replace(tick_separator_period, string.Empty).Replace(tick_separator_dash, string.Empty) : text, + settings.font_size, settings.width, row_height, HorizontalAlignment.Center, 0, VerticalAlignment.Center, row * row_height, true); public static double[] gen_prices(double mid, int row_count, ContractSpecificationImmutable spec) { // require odd number @@ -79,10 +84,10 @@ namespace mbts.spark { result[i] = format_text(spec.format(prices[i], reference_price, format_in_tick_terms), i, row_height, settings, glyph_context)); return result; } - public static GlyphRun[] format_prices(double[] prices, double row_height, LadderColumnSettings settings, GlyphContext glyph_context, ContractSpecificationImmutable spec) { + public static GlyphRun[] format_prices(double[] prices, double row_height, LadderColumnSettings settings, GlyphContext glyph_context, ContractSpecificationImmutable spec, LadderSettings.PriceDisplayFormat price_display_format) { var result = new GlyphRun[prices.Length]; Parallel.For(0, prices.Length, i => - result[i] = format_text(spec.format(prices[i]), i, row_height, settings, glyph_context)); + result[i] = format_text(spec.format(prices[i]), i, row_height, settings, glyph_context, price_display_format)); return result; } @@ -104,9 +109,9 @@ namespace mbts.spark { } public static double[] render_prices(DrawingVisual price, GlyphContext glyph_context, double mid, int row_count, double row_height, - LadderColumnSettings settings, ContractSpecificationImmutable spec) { + LadderColumnSettings settings, ContractSpecificationImmutable spec, LadderSettings.PriceDisplayFormat price_display_format) { var dprices = gen_prices(mid, row_count, spec); - render_prices(price, glyph_context, row_count, row_height, dprices, settings, spec); + render_prices(price, glyph_context, row_count, row_height, dprices, settings, spec, price_display_format); return dprices; } @@ -122,10 +127,10 @@ namespace mbts.spark { } } - public static void render_prices(DrawingVisual price, GlyphContext glyph_context, int row_count, double row_height, double[] dprices, LadderColumnSettings settings, ContractSpecificationImmutable spec) { + public static void render_prices(DrawingVisual price, GlyphContext glyph_context, int row_count, double row_height, double[] dprices, LadderColumnSettings settings, ContractSpecificationImmutable spec, LadderSettings.PriceDisplayFormat price_display_format) { var foreground = settings.foreground.rgb_brush(); //var background = new SolidColorBrush(settings.background.rgb_color()); - var fprices = format_prices(dprices, row_height, settings, glyph_context, spec); + var fprices = format_prices(dprices, row_height, settings, glyph_context, spec, price_display_format); using (var dc = price.RenderOpen()) using (_draw_with_clip(dc, settings, row_height, row_count)) { //dc.DrawRectangle(background, null, new Rect(0, 0, settings.width, row_count * row_height)); From 51fb0684695b083e1b1e42095eeff09cde727f5c Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Thu, 14 Nov 2019 15:51:40 -0600 Subject: [PATCH 13/36] adding manual test --- testing/manual/settings/Ladder_MaxClip.txt | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 testing/manual/settings/Ladder_MaxClip.txt diff --git a/testing/manual/settings/Ladder_MaxClip.txt b/testing/manual/settings/Ladder_MaxClip.txt new file mode 100644 index 000000000..f4757c100 --- /dev/null +++ b/testing/manual/settings/Ladder_MaxClip.txt @@ -0,0 +1,41 @@ +1. Verify you can place orders +Launch a Ladder +Place a 10 lot order away from the market and make sure the order is not rejected +Cancel the order + +2. Verify the Max Order Quantity limit works +Click on the Settings button +Click on the Safety Checks tab +Click on the checkbox next to Max Order Quantity and specify 5 + You should additionally observe that the text has gone from a disabled appearance to active + The ticker box is also now active +Hit apply +Back in the ladder, attempt to place another 10 lot order away from the market. You should observe the following: + You are now working a 5 lot order + The qty in the qty box additionally reads 5 +Cancel the 5 lot order + +3. Verify the Max Order Quantity when disabled allows you to place a 10 lot order +This is essentially the same as step 1, except now we're explicitly unchecking the checkbox, ergo... +Uncheck the Max Order Quantity chechbox and observe that: + The Max order quantity text is disabled + The ticker box is disabled +Click Apply +In the ladder, click the 5 button so that your qty box reads 10, which is a quantity greater than the disabled 5 + A 10 lot order should now be working +Cancel the 10 lot order. + +4. Right click / Alternate order qty respects the limit +Re-enable the Max Order Quantity (5 is still fine) +On the Order Quantities tab, specify 7 as your 'Single Click' Quantity +In the ladder, Right click to work an order attempting to use your single click quantity + You should be working a a 5 lot order now i.e. your max order quantity + Observe that the qty box did NOT update with your alternate order quantity + +5. Cross market alert communicates respects the limit +Back on the Safety Checks tab, make sure Warn on Market Cross is checked +Attempt to place a 10 lot bid order (higher than your max of 5) on the sell side of the market + You should observe the message respects your max order quantity and warns you about buying 5 + Feel free to click whichever button you desire on the warning dialog + +FIN From e2b80942df9c00ffc03b6fe97b7d71f67d709f19 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Thu, 14 Nov 2019 15:58:59 -0600 Subject: [PATCH 14/36] adding manual test --- .../manual/settings/Ladder_PriceDisplayFormat.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 testing/manual/settings/Ladder_PriceDisplayFormat.txt diff --git a/testing/manual/settings/Ladder_PriceDisplayFormat.txt b/testing/manual/settings/Ladder_PriceDisplayFormat.txt new file mode 100644 index 000000000..d7f4174e1 --- /dev/null +++ b/testing/manual/settings/Ladder_PriceDisplayFormat.txt @@ -0,0 +1,12 @@ +Launch an ES Ladder (i.e. an instrument whose separator is the .) + Observe the ladder prices are in fact separated by a decimal point +Launch a ZT ladder (i.e. an instrument whose separator is the -) + Observe the ladder prices are in fact separated by a dash +Perform the following in each: + Click Settings + Go to Market Price and Size Display tab + Click on Integer under Price Display Format + Click Apply + Observe that the separator disappears when you do this + Feel free to go back and forth several times + From 96f71290a4827697fb099761846bb18d2e01a8af Mon Sep 17 00:00:00 2001 From: John Colvin Date: Thu, 14 Nov 2019 16:05:51 -0600 Subject: [PATCH 15/36] SP-265 pnl crash due to CastException --- src/client/spark/Modules/Trading/PNL/View/PNLView.xaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/spark/Modules/Trading/PNL/View/PNLView.xaml b/src/client/spark/Modules/Trading/PNL/View/PNLView.xaml index f30696473..3109114d0 100644 --- a/src/client/spark/Modules/Trading/PNL/View/PNLView.xaml +++ b/src/client/spark/Modules/Trading/PNL/View/PNLView.xaml @@ -698,8 +698,8 @@ c:DataGridFilterProperties.FilterActive="{Binding DataContext.security_filter.active, Source={u:DirectReference _grid}}" c:DataGridFilterProperties.FilterOpen="{Binding DataContext.security_filter.open, Source={u:DirectReference _grid}}" key="Security" - sort_member_path="security_cell.cell_data" - data_member_path="security" + data_member_path="security_cell.cell_data" + sort_member_path="security" HeaderTemplate="{StaticResource AnchorableColumnHeaderTemplate}" /> From 4de77ce339831eb4fde9bf5752ba4008d1ecff79 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Thu, 14 Nov 2019 16:08:49 -0600 Subject: [PATCH 16/36] pnl sometimes duplicates grouping columns when they are changed in settings dialog --- .../Trading/PNL/Settings/VM/PNLSettingsVM.cs | 439 +++++++++--------- 1 file changed, 221 insertions(+), 218 deletions(-) diff --git a/src/client/spark/Modules/Trading/PNL/Settings/VM/PNLSettingsVM.cs b/src/client/spark/Modules/Trading/PNL/Settings/VM/PNLSettingsVM.cs index 47a36196f..518e259a6 100644 --- a/src/client/spark/Modules/Trading/PNL/Settings/VM/PNLSettingsVM.cs +++ b/src/client/spark/Modules/Trading/PNL/Settings/VM/PNLSettingsVM.cs @@ -1,220 +1,223 @@ -using bts.collections; -using bts.utils; -using mbts; -using mbts.collections; -using mbts.expression; -using mbts.spark; -using mbts.ui; -using mbts.ui.settings; -using mbts.ui.shell; -using mbts.ui.spark; -using mbts.ui.utility; -using mbts.utils; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Collections.Specialized; -using System.Dynamic; -using System.Linq; -using ColumnKeys = bts.shell.pnl.PNLView.Columns; - -namespace bts.shell.pnl { - class PNLSettingsVM : DisposableViewModelBase, IWindowSettingsVM, IValueFactory, IObservable, ITemplateSelectorKey { - readonly IReadOnlyDictionary _anchor_cache; - readonly DeferrableActionWrapper _sync_anchors; - - PNLCalculationType _calculation_type; - PNLHeaderRowDisplay _header_row_display; - PNLSettings _last_loaded; - - public PNLSettingsVM(PNLSettings settings) { - // init anchor cache, deferrable resync - _anchor_cache = PNLSettings.anchorable_columns.ToDictionary(k => k, k => new AnchorItemVM(this, k)); - _sync_anchors = new DeferrableActionWrapper(() => { - for (int i = 0; i < anchor_items.Count; i++) { - anchor_items[i].anchor_index = i + 1; - anchor_items[i].refresh(); - } - }); - core_settings_vm = new SimpleGridSettingsVM(column_factory: col_settings => { - var col_vm = new PNLColumnVM(core_settings_vm, EnumHelper.parse(col_settings.id)); - col_vm.load_from(col_settings); - return col_vm; - }); - core_settings_vm.selection_highlight.bind_opacity_to_alpha = true; - _dispose = Disposable.Create( - anchor_items.Subscribe((s, e) => _sync_anchors.execute())); - load(settings); - } - - public IEnumerable anchor_item_headers => _anchor_cache.Values; - public ObservableCollection anchor_items { get; } = new ObservableCollection(); - public SimpleGridSettingsVM core_settings_vm { get; } - public PNLGroupRowAppearanceVM group_row_defaults { get; } = new PNLGroupRowAppearanceVM(); - public PNLCellAppearanceVM header_row_defaults { get; } = new PNLCellAppearanceVM(); - public PNLCalculationType calculation_type { get => _calculation_type; set => Set(ref _calculation_type, value); } - public IEnumerable calculation_types => EnumHelper.get_values_except(PNLCalculationType.None, PNLCalculationType.Same, PNLCalculationType.Opposite); - public PNLHeaderRowDisplay header_row_display { get => _header_row_display; set => Set(ref _header_row_display, value); } - public IEnumerable header_row_display_options => PNLSettings.header_row_display_options; - - string ITemplateSelectorKey.key => GridSettingsTemplateKeys.PNL; - - public PNLSettings get_result() { - var s = _last_loaded == null ? new PNLSettings() : SparkUtils.clone_proto(_last_loaded); - s.calculation_type = _calculation_type; - s.grid = core_settings_vm.create(); - // move anchor cols to the left, order wrt grouping hierarchy - var new_cols = new Lazy>(() => s.grid.columns.ToList()); - for (int i = 0; i < s.grid.columns.Count; i++) { - var key = s.grid.columns[i].strong_id(); - if (_anchor_cache.TryGetValue(key, out var a) && a.anchor_index.HasValue) { - // anchor index is 1 based, subtract 1 to get 0 based - int anchor_index = a.anchor_index.Value - 1; - if (anchor_index != i && anchor_index >= 0 && anchor_index < s.grid.columns.Count) { - new_cols.Value.RemoveAt(i); - new_cols.Value.Insert(anchor_index, s.grid.columns[i]); - } +using bts.collections; +using bts.utils; +using mbts; +using mbts.collections; +using mbts.expression; +using mbts.spark; +using mbts.ui; +using mbts.ui.settings; +using mbts.ui.shell; +using mbts.ui.spark; +using mbts.ui.utility; +using mbts.utils; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Collections.Specialized; +using System.Dynamic; +using System.Linq; +using ColumnKeys = bts.shell.pnl.PNLView.Columns; + +namespace bts.shell.pnl { + class PNLSettingsVM : DisposableViewModelBase, IWindowSettingsVM, IValueFactory, IObservable, ITemplateSelectorKey { + readonly IReadOnlyDictionary _anchor_cache; + readonly DeferrableActionWrapper _sync_anchors; + + PNLCalculationType _calculation_type; + PNLHeaderRowDisplay _header_row_display; + PNLSettings _last_loaded; + + public PNLSettingsVM(PNLSettings settings) { + // init anchor cache, deferrable resync + _anchor_cache = PNLSettings.anchorable_columns.ToDictionary(k => k, k => new AnchorItemVM(this, k)); + _sync_anchors = new DeferrableActionWrapper(() => { + for (int i = 0; i < anchor_items.Count; i++) { + anchor_items[i].anchor_index = i + 1; + anchor_items[i].refresh(); } - } - // rule-based animations - var trigger_anims = core_settings_vm.columns - .OfType() - .SelectMany(c => c.get_triggers()) - .GroupBy(tup => tup.expression) - .Where(g => CoreExpressionEvaluator.validate(g.Key)) - .Select(g => ( - expression: g.Key, - animations: g.ToArray())) - .ToList(); - - var normalized_anims = trigger_anims - .Where(tup => CoreExpressionEvaluator.validate(tup.expression)) - .ToList(); - - s = s.with(anchors: anchor_items.Select(vm => vm.key), - grid: new_cols.IsValueCreated ? s.grid.with(columns: new_cols.Value) : null, - group_columns: core_settings_vm.columns.OfType().Select(c => { - var col_settings = c.create(); - col_settings = c.group_column_vm.apply_to(col_settings); - return col_settings; - }), - header_columns: core_settings_vm.columns.OfType().Select(c => { - var col_settings = c.create(); - col_settings = c.header_column_vm.apply_to(col_settings); - return col_settings; - }), - animations: trigger_anims.Select( - ta => new PNLAnimationTriggerData { - expression = ta.expression, - animations = Array.ConvertAll(ta.animations, t => t.row) - }), - group_header_animations: normalized_anims - .Select( - ta => new PNLAnimationTriggerData { - expression = ta.expression, - animations = Array.ConvertAll(ta.animations, t => t.group) - }), - header_row_animations: normalized_anims.Select( - ta => new PNLAnimationTriggerData { - expression = ta.expression, - animations = Array.ConvertAll(ta.animations, t => t.header) - })); - s.header_row_display = header_row_display; - s.header_cell_appearance = PNLCellAppearanceProto.from_appearance(header_row_defaults.to_appearance()); - // group - var (group_cell_appearance, group_row_background_colors) = group_row_defaults.create(); - s.group_cell_appearance = PNLCellAppearanceProto.from_appearance(group_cell_appearance); - s.group_background_colors.SetItems(group_row_background_colors.Select(c => c.rgb_color())); - // - return s; - } - - public void load(PNLSettings value) { - _last_loaded = value; - header_row_defaults.load(value.header_cell_appearance.to_appearance()); - group_row_defaults.load_from((value.group_cell_appearance.to_appearance(), value.group_background_colors.WrapSelectorRO(c => c.argb_color()))); - var column_map = _map_column_data(value.grid.columns, value.animations); - var group_column_map = _map_column_data(value.group_columns, value.group_header_animations); - var header_column_map = _map_column_data(value.header_columns, value.header_row_animations); - - core_settings_vm.load_from(value.grid); - - for (int i = 0; i < core_settings_vm.columns.Count; i++) { - var col_vm = core_settings_vm.columns[i] as PNLColumnVM ?? throw new InvalidOperationException($"In {nameof(PNLSettingsVM)}, all columns should be of type {typeof(PNLColumnVM)}."); - var key = EnumHelper.parse(col_vm.id); - var (col_settings, trigger_animations) = column_map[key]; - var group_data = group_column_map.GetNullable(key); - var header_data = header_column_map.GetNullable(key); - col_vm.load_from(col_settings, trigger_animations, group_data?.settings, group_data?.triggers, header_data?.triggers, header_data?.settings); - } - using (_sync_anchors.defer_execution()) - anchor_items.WrapSelector(a => a.key, k => _anchor_cache[k]).sync_with(value.anchors.Intersect(PNLSettings.anchorable_columns)); - header_row_display = value.header_row_display; - calculation_type = value.calculation_type; - } - - PNLSettings IValueFactory.create() => get_result(); - void IValueFactory.load_from(PNLSettings value) => load(value); - IDisposable IObservable.Subscribe(IObserver observer) => throw new NotImplementedException(); - - static Dictionary triggers)> _map_column_data(IEnumerable columns, IEnumerable triggers) { - var map = columns.ToDictionary( - c => c.strong_id(), - c => (settings: c, triggers: new Dictionary())); - foreach (var trig in triggers) { - foreach (var anim in trig.animations) { - if (map.TryGetValue(anim.column, out var col_data)) - col_data.triggers[trig.expression] = anim; - } - } - return map; - } - - void _append_or_remove_anchor(ColumnKeys key, bool include) { - if (!_anchor_cache.TryGetValue(key, out var vm)) - throw new KeyNotFoundException($"Column key '{key}' is not anchorable (expected one of: {string.Join(", ", PNLSettings.anchorable_columns)})."); - if (vm.include == include) - return; - if (include) { - if (anchor_items.Any(a => a.key == key)) - throw new InvalidOperationException($"{nameof(anchor_items)} already contains an element with key '{key}.'"); - anchor_items.Add(vm); - vm.anchor_index = anchor_items.Count; - } else { - if (!anchor_items.Remove(vm)) - throw new InvalidOperationException($"{nameof(anchor_items)} does not contain an element with key '{key}.'"); - vm.anchor_index = null; - } - _sync_anchors.execute(); - } - - public class AnchorItemVM : ViewModelBase, IEquatable { - readonly PNLSettingsVM _owner; - int? _anchor_index; - - public AnchorItemVM(PNLSettingsVM owner, ColumnKeys key) { - _owner = owner; - this.key = key; - } - - public ColumnKeys key { get; } - public bool include { get => anchor_index.HasValue; set => _owner._append_or_remove_anchor(key, value); } - public int? anchor_index { get => _anchor_index; set => Set(ref _anchor_index, value); } - - public void refresh() => - RaisePropertyChanged(nameof(include), nameof(anchor_index)); - - public bool Equals(AnchorItemVM other) => - other != null && key == other.key; - - public override bool Equals(object obj) => - Equals(obj as AnchorItemVM); - - public override int GetHashCode() => - key.GetHashCode(); - - public override string ToString() => - EnumHelper.get_display_name(key); - } - } + }); + core_settings_vm = new SimpleGridSettingsVM(column_factory: col_settings => { + var col_vm = new PNLColumnVM(core_settings_vm, EnumHelper.parse(col_settings.id)); + col_vm.load_from(col_settings); + return col_vm; + }); + core_settings_vm.selection_highlight.bind_opacity_to_alpha = true; + _dispose = Disposable.Create( + anchor_items.Subscribe((s, e) => _sync_anchors.execute())); + load(settings); + } + + public IEnumerable anchor_item_headers => _anchor_cache.Values; + public ObservableCollection anchor_items { get; } = new ObservableCollection(); + public SimpleGridSettingsVM core_settings_vm { get; } + public PNLGroupRowAppearanceVM group_row_defaults { get; } = new PNLGroupRowAppearanceVM(); + public PNLCellAppearanceVM header_row_defaults { get; } = new PNLCellAppearanceVM(); + public PNLCalculationType calculation_type { get => _calculation_type; set => Set(ref _calculation_type, value); } + public IEnumerable calculation_types => EnumHelper.get_values_except(PNLCalculationType.None, PNLCalculationType.Same, PNLCalculationType.Opposite); + public PNLHeaderRowDisplay header_row_display { get => _header_row_display; set => Set(ref _header_row_display, value); } + public IEnumerable header_row_display_options => PNLSettings.header_row_display_options; + + string ITemplateSelectorKey.key => GridSettingsTemplateKeys.PNL; + + public PNLSettings get_result() { + var s = _last_loaded == null ? new PNLSettings() : SparkUtils.clone_proto(_last_loaded); + s.calculation_type = _calculation_type; + s.grid = core_settings_vm.create(); + // move anchor cols to the left, order wrt grouping hierarchy + List new_cols = null; + IEnumerable cols = s.grid.columns; + var sorted_anchors = anchor_items.OrderBy(a => a.anchor_index).ToList(); + for (int i = 0; i < sorted_anchors.Count; i++) { + if (GridSettingsHelper.try_find_column(cols, sorted_anchors[i].key, out var match, out int pos) && pos != i) { + if (new_cols == null) { + new_cols = s.grid.columns.ToList(); + // set cols to new_cols so subsequent position lookups + // take previous column order manipulations into account. + cols = new_cols; + } + new_cols.RemoveAt(pos); + new_cols.Insert(i, match); + } + } + // rule-based animations + var trigger_anims = core_settings_vm.columns + .OfType() + .SelectMany(c => c.get_triggers()) + .GroupBy(tup => tup.expression) + .Where(g => CoreExpressionEvaluator.validate(g.Key)) + .Select(g => ( + expression: g.Key, + animations: g.ToArray())) + .ToList(); + + var normalized_anims = trigger_anims + .Where(tup => CoreExpressionEvaluator.validate(tup.expression)) + .ToList(); + + s = s.with(anchors: anchor_items.Select(vm => vm.key), + grid: new_cols == null ? null : s.grid.with(columns: new_cols), + group_columns: core_settings_vm.columns.OfType().Select(c => { + var col_settings = c.create(); + col_settings = c.group_column_vm.apply_to(col_settings); + return col_settings; + }), + header_columns: core_settings_vm.columns.OfType().Select(c => { + var col_settings = c.create(); + col_settings = c.header_column_vm.apply_to(col_settings); + return col_settings; + }), + animations: trigger_anims.Select( + ta => new PNLAnimationTriggerData { + expression = ta.expression, + animations = Array.ConvertAll(ta.animations, t => t.row) + }), + group_header_animations: normalized_anims + .Select( + ta => new PNLAnimationTriggerData { + expression = ta.expression, + animations = Array.ConvertAll(ta.animations, t => t.group) + }), + header_row_animations: normalized_anims.Select( + ta => new PNLAnimationTriggerData { + expression = ta.expression, + animations = Array.ConvertAll(ta.animations, t => t.header) + })); + s.header_row_display = header_row_display; + s.header_cell_appearance = PNLCellAppearanceProto.from_appearance(header_row_defaults.to_appearance()); + // group + var (group_cell_appearance, group_row_background_colors) = group_row_defaults.create(); + s.group_cell_appearance = PNLCellAppearanceProto.from_appearance(group_cell_appearance); + s.group_background_colors.SetItems(group_row_background_colors.Select(c => c.rgb_color())); + // + return s; + } + + public void load(PNLSettings value) { + _last_loaded = value; + header_row_defaults.load(value.header_cell_appearance.to_appearance()); + group_row_defaults.load_from((value.group_cell_appearance.to_appearance(), value.group_background_colors.WrapSelectorRO(c => c.argb_color()))); + var column_map = _map_column_data(value.grid.columns, value.animations); + var group_column_map = _map_column_data(value.group_columns, value.group_header_animations); + var header_column_map = _map_column_data(value.header_columns, value.header_row_animations); + + core_settings_vm.load_from(value.grid); + + for (int i = 0; i < core_settings_vm.columns.Count; i++) { + var col_vm = core_settings_vm.columns[i] as PNLColumnVM ?? throw new InvalidOperationException($"In {nameof(PNLSettingsVM)}, all columns should be of type {typeof(PNLColumnVM)}."); + var key = EnumHelper.parse(col_vm.id); + var (col_settings, trigger_animations) = column_map[key]; + var group_data = group_column_map.GetNullable(key); + var header_data = header_column_map.GetNullable(key); + col_vm.load_from(col_settings, trigger_animations, group_data?.settings, group_data?.triggers, header_data?.triggers, header_data?.settings); + } + using (_sync_anchors.defer_execution()) + anchor_items.WrapSelector(a => a.key, k => _anchor_cache[k]).sync_with(value.anchors.Intersect(PNLSettings.anchorable_columns)); + header_row_display = value.header_row_display; + calculation_type = value.calculation_type; + } + + PNLSettings IValueFactory.create() => get_result(); + void IValueFactory.load_from(PNLSettings value) => load(value); + IDisposable IObservable.Subscribe(IObserver observer) => throw new NotImplementedException(); + + static Dictionary triggers)> _map_column_data(IEnumerable columns, IEnumerable triggers) { + var map = columns.ToDictionary( + c => c.strong_id(), + c => (settings: c, triggers: new Dictionary())); + foreach (var trig in triggers) { + foreach (var anim in trig.animations) { + if (map.TryGetValue(anim.column, out var col_data)) + col_data.triggers[trig.expression] = anim; + } + } + return map; + } + + void _append_or_remove_anchor(ColumnKeys key, bool include) { + if (!_anchor_cache.TryGetValue(key, out var vm)) + throw new KeyNotFoundException($"Column key '{key}' is not anchorable (expected one of: {string.Join(", ", PNLSettings.anchorable_columns)})."); + if (vm.include == include) + return; + if (include) { + if (anchor_items.Any(a => a.key == key)) + throw new InvalidOperationException($"{nameof(anchor_items)} already contains an element with key '{key}.'"); + anchor_items.Add(vm); + vm.anchor_index = anchor_items.Count; + } else { + if (!anchor_items.Remove(vm)) + throw new InvalidOperationException($"{nameof(anchor_items)} does not contain an element with key '{key}.'"); + vm.anchor_index = null; + } + _sync_anchors.execute(); + } + + public class AnchorItemVM : ViewModelBase, IEquatable { + readonly PNLSettingsVM _owner; + int? _anchor_index; + + public AnchorItemVM(PNLSettingsVM owner, ColumnKeys key) { + _owner = owner; + this.key = key; + } + + public ColumnKeys key { get; } + public bool include { get => anchor_index.HasValue; set => _owner._append_or_remove_anchor(key, value); } + public int? anchor_index { get => _anchor_index; set => Set(ref _anchor_index, value); } + + public void refresh() => + RaisePropertyChanged(nameof(include), nameof(anchor_index)); + + public bool Equals(AnchorItemVM other) => + other != null && key == other.key; + + public override bool Equals(object obj) => + Equals(obj as AnchorItemVM); + + public override int GetHashCode() => + key.GetHashCode(); + + public override string ToString() => + EnumHelper.get_display_name(key); + } + } } \ No newline at end of file From 45e10ca3770568908a1c980ec4aecc3a4e9fe071 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Thu, 14 Nov 2019 21:09:31 -0600 Subject: [PATCH 17/36] SP-265 use 'is' instead of explicit cast to IPNLCellData (the cast should work; this is defensive) --- .../spark/Modules/Trading/PNL/VM/PNLRowComparer.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/client/spark/Modules/Trading/PNL/VM/PNLRowComparer.cs b/src/client/spark/Modules/Trading/PNL/VM/PNLRowComparer.cs index 0932b01db..9d88699da 100644 --- a/src/client/spark/Modules/Trading/PNL/VM/PNLRowComparer.cs +++ b/src/client/spark/Modules/Trading/PNL/VM/PNLRowComparer.cs @@ -90,12 +90,11 @@ namespace bts.shell.pnl { } int? _try_compare_groups(CollectionViewGroup x, CollectionViewGroup y) { - if (x == null || y == null) - return null; - var xcell = (IPNLCellData)x.Name; - var ycell = (IPNLCellData)y.Name; - var comp = _get_column_comparer(xcell.column); - return comp.value_comparer.Compare(xcell.value, ycell.value); + if (x?.Name is IPNLCellData xcell && y?.Name is IPNLCellData ycell) { + var comp = _get_column_comparer(xcell.column); + return comp.value_comparer.Compare(xcell.value, ycell.value); + } + return null; } } -} \ No newline at end of file +} From 6aad329e095ae29722ece522fbda3c81752839de Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Mon, 18 Nov 2019 13:03:53 -0500 Subject: [PATCH 18/36] Include ice symbol list in defaults for windows --- src/lib/config/defaults/Symbols.conf | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib/config/defaults/Symbols.conf b/src/lib/config/defaults/Symbols.conf index 93b7126d9..9f4d0f77a 100644 --- a/src/lib/config/defaults/Symbols.conf +++ b/src/lib/config/defaults/Symbols.conf @@ -96,6 +96,10 @@ Symbols { future: @SymbolLists.list[GLBX].symbol spread: @SymbolLists.list[GLBX].symbol } + simice { + future: @SymbolLists.list[ICE].symbol + spread: @SymbolLists.list[ICE].symbol + } } } @@ -106,6 +110,10 @@ Symbols { future: @SymbolLists.list[GLBX].symbol spread: @SymbolLists.list[GLBX].symbol } + ice { + future: @SymbolLists.list[ICE].symbol + spread: @SymbolLists.list[ICE].symbol + } } } From 234d4997313bc74df85ff6548421566063d181b7 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 19 Nov 2019 08:51:38 -0600 Subject: [PATCH 19/36] adding ladder spacebar test --- testing/manual/settings/Ladder_Spacebar.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 testing/manual/settings/Ladder_Spacebar.txt diff --git a/testing/manual/settings/Ladder_Spacebar.txt b/testing/manual/settings/Ladder_Spacebar.txt new file mode 100644 index 000000000..b22fe6c15 --- /dev/null +++ b/testing/manual/settings/Ladder_Spacebar.txt @@ -0,0 +1,10 @@ +This isn't a setting exactly, but rather a test of keyboard functionality. Currently we are only testing the spacebar key. + +1. Verify pressing the spacebar while in a Ladder Window recenters ALL ladders +Launch 2 ladders +Click one of the Ladder windows to make sure said window receives focus +Scroll both ladders so they are no longer centered at mid market +Press the spacebar + You should observe both scrolled ladders are now centered once again + The countdown timer is also reset via this spacebar action. This is more informational; I don't expect you to wait to verify that the timer is reset. + From a9b40493079bfd4f7ae73d44f0b26beaf77ab19c Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 20 Nov 2019 09:13:58 -0600 Subject: [PATCH 20/36] relocating bus.post of recenter all to common public ladder function --- src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs b/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs index 3d9b7ed1a..ca85b7b7f 100644 --- a/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs +++ b/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs @@ -467,6 +467,10 @@ namespace mbts.spark { settings_invalidated?.Invoke(); } + public void recenter_all_ladders() { + _bus?.post(SparkTags.RequestRecenterLadder, null); + } + public Task send_order_async((double price, Side? side, MouseButton button) args) { if (order_properties_vm != null && args.button != MouseButton.Middle) { var size_from_alternate = args.button == MouseButton.Right; From 14ebe5ef5178495c2d9d06d5146b89cabc4f7c4e Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 20 Nov 2019 09:14:20 -0600 Subject: [PATCH 21/36] (shift or alt) + double click to recenter all ladders --- .../Modules/Trading/Ladder/View/LadderGridHost.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/client/spark/Modules/Trading/Ladder/View/LadderGridHost.cs b/src/client/spark/Modules/Trading/Ladder/View/LadderGridHost.cs index 32f2725c7..7a51bc6d2 100644 --- a/src/client/spark/Modules/Trading/Ladder/View/LadderGridHost.cs +++ b/src/client/spark/Modules/Trading/Ladder/View/LadderGridHost.cs @@ -490,8 +490,14 @@ namespace mbts.spark { protected override void OnMouseDoubleClick(MouseButtonEventArgs e) { var column = _column_for_point(e.GetPosition(this)); - if (column.column_type == ColumnType.Price) - _scroll_to_center(); + if (column.column_type == ColumnType.Price) { + if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift) || + Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt)) { + _vm?.recenter_all_ladders(); + } else { + _scroll_to_center(); + } + } } #region Row Utility Methods From bd28a0fa548a411c921e7132e404f73f75291842 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 20 Nov 2019 09:45:27 -0600 Subject: [PATCH 22/36] delete old test --- testing/manual/settings/Ladder_Spacebar.txt | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 testing/manual/settings/Ladder_Spacebar.txt diff --git a/testing/manual/settings/Ladder_Spacebar.txt b/testing/manual/settings/Ladder_Spacebar.txt deleted file mode 100644 index b22fe6c15..000000000 --- a/testing/manual/settings/Ladder_Spacebar.txt +++ /dev/null @@ -1,10 +0,0 @@ -This isn't a setting exactly, but rather a test of keyboard functionality. Currently we are only testing the spacebar key. - -1. Verify pressing the spacebar while in a Ladder Window recenters ALL ladders -Launch 2 ladders -Click one of the Ladder windows to make sure said window receives focus -Scroll both ladders so they are no longer centered at mid market -Press the spacebar - You should observe both scrolled ladders are now centered once again - The countdown timer is also reset via this spacebar action. This is more informational; I don't expect you to wait to verify that the timer is reset. - From fa49a0de07b27f0cbe31fc24cb4eb2a13f493423 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 20 Nov 2019 09:45:51 -0600 Subject: [PATCH 23/36] adding new test --- testing/manual/settings/Ladder_RecenterAll.txt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 testing/manual/settings/Ladder_RecenterAll.txt diff --git a/testing/manual/settings/Ladder_RecenterAll.txt b/testing/manual/settings/Ladder_RecenterAll.txt new file mode 100644 index 000000000..c7c6d5018 --- /dev/null +++ b/testing/manual/settings/Ladder_RecenterAll.txt @@ -0,0 +1,6 @@ +1. Verify pressing the shift or alt key while double clicking in the Price column in a Ladder Window recenters ALL ladders +Launch 2 ladders +Scroll both ladders so they are no longer centered at mid market +Press the shift + double click while over the Price column + You should observe both scrolled ladders are now centered once again + The countdown timer is also reset via this spacebar action. This is more informational; I don't expect you to wait to verify that the timer is reset. \ No newline at end of file From 26b5fe56999c1956f2b8a263647b4b9247297fae Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 20 Nov 2019 09:47:38 -0600 Subject: [PATCH 24/36] updating release notes --- doc/user/content/release_notes/_index.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/user/content/release_notes/_index.md b/doc/user/content/release_notes/_index.md index 99931f53d..3b1adae92 100644 --- a/doc/user/content/release_notes/_index.md +++ b/doc/user/content/release_notes/_index.md @@ -6,9 +6,14 @@ insert_anchor_links = "right" +++ ## 2.14.0 ### User Visible Changes + - All ladders can now be recentered by (shift or alt) + double clicking over the Price column in a ladder + - Added a Max Order Quantity setting to the Safety Checks tab on the Ladder settings. This setting allows for a user-defined maximum order quantity. + - Added a Price Display Format setting to the Market Price and Size Display tab on the Ladder settings. This setting allows for price levels in the ladder to be displayed without a decimal separator. + - Synthetic instrument creation with 3 legs no longer defaults to butterfly quantites ### Bug Fixes - Fixed an issue where market transition were not observed by IAlgoOrder - Fixed a bug in error reporting + - Fixed a bug in the PnL window where specifying a certain grouping order would lead to a UI failure ## 2.13.0 ### User Visible Changes From b62d9751cf773abbcf0516484a1e19aaa3470293 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Wed, 20 Nov 2019 14:57:56 -0500 Subject: [PATCH 25/36] chown duplicates files in docker image --- src/sdk/Dockerfile | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/sdk/Dockerfile b/src/sdk/Dockerfile index 3da602c57..3da5c5045 100644 --- a/src/sdk/Dockerfile +++ b/src/sdk/Dockerfile @@ -12,19 +12,22 @@ env SDK_ROOT=/sdk \ SDK_VERSION=$SDK_VERSION \ SDK_BUILD_DATE=$SDK_BUILD_DATE -# copy sdk -COPY include/ /sdk/include/ -COPY lib/ /sparkbin/ -COPY externals /sdk/externals/ -COPY spark.conf /sparkdata/conf/ -COPY futures.coconut /sparkdata/data/replay/futures.coconut - # add user bts RUN groupadd --gid 1000 $USERNAME && \ useradd -s /bin/bash --uid 1000 --gid 1000 -m $USERNAME && \ + mkdir -p /sparkbin/plugins && \ + mkdir /sparkdata && \ ln -s /sparkbin/ sdk/lib && \ echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME && \ chmod 0440 /etc/sudoers.d/$USERNAME && \ chown -R bts.bts /sparkbin/plugins && \ chown -R bts.bts /sparkdata +# copy sdk +COPY include/ /sdk/include/ +COPY lib/ /sparkbin/ +COPY externals /sdk/externals/ +COPY spark.conf /sparkdata/conf/ +COPY --chown=$USERNAME futures.coconut /sparkdata/data/replay/futures.coconut + + From 2688281a10a5eacd6ed2af547b5ba3538f0e147b Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Mon, 16 Dec 2019 10:26:34 -0500 Subject: [PATCH 26/36] Protect against ICE 0-leg spread data on cert --- .../md/platforms/ice_onixs/ICEListener.h | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/server/sparkd/md/platforms/ice_onixs/ICEListener.h b/src/server/sparkd/md/platforms/ice_onixs/ICEListener.h index b73cf1c49..cd7001d41 100644 --- a/src/server/sparkd/md/platforms/ice_onixs/ICEListener.h +++ b/src/server/sparkd/md/platforms/ice_onixs/ICEListener.h @@ -212,30 +212,32 @@ void ICEListener::on_uds_future_spread(const Definition& def, bool& is_intereste fsec.alt_symbol(def.strategySymbol); const auto& legs = def.legs; - fsec.set_leg_count(legs.size()); - for(size_t x = 0; x < fsec.leg_count(); ++x) - { - const auto& leg = legs[x]; - if(leg.ratioPriceNumerator && leg.ratioPriceDenominator) + if (legs.size() > 0) { + fsec.set_leg_count(legs.size()); + for(size_t x = 0; x < fsec.leg_count(); ++x) { - auto num = *leg.ratioPriceNumerator; - auto denom = *leg.ratioPriceDenominator; - fsec.legs[x].leg_price = num / (double) denom; + const auto& leg = legs[x]; + if(leg.ratioPriceNumerator && leg.ratioPriceDenominator) + { + auto num = *leg.ratioPriceNumerator; + auto denom = *leg.ratioPriceDenominator; + fsec.legs[x].leg_price = num / (double) denom; + } + if(leg.ratioQtyNumerator && leg.ratioQtyDenominator) + { + auto num = *leg.ratioQtyNumerator; + auto denom = *leg.ratioQtyDenominator; + fsec.legs[x].leg_delta = num / (double) denom; + } + + fsec.legs[x].leg_quantity = leg.ratio; + fsec.legs[x].leg_side = leg.side == onixs_ice::Side::Bid ? api::SIDE_BUY : api::SIDE_SELL; + fsec.legs[x].exchange_key = ExchangeKey(leg.marketId); + fsec.legs[x].key = invalid_security_key; } - if(leg.ratioQtyNumerator && leg.ratioQtyDenominator) - { - auto num = *leg.ratioQtyNumerator; - auto denom = *leg.ratioQtyDenominator; - fsec.legs[x].leg_delta = num / (double) denom; - } - - fsec.legs[x].leg_quantity = leg.ratio; - fsec.legs[x].leg_side = leg.side == onixs_ice::Side::Bid ? api::SIDE_BUY : api::SIDE_SELL; - fsec.legs[x].exchange_key = ExchangeKey(leg.marketId); - fsec.legs[x].key = invalid_security_key; + add_security(fsec); + is_interested = true; } - add_security(fsec); - is_interested = true; } From 9a3b07b622bf784b86a8cd036a7d694455432001 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 17 Dec 2019 10:21:38 -0600 Subject: [PATCH 27/36] adding ToCsv IEnumerable ext method in a new util namespace --- src/client/spark_core/utils/CsvHelper.cs | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/client/spark_core/utils/CsvHelper.cs diff --git a/src/client/spark_core/utils/CsvHelper.cs b/src/client/spark_core/utils/CsvHelper.cs new file mode 100644 index 000000000..afc1dbd90 --- /dev/null +++ b/src/client/spark_core/utils/CsvHelper.cs @@ -0,0 +1,30 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace bts.utils.csv { + public static class CsvHelper { + + public static string ToCsv(this IEnumerable items, IEnumerable properties = null) where T : class { + var output = ""; + var delimiter = ","; + properties = properties == null ? typeof(T).GetProperties() : properties; + + using (var sw = new StringWriter()) { + var header = properties.Select(n => n.Name).Aggregate((first, second) => first + delimiter + second); + sw.WriteLine(header); + foreach (var i in items) { + var row = properties.Select(x => x.GetValue(i, null)) + .Select(x => x == null ? "null" : x.ToString()) + .Aggregate((first, second) => first + delimiter + second); + sw.WriteLine(row); + } + output = sw.ToString(); + } + return output; + } + + } +} From 219dff405517aa5773fe8b5671445d3d99bd791f Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 17 Dec 2019 10:28:57 -0600 Subject: [PATCH 28/36] adding new export_csv IDialogCommand which just creates a new file --- .../Extensions/Command/FileDialogCommand.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/client/spark/view/Extensions/Command/FileDialogCommand.cs b/src/client/spark/view/Extensions/Command/FileDialogCommand.cs index 7b0778f1a..7889416f9 100644 --- a/src/client/spark/view/Extensions/Command/FileDialogCommand.cs +++ b/src/client/spark/view/Extensions/Command/FileDialogCommand.cs @@ -64,6 +64,25 @@ namespace mbts.ui { } }, can_execute == null ? null : new Func(_ => can_execute())); + public static IDialogCommand export_csv( + Func get_file_content, + string source_window_name) => + new AnonymousFileDialogCommand(_ => + _create_save_file_dialog( + Environment.GetFolderPath(Environment.SpecialFolder.Desktop), + $"BTS_Spark_{source_window_name}_{DateTime.Now.ToString("yyyyMMdd_HHmm")}.csv", + new[] { ("CSV (comma delimited)", new string[] { "csv" }) } + ), + (_, file) => { + try { + File.WriteAllText(file, get_file_content.Invoke()); + } catch (Exception ex) { + BTSMessageBox.Show($"Error exporting data to csv: {ex}.", "CSV Export Error", BTSMessageBoxButtons.OK, System.Windows.MessageBoxImage.Error, true, false, true); + } + }, + // we are always able to perform an export, even when no rows (it will just be a header) + (_) => true); + static TDialog _create_file_dialog(string initial_dir = null, IReadOnlyList<(string name, string[] extensions)> filter_items = null) where TDialog : FileDialog, new() { var rv = new TDialog(); if (!string.IsNullOrEmpty(initial_dir)) From 6074afd9996373404e1a6bcae89eef8e6f815de3 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 17 Dec 2019 10:32:15 -0600 Subject: [PATCH 29/36] adding csv export command to fills vm --- .../spark/Modules/Trading/Fills/FillsVM.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/client/spark/Modules/Trading/Fills/FillsVM.cs b/src/client/spark/Modules/Trading/Fills/FillsVM.cs index e370685ea..70e5d1977 100644 --- a/src/client/spark/Modules/Trading/Fills/FillsVM.cs +++ b/src/client/spark/Modules/Trading/Fills/FillsVM.cs @@ -5,6 +5,7 @@ using bts.collections; using bts.shell.fills; using bts.spark; using bts.utils; +using bts.utils.csv; using mbts.collections; using mbts.persist; using mbts.spark.filters; @@ -23,6 +24,7 @@ using System.Linq; using System.Reactive.Disposables; using System.Reactive.Linq; using System.Windows.Data; +using System.Windows.Input; using System.Windows.Media; using static bts.api.orderman.Fill.Types; using static bts.shell.FillsWindowFactory; @@ -145,6 +147,7 @@ namespace mbts.spark { _unfiltered_fills_changed += o.OnNext; return Disposable.Create(() => _unfiltered_fills_changed -= o.OnNext); }); + export_to_csv_command = FileDialogCommand.export_csv(() => rows.ToCsv(Row.csv_properties), "Fills"); _dispose = new CompositeDisposable( ObservableAutoWrapper.connect(col_tups, columns, ct => ct.col), ObservableAutoWrapper.connect_item_hooks(col_tups, ct => ct.filter as IDisposable), @@ -210,6 +213,8 @@ namespace mbts.spark { public void on_sorting(object sender, DIYGridSortingEventArgs e) => _rows_manager.on_sorting(e); + public ICommand export_to_csv_command { get; } + static Columns _col_key(ColumnBase column) => ((IKeyedColumn)column).key; @@ -309,6 +314,27 @@ namespace mbts.spark { public override bool Equals(object obj) => Equals(obj as Row); public override int GetHashCode() => _fill.FillKey.GetHashCode() ^ _order.Key.GetHashCode(); + static HashSet _properties_for_csv_export = new HashSet(new string[] { + nameof(fill_time), + nameof(time_in_force), + nameof(order_type), + nameof(display_name), + nameof(account), + nameof(user), + nameof(exchange), + nameof(side), + nameof(price), + nameof(size), + nameof(fill_kind), + nameof(fill_status), + nameof(fill_key), + nameof(order_key), + nameof(root_algo_order_type), + nameof(root_algo_display_name) + }); + public static IEnumerable csv_properties => typeof(Row).GetProperties() + .Where(x => _properties_for_csv_export.Contains(x.Name)); + public event Action invalidated; void IRowVM.raise_invalidated() => invalidated?.Invoke(); } From efc175f65484d983a6531007ce1f25a052da1bf5 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 17 Dec 2019 10:32:58 -0600 Subject: [PATCH 30/36] adding export to csv command to Fills window --- src/client/spark/Modules/Trading/Fills/FillsWindow.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/client/spark/Modules/Trading/Fills/FillsWindow.cs b/src/client/spark/Modules/Trading/Fills/FillsWindow.cs index 090fd86b5..3d25ba1f0 100644 --- a/src/client/spark/Modules/Trading/Fills/FillsWindow.cs +++ b/src/client/spark/Modules/Trading/Fills/FillsWindow.cs @@ -59,6 +59,7 @@ namespace mbts.spark { _view = new FillsView { DataContext = _vm }; _commands = new List { + new SparkCommandCommand("Export to csv", Icons.Export, _vm.export_to_csv_command), // wrap the grid settings view factory in a dialogCommand here since the vm is destroyed/recreated when the security criteria changes SparkCommands.window_settings_command(new DialogCommand(() => { var vm = new ShellSettingsDialogVM( From b5f53ee9181d70544b04d53ef8ae2ca8fc480125 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 18 Dec 2019 10:10:04 -0600 Subject: [PATCH 31/36] adding csv_properties to TimeAndSalesVM.Row --- .../Modules/Market/TimeAndSales/TimeAndSalesVM.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesVM.cs b/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesVM.cs index e2b5b8139..ce68f2a9c 100644 --- a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesVM.cs +++ b/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesVM.cs @@ -52,7 +52,7 @@ namespace mbts.spark { columns.Add(new RenderTextColumn(col_key, r => r[col_key], filter, filter_template, r => _get_aggressor_brush(r)) { id = col_id(col_key), Header = header, Width = width, sort_member_path = sort_member_path, horizontal_alignment = h_alignment } ); - + // be sure to load GridSettings AFTER the columns collection has been populated, the grid settings manager looks columns by id to apply the appropriate settings, // if the collection is not populated, the column settings will not be applied grid_settings_manager = new SimpleGridSettingsManager(columns, new Dictionary { }, row_vms); @@ -173,6 +173,19 @@ namespace mbts.spark { } } + static HashSet _properties_for_csv_export = new HashSet(new string[] { + nameof(security), + nameof(trade_key), + nameof(time), + nameof(price), + nameof(size), + nameof(aggressor_side), + }); + public static IEnumerable csv_properties => typeof(Row).GetProperties() + .Where(x => _properties_for_csv_export.Contains(x.Name) + ); + + public void raise_invalidated() => invalidated?.Invoke(); } } From 9eada2724bcce5a942ceb8249dc91ae0d52671ab Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 18 Dec 2019 10:11:10 -0600 Subject: [PATCH 32/36] Having the Command be on the Window rather than the VM; nice thinking John --- .../spark/Modules/Market/TimeAndSales/TimeAndSalesWindow.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesWindow.cs b/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesWindow.cs index 85938778a..d506ddba2 100644 --- a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesWindow.cs +++ b/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesWindow.cs @@ -3,6 +3,7 @@ using bts.api; using bts.shell; using bts.shell.fills; using bts.spark; +using bts.utils.csv; using mbts.co2; using mbts.persist; using mbts.ui; @@ -63,6 +64,7 @@ namespace mbts.spark { var current_smd_source = connectable_builder.create(vm => vm.current_security_md_observable(_bus)).OnDispatcher(); var selected_secs_source = connectable_builder.create(vm => vm.selected_securities_observable()).OnDispatcher(); _commands = new SparkCommand[] { + new SparkCommandCommand("Export to csv", Icons.Export, FileDialogCommand.export_csv(() => _vm.value.row_vms.ToCsv(TimeAndSalesVM.Row.csv_properties), "TaS")), SparkCommands.ShowLadder(SparkCommands.KeyGestures.ShowLadder).complete(current_smd_source, md => md.HasValue, ConvertUtils.ValueOrDefault), SparkCommands.ShowOrderTicketFromSecurity(SparkCommands.KeyGestures.ShowOrderTicket).complete(current_smd_source, md => md.HasValue, ConvertUtils.ValueOrDefault), SparkCommands.ShowFills(SparkCommands.KeyGestures.ShowFills).complete(selected_secs_source, always_true, get_fills_startup_data), From 980f38ba033fe7343ff857fa1470ffb0bf4302d3 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 18 Dec 2019 13:46:22 -0600 Subject: [PATCH 33/36] using OrderedDictionary to CSVs are output with a predictable column order --- src/client/spark_core/utils/CsvHelper.cs | 30 ++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/client/spark_core/utils/CsvHelper.cs b/src/client/spark_core/utils/CsvHelper.cs index afc1dbd90..2b4fdfbe9 100644 --- a/src/client/spark_core/utils/CsvHelper.cs +++ b/src/client/spark_core/utils/CsvHelper.cs @@ -1,22 +1,29 @@ using System; using System.IO; using System.Collections.Generic; +using System.Collections.Specialized; using System.Linq; using System.Reflection; namespace bts.utils.csv { public static class CsvHelper { - public static string ToCsv(this IEnumerable items, IEnumerable properties = null) where T : class { + public static string ToCsv(this IEnumerable items, OrderedDictionary properties = null) where T : class { var output = ""; var delimiter = ","; - properties = properties == null ? typeof(T).GetProperties() : properties; + if (properties == null) { + properties = new OrderedDictionary(); + foreach (var pi in typeof(T).GetProperties()) { + properties.Add(pi.Name, pi); + } + } using (var sw = new StringWriter()) { - var header = properties.Select(n => n.Name).Aggregate((first, second) => first + delimiter + second); + var dict_values = properties.Values.OfType(); + var header = dict_values.Select(n => n.Name).Aggregate((first, second) => first + delimiter + second); sw.WriteLine(header); foreach (var i in items) { - var row = properties.Select(x => x.GetValue(i, null)) + var row = dict_values.Select(x => x.GetValue(i, null)) .Select(x => x == null ? "null" : x.ToString()) .Aggregate((first, second) => first + delimiter + second); sw.WriteLine(row); @@ -26,5 +33,20 @@ namespace bts.utils.csv { return output; } + public static OrderedDictionary create_ordering_maintainer(Type t, string[] property_names_in_order) { + OrderedDictionary od = new OrderedDictionary(); + var props = t.GetProperties(); + foreach (var n in property_names_in_order) { + var query = props.Where(pi => pi.Name == n); + if (query.Any()) { + var property_info = query.First(); + if (!od.Contains(property_info)) { + od.Add(n, property_info); + } + } + } + return od; + } + } } From 54f954fd4b9dfdee2e52f8f3394dd83ac45cec0f Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 18 Dec 2019 13:47:03 -0600 Subject: [PATCH 34/36] adding CSV export to order book --- .../Trading/OrderBook/OrderBookRowVM.cs | 31 +++++++++++++++++++ .../Trading/OrderBook/OrderBookWindow.cs | 2 ++ 2 files changed, 33 insertions(+) diff --git a/src/client/spark/Modules/Trading/OrderBook/OrderBookRowVM.cs b/src/client/spark/Modules/Trading/OrderBook/OrderBookRowVM.cs index 8644745b1..a4ebe3f3a 100644 --- a/src/client/spark/Modules/Trading/OrderBook/OrderBookRowVM.cs +++ b/src/client/spark/Modules/Trading/OrderBook/OrderBookRowVM.cs @@ -4,6 +4,7 @@ using bts.api.orderman; using bts.collections; using bts.spark; using bts.utils; +using bts.utils.csv; using mbts.ui; using mbts.ui.controls; using System; @@ -11,6 +12,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Reactive.Linq; using System.Runtime.CompilerServices; +using System.Linq; using System.Windows.Input; using System.Windows.Media; using Columns = mbts.spark.OrderBookGridView.ColumnKeys; @@ -60,6 +62,35 @@ namespace mbts.spark { public event Action<(OrderSecurityRootPair oldval, OrderSecurityRootPair newval)> updated; public event PropertyChangedEventHandler PropertyChanged; + public static System.Collections.Specialized.OrderedDictionary csv_ordered_properties => + CsvHelper.create_ordering_maintainer( + typeof(OrderBookRowVM), + new string[] { + nameof(security_text), + nameof(symbol), + nameof(time_created), + nameof(last_change), + nameof(user), + nameof(account), + nameof(exchange), + nameof(time_in_force), + nameof(order_type), + nameof(root_algo_display_name), + nameof(order_sub_type), + nameof(side), + nameof(quantity), + nameof(filled_quantity), + nameof(price), + nameof(avg_price), + nameof(last_price), + nameof(piq), + nameof(status), + // last message (could contains commas, so skipping) + nameof(security_key), + nameof(order_key), + nameof(parent_order_key), + }); + // Core public OrderSecurityRootPair order_tuple { get; private set; } public OrderRecordImmutable order => order_tuple.order.order; diff --git a/src/client/spark/Modules/Trading/OrderBook/OrderBookWindow.cs b/src/client/spark/Modules/Trading/OrderBook/OrderBookWindow.cs index b416e6937..1692a0140 100644 --- a/src/client/spark/Modules/Trading/OrderBook/OrderBookWindow.cs +++ b/src/client/spark/Modules/Trading/OrderBook/OrderBookWindow.cs @@ -4,6 +4,7 @@ using bts.shell; using bts.shell.fills; using bts.shell.orderbook; using bts.spark; +using bts.utils.csv; using bts.view; using mbts.persist; using mbts.ui; @@ -184,6 +185,7 @@ namespace mbts.spark { show_grid_settings_command.group = CommandGroups.Auxiliary; _commands = new SparkCommand[] { + new SparkCommandCommand("Export to csv", Icons.Export, FileDialogCommand.export_csv(() => _vm.rows.ToCsv(OrderBookRowVM.csv_ordered_properties), "OrderBook")), toggle_show_right_panel_command, attach_selected_orders_command, detach_selected_orders_command, From 0b313a8aa81651e16840e883984f4b44129e17a4 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 18 Dec 2019 13:47:36 -0600 Subject: [PATCH 35/36] refactoring Fills CSV export --- .../spark/Modules/Trading/Fills/FillsVM.cs | 45 +++++++++---------- .../Modules/Trading/Fills/FillsWindow.cs | 3 +- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/client/spark/Modules/Trading/Fills/FillsVM.cs b/src/client/spark/Modules/Trading/Fills/FillsVM.cs index 70e5d1977..c13f07e0a 100644 --- a/src/client/spark/Modules/Trading/Fills/FillsVM.cs +++ b/src/client/spark/Modules/Trading/Fills/FillsVM.cs @@ -147,7 +147,6 @@ namespace mbts.spark { _unfiltered_fills_changed += o.OnNext; return Disposable.Create(() => _unfiltered_fills_changed -= o.OnNext); }); - export_to_csv_command = FileDialogCommand.export_csv(() => rows.ToCsv(Row.csv_properties), "Fills"); _dispose = new CompositeDisposable( ObservableAutoWrapper.connect(col_tups, columns, ct => ct.col), ObservableAutoWrapper.connect_item_hooks(col_tups, ct => ct.filter as IDisposable), @@ -213,8 +212,6 @@ namespace mbts.spark { public void on_sorting(object sender, DIYGridSortingEventArgs e) => _rows_manager.on_sorting(e); - public ICommand export_to_csv_command { get; } - static Columns _col_key(ColumnBase column) => ((IKeyedColumn)column).key; @@ -303,6 +300,7 @@ namespace mbts.spark { public FillStatus fill_status => _fill.FillStatus; public string fill_key => _fill.FillKey; public string order_key => _order.Key.ToString(); + public string symbol => fill_tuple.security?.Symbol; // Root Algo public OrderType root_algo_order_type => _root_algo.HasValue ? _root_algo.Value.value.CustomCase : OrderType.None; @@ -314,26 +312,27 @@ namespace mbts.spark { public override bool Equals(object obj) => Equals(obj as Row); public override int GetHashCode() => _fill.FillKey.GetHashCode() ^ _order.Key.GetHashCode(); - static HashSet _properties_for_csv_export = new HashSet(new string[] { - nameof(fill_time), - nameof(time_in_force), - nameof(order_type), - nameof(display_name), - nameof(account), - nameof(user), - nameof(exchange), - nameof(side), - nameof(price), - nameof(size), - nameof(fill_kind), - nameof(fill_status), - nameof(fill_key), - nameof(order_key), - nameof(root_algo_order_type), - nameof(root_algo_display_name) - }); - public static IEnumerable csv_properties => typeof(Row).GetProperties() - .Where(x => _properties_for_csv_export.Contains(x.Name)); + public static System.Collections.Specialized.OrderedDictionary csv_ordered_properties => + CsvHelper.create_ordering_maintainer(typeof(Row), + new string[] { + nameof(security), + nameof(symbol), + nameof(order_type), + nameof(root_algo_display_name), + nameof(side), + nameof(fill_time), + nameof(user), + nameof(account), + nameof(exchange), + nameof(time_in_force), + nameof(size), + nameof(price), + nameof(fill_kind), + nameof(fill_status), + nameof(fill_key), + nameof(order_key), + nameof(security_key) + }); public event Action invalidated; void IRowVM.raise_invalidated() => invalidated?.Invoke(); diff --git a/src/client/spark/Modules/Trading/Fills/FillsWindow.cs b/src/client/spark/Modules/Trading/Fills/FillsWindow.cs index 3d25ba1f0..1d16525cd 100644 --- a/src/client/spark/Modules/Trading/Fills/FillsWindow.cs +++ b/src/client/spark/Modules/Trading/Fills/FillsWindow.cs @@ -3,6 +3,7 @@ using bts.api; using bts.shell; using bts.shell.fills; using bts.spark; +using bts.utils.csv; using mbts.persist; using mbts.ui; using mbts.ui.settings; @@ -59,7 +60,7 @@ namespace mbts.spark { _view = new FillsView { DataContext = _vm }; _commands = new List { - new SparkCommandCommand("Export to csv", Icons.Export, _vm.export_to_csv_command), + new SparkCommandCommand("Export to csv", Icons.Export, FileDialogCommand.export_csv(() => _vm.rows.ToCsv(FillsVM.Row.csv_ordered_properties), "Fills")), // wrap the grid settings view factory in a dialogCommand here since the vm is destroyed/recreated when the security criteria changes SparkCommands.window_settings_command(new DialogCommand(() => { var vm = new ShellSettingsDialogVM( From 25445d58d090d328f8088e8a196b2535d4c08fb7 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Wed, 18 Dec 2019 13:48:14 -0600 Subject: [PATCH 36/36] refactoring TaS CSV export --- .../Market/TimeAndSales/TimeAndSalesVM.cs | 23 ++++++++++--------- .../Market/TimeAndSales/TimeAndSalesWindow.cs | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesVM.cs b/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesVM.cs index ce68f2a9c..fac70916b 100644 --- a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesVM.cs +++ b/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesVM.cs @@ -1,6 +1,7 @@ using bts.api; using bts.co2; using bts.collections; +using bts.utils.csv; using mbts.persist; using mbts.spark.filters; using mbts.ui; @@ -173,17 +174,17 @@ namespace mbts.spark { } } - static HashSet _properties_for_csv_export = new HashSet(new string[] { - nameof(security), - nameof(trade_key), - nameof(time), - nameof(price), - nameof(size), - nameof(aggressor_side), - }); - public static IEnumerable csv_properties => typeof(Row).GetProperties() - .Where(x => _properties_for_csv_export.Contains(x.Name) - ); + public static System.Collections.Specialized.OrderedDictionary csv_ordered_properties => + CsvHelper.create_ordering_maintainer( + typeof(TimeAndSalesVM.Row), + new string[] { + nameof(security), + nameof(time), + nameof(price), + nameof(size), + nameof(aggressor_side), + nameof(security_key), + }); public void raise_invalidated() => invalidated?.Invoke(); diff --git a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesWindow.cs b/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesWindow.cs index d506ddba2..168d47796 100644 --- a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesWindow.cs +++ b/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesWindow.cs @@ -64,7 +64,7 @@ namespace mbts.spark { var current_smd_source = connectable_builder.create(vm => vm.current_security_md_observable(_bus)).OnDispatcher(); var selected_secs_source = connectable_builder.create(vm => vm.selected_securities_observable()).OnDispatcher(); _commands = new SparkCommand[] { - new SparkCommandCommand("Export to csv", Icons.Export, FileDialogCommand.export_csv(() => _vm.value.row_vms.ToCsv(TimeAndSalesVM.Row.csv_properties), "TaS")), + new SparkCommandCommand("Export to csv", Icons.Export, FileDialogCommand.export_csv(() => _vm.value.row_vms.ToCsv(TimeAndSalesVM.Row.csv_ordered_properties), "TaS")), SparkCommands.ShowLadder(SparkCommands.KeyGestures.ShowLadder).complete(current_smd_source, md => md.HasValue, ConvertUtils.ValueOrDefault), SparkCommands.ShowOrderTicketFromSecurity(SparkCommands.KeyGestures.ShowOrderTicket).complete(current_smd_source, md => md.HasValue, ConvertUtils.ValueOrDefault), SparkCommands.ShowFills(SparkCommands.KeyGestures.ShowFills).complete(selected_secs_source, always_true, get_fills_startup_data),