From dfa18c632ec456b5c2d35f71d9cc31fffd3ab66d Mon Sep 17 00:00:00 2001 From: John Colvin Date: Thu, 27 Jan 2022 00:17:36 -0500 Subject: [PATCH 1/5] Add greeks to mview --- .../spark/Analytics/Core/GreeksTuple.cs | 61 +++++++++++++++++++ .../Market/MarketView/MarketViewRow.cs | 56 +++++++++++------ .../Modules/Market/MarketView/MarketViewVM.cs | 24 +++++++- .../Market/MarketView/MarketViewView.xaml.cs | 8 ++- .../MarketView/MarketViewWindowFactory.cs | 13 +++- src/client/spark/core/Bus/SparkTags.cs | 3 + .../Controls/DIYGrid/Columns/ColumnBase.cs | 1 + src/client/spark_core/utils/DoubleHelper.cs | 3 + 8 files changed, 146 insertions(+), 23 deletions(-) create mode 100644 src/client/spark/Analytics/Core/GreeksTuple.cs diff --git a/src/client/spark/Analytics/Core/GreeksTuple.cs b/src/client/spark/Analytics/Core/GreeksTuple.cs new file mode 100644 index 000000000..2efff8880 --- /dev/null +++ b/src/client/spark/Analytics/Core/GreeksTuple.cs @@ -0,0 +1,61 @@ +namespace mbts.analytics { + using System; + + readonly struct GreeksTuple : IEquatable { + public GreeksTuple(double theo, double delta, double gamma, double vega, double theta, double rho) { + this.theo = theo; + this.delta = delta; + this.gamma = gamma; + this.vega = vega; + this.theta = theta; + this.rho = rho; + } + + public static GreeksTuple empty => new(double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN); + + public double theo { get; } + public double delta { get; } + public double gamma { get; } + public double vega { get; } + public double theta { get; } + public double rho { get; } + + public bool Equals(GreeksTuple other) => + theo.Equals(other.theo) && + delta.Equals(other.delta) && + gamma.Equals(other.gamma) && + vega.Equals(other.vega) && + theta.Equals(other.theta) && + rho.Equals(other.rho); + + public override bool Equals(object obj) => + obj is GreeksTuple gt && Equals(gt); + + public override int GetHashCode() => + HashCode.Combine(theo, delta, gamma, vega, theta, rho); + + public override string ToString() => + $"theo: {theo}; delta: {delta}; gamma: {gamma}; vega: {vega}; theta: {theta}; rho: {rho}"; + + public static bool operator ==(GreeksTuple a, GreeksTuple b) => a.Equals(b); + public static bool operator !=(GreeksTuple a, GreeksTuple b) => !a.Equals(b); + } + + static class GreeksTupleExtensions { + public static GreeksTuple with( + this GreeksTuple greeks_tuple, + double theo = double.NaN, + double delta = double.NaN, + double gamma = double.NaN, + double vega = double.NaN, + double theta = double.NaN, + double rho = double.NaN) => + new( + theo.if_nan(greeks_tuple.theo), + delta.if_nan(greeks_tuple.delta), + gamma.if_nan(greeks_tuple.gamma), + vega.if_nan(greeks_tuple.vega), + theta.if_nan(greeks_tuple.theta), + rho.if_nan(greeks_tuple.rho)); + } +} diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs b/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs index 32058895e..ae35bdea7 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs @@ -1,26 +1,27 @@ -using bts.api; -using bts.api.orderman; -using bts.collections; -using bts.utils; +namespace mbts.spark { + using bts.api; + using bts.api.orderman; + using bts.collections; + using bts.utils; -using mbts.co2; -using mbts.spark.utilities; -using mbts.ui; -using mbts.ui.controls; -using mbts.ui.shell; -using mbts.ui.spark; -using mbts.ui.utility; -using mbts.utils; + using mbts.analytics; + using mbts.co2; + using mbts.spark.utilities; + using mbts.ui; + using mbts.ui.controls; + 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.Linq; -using System.Reactive.Linq; -using System.Windows.Input; + using System; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Collections.Specialized; + using System.Linq; + using System.Reactive.Linq; + using System.Windows.Input; -namespace mbts.spark { partial class MarketViewVM { public class Row : DisposableViewModelBase, ISecurityMDRow, IEquatable, DIYGrid.IRowVM, DIYGrid.IActionableRowVM { readonly IBus _bus; @@ -49,6 +50,7 @@ namespace mbts.spark { ulong _bbo_ref, _last_ref; uint? _display_qty_divisor_backing; bool _is_visible; + GreeksTuple _greeks = GreeksTuple.empty; public Row(IBus bus, SecurityMD smd, OrdersModel orders_model) { _bus = bus; @@ -215,6 +217,20 @@ namespace mbts.spark { public string hub_alias => security.hub_alias(); public string strip_name => security.strip_name(); public string mic_code => security.mic_code(); + + // greeks + public GreeksTuple greeks { + get => _greeks; + set => Set(ref _greeks, value, nameof(greeks), + nameof(theo), nameof(delta), nameof(gamma), nameof(vega), nameof(theta), nameof(rho)); + } + public double theo => _greeks.theo; + public double delta => _greeks.delta; + public double gamma => _greeks.gamma; + public double vega => _greeks.vega; + public double theta => _greeks.theta; + public double rho => _greeks.rho; + // animations public IList animations => _animation.get_animations().ToList(); public ObservableCollection row_animations { get; } = new ObservableCollection(); diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs b/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs index cc3166989..15e062a99 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs @@ -158,6 +158,14 @@ namespace mbts.spark { add_col(Columns.StripName, "Strip Name", r => r.security.strip_name(), nameof(Row.strip_name), DefaultColumnWidths.SecurityKey, strip_name_filter, DataGridFilterKnownTemplates.Regex); add_col(Columns.MicCode, "Mic Code", r => r.security.mic_code(), nameof(Row.mic_code), DefaultColumnWidths.SecurityKey, mic_code_filter, DataGridFilterKnownTemplates.Regex); + // greeks + add_col(Columns.Theo, "Theo", r => r.theo.is_nan() ? string.Empty : r.theo.ToString("0.00"), nameof(Row.theo), DefaultColumnWidths.Greeks, theo_filter, DataGridFilterKnownTemplates.DoubleMinMax); + add_col(Columns.Delta, "Delta", r => r.delta.is_nan() ? string.Empty : r.delta.ToString("0.00"), nameof(Row.delta), DefaultColumnWidths.Greeks, delta_filter, DataGridFilterKnownTemplates.DoubleMinMax); + add_col(Columns.Gamma, "Gamma", r => r.gamma.is_nan() ? string.Empty : r.gamma.ToString("0.00"), nameof(Row.gamma), DefaultColumnWidths.Greeks, gamma_filter, DataGridFilterKnownTemplates.DoubleMinMax); + add_col(Columns.Vega, "Vega", r => r.vega.is_nan() ? string.Empty : r.vega.ToString("0.00"), nameof(Row.vega), DefaultColumnWidths.Greeks, vega_filter, DataGridFilterKnownTemplates.DoubleMinMax); + add_col(Columns.Theta, "Theta", r => r.theta.is_nan() ? string.Empty : r.theta.ToString("0.00"), nameof(Row.theta), DefaultColumnWidths.Greeks, theta_filter, DataGridFilterKnownTemplates.DoubleMinMax); + add_col(Columns.Rho, "Rho", r => r.rho.is_nan() ? string.Empty : r.rho.ToString("0.00"), nameof(Row.rho), DefaultColumnWidths.Greeks, rho_filter, DataGridFilterKnownTemplates.DoubleMinMax); + // row vm filter // Althoguh securities are filtered at the row 'model' level (SecurityMD), the column base filters have to be applied at the row vm level, // because they access market data, which is polled periodically and cached in the row vm. @@ -180,6 +188,13 @@ namespace mbts.spark { }), security_mds_source.Subscribe(_on_securities), ObservableAutoWrapper.connect_item_hooks(_rows, r => r, true), + bus.subscribe(SparkTags.Greeks).OnDispatcher().Subscribe(greeks => { + foreach (var r in rows) { + if (greeks.TryGetValue(r.security_key, out var g)) { + r.greeks = g; + } + } + }), WorkLoop.Start("MarketView", _refresh)); // local functions @@ -368,7 +383,7 @@ namespace mbts.spark { public IDataGridColumnPersistentFilter working_ask_volume_filter { get; } = new IntMinMax(r => r.working_ask_volume, nameof(Row.working_ask_volume)); public IDataGridColumnPersistentFilter volume_filter { get; } = new ULongMinMax(r => r.volume, nameof(Row.volume)); public IDataGridColumnPersistentFilter security_key_filter { get; } = new RegexFilterVM(r => r.security_key.ToString(), nameof(Row.security_key)); - + public IDataGridColumnPersistentFilter market_description_filter { get; } = new RegexFilterVM(r => r.security.HasIce ? r.security.Ice.MarketDescription : "", nameof(Row.market_description)); public IDataGridColumnPersistentFilter cleared_alias_filter { get; } = new RegexFilterVM(r => r.security.HasIce ? r.security.Ice.ClearedAlias : "", nameof(Row.cleared_alias)); public IDataGridColumnPersistentFilter product_description_filter { get; } = new RegexFilterVM(r => r.security.HasIce ? r.security.Ice.ProductName : "", nameof(Row.product_description)); @@ -376,6 +391,13 @@ namespace mbts.spark { public IDataGridColumnPersistentFilter strip_name_filter { get; } = new RegexFilterVM(r => r.security.HasIce ? r.security.Ice.StripName : "", nameof(Row.strip_name)); public IDataGridColumnPersistentFilter mic_code_filter { get; } = new RegexFilterVM(r => r.security.HasIce ? r.security.Ice.MicCode : "", nameof(Row.mic_code)); + public IDataGridColumnPersistentFilter theo_filter { get; } = new DoubleMinMax(r => r.theo, nameof(Row.theo)); + public IDataGridColumnPersistentFilter delta_filter { get; } = new DoubleMinMax(r => r.delta, nameof(Row.delta)); + public IDataGridColumnPersistentFilter vega_filter { get; } = new DoubleMinMax(r => r.vega, nameof(Row.vega)); + public IDataGridColumnPersistentFilter gamma_filter { get; } = new DoubleMinMax(r => r.gamma, nameof(Row.gamma)); + public IDataGridColumnPersistentFilter theta_filter { get; } = new DoubleMinMax(r => r.theta, nameof(Row.theta)); + public IDataGridColumnPersistentFilter rho_filter { get; } = new DoubleMinMax(r => r.rho, nameof(Row.rho)); + IEnumerable> _all_filters => _filter_getters.Select(g => g(this)); diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewView.xaml.cs b/src/client/spark/Modules/Market/MarketView/MarketViewView.xaml.cs index c6a19a17b..79967ceda 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewView.xaml.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewView.xaml.cs @@ -61,7 +61,13 @@ namespace mbts.ui.spark { ProductDescription, HubAlias, StripName, - MicCode + MicCode, + Theo, + Delta, + Gamma, + Vega, + Theta, + Rho } public static ExecutedRoutedEventHandler diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs b/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs index 05f6a88d3..cb79af1ed 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs @@ -147,7 +147,12 @@ namespace bts.shell { public static GridColumnSettings strip_name => new GridColumnSettings(col_id(Columns.StripName), DefaultColumnHeaders.StripName, is_visible: false, width: DefaultColumnWidths.SecurityKey); public static GridColumnSettings mic_code => new GridColumnSettings(col_id(Columns.MicCode), DefaultColumnHeaders.MicCode, is_visible: false, width: DefaultColumnWidths.SecurityKey); - + public static GridColumnSettings theo => new(col_id(Columns.Theo), "Theo", is_visible: false, width: DefaultColumnWidths.Greeks); + public static GridColumnSettings delta => new(col_id(Columns.Delta), "Delta", is_visible: false, width: DefaultColumnWidths.Greeks); + public static GridColumnSettings gamma => new(col_id(Columns.Gamma), "Gamma", is_visible: false, width: DefaultColumnWidths.Greeks); + public static GridColumnSettings vega => new(col_id(Columns.Vega), "Vega", is_visible: false, width: DefaultColumnWidths.Greeks); + public static GridColumnSettings theta => new(col_id(Columns.Theta), "Theta", is_visible: false, width: DefaultColumnWidths.Greeks); + public static GridColumnSettings rho => new(col_id(Columns.Rho), "Rho", is_visible: false, width: DefaultColumnWidths.Greeks); public static IEnumerable default_sorting_criterion { get { @@ -185,6 +190,12 @@ namespace bts.shell { yield return hub_alias; yield return strip_name; yield return mic_code; + yield return theo; + yield return delta; + yield return gamma; + yield return vega; + yield return theta; + yield return rho; } } diff --git a/src/client/spark/core/Bus/SparkTags.cs b/src/client/spark/core/Bus/SparkTags.cs index 7a09a0c23..6a7a387e5 100644 --- a/src/client/spark/core/Bus/SparkTags.cs +++ b/src/client/spark/core/Bus/SparkTags.cs @@ -306,6 +306,9 @@ namespace mbts.spark { public static ITag show_analytics_exp_params { get; } = new SparkTag("Show Analytics Exp Params"); + + public static ITag> Greeks { get; } = + new SparkTag>("Greeks"); #endregion public static ITag> SyntheticDeleteTag { get; } = new SparkTag>(nameof(SyntheticDeleteTag)); diff --git a/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs b/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs index 50d3c60c1..7aa569933 100644 --- a/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs +++ b/src/client/spark/view/Controls/DIYGrid/Columns/ColumnBase.cs @@ -29,6 +29,7 @@ namespace mbts.ui.controls { AveragePrice = 76, LastPrice = 78, Settlement = 82, + Greeks = 56, Security = 80, SecurityKey = 90, SecurityType = 96, diff --git a/src/client/spark_core/utils/DoubleHelper.cs b/src/client/spark_core/utils/DoubleHelper.cs index c9cfbc515..362f87d76 100644 --- a/src/client/spark_core/utils/DoubleHelper.cs +++ b/src/client/spark_core/utils/DoubleHelper.cs @@ -18,6 +18,9 @@ namespace mbts { public static bool is_nan(this double value) => double.IsNaN(value); + public static double if_nan(this double d, double if_nan) => + d.is_nan() ? if_nan : d; + /// /// If the specified value is a , , or , returns the equivalent ; otherwise, returns . /// From 2fdce0280ad191ba0333bd9d3cba380e8a25dfc3 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Thu, 27 Jan 2022 11:52:29 -0500 Subject: [PATCH 2/5] refactor: Clean up MarketViewRow * Define fields of the same type in separate statements * Insert some new lines for easier code browsing * Replace large delegates with local fns --- .../Market/MarketView/MarketViewRow.cs | 138 ++++++++++-------- 1 file changed, 78 insertions(+), 60 deletions(-) diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs b/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs index ae35bdea7..f5350101e 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs @@ -1,6 +1,8 @@ namespace mbts.spark { using bts.api; + using bts.api.core; using bts.api.orderman; + using bts.api.position; using bts.collections; using bts.utils; @@ -26,27 +28,38 @@ public class Row : DisposableViewModelBase, ISecurityMDRow, IEquatable, DIYGrid.IRowVM, DIYGrid.IActionableRowVM { readonly IBus _bus; readonly OrdersModel _orders_model; - readonly AnimationManager _animation = new AnimationManager(); - readonly ObservableCollection _orders = new ObservableCollection(); - readonly ObservableFilterCollection _working_orders, _working_bids, _working_asks; - readonly Property _bid_price, _ask_price, _last_price, _day_change, _settlement, _session_high, _session_low; + readonly AnimationManager _animation = new(); + readonly ObservableCollection _orders = new(); + readonly ObservableFilterCollection _working_orders; + readonly ObservableFilterCollection _working_bids; + readonly ObservableFilterCollection _working_asks; + readonly Property _bid_price; + readonly Property _ask_price; + readonly Property _last_price; + readonly Property _day_change; + readonly Property _settlement; + readonly Property _session_high; + readonly Property _session_low; readonly Property _last_price_from_spread; readonly CellProperty _day_position; readonly CellProperty _raw_day_position; readonly CellProperty _last_size; readonly CellProperty _volume; - readonly CellProperty _inside_bids, _inside_asks; - readonly CellProperty _working_bid_volume, _working_ask_volume; - readonly CellProperty _working_best_bid, _working_best_ask; - readonly MyOrderSummarizer _order_summarizer = new MyOrderSummarizer(); - readonly MDDisplayHelper.SizeFormatter _size_formatter = MDDisplayHelper.get_formatter(MarketSizeDisplay.get_default()); - PropertyAutoWrapper - _bid_direct_size, - _bid_implied_size, - _bid_merged_size, - _ask_direct_size, - _ask_implied_size, - _ask_merged_size; + readonly CellProperty _inside_bids; + readonly CellProperty _inside_asks; + readonly CellProperty _working_bid_volume; + readonly CellProperty _working_ask_volume; + readonly CellProperty _working_best_bid; + readonly CellProperty _working_best_ask; + readonly MyOrderSummarizer _order_summarizer = new(); + + readonly PropertyAutoWrapper _bid_direct_size; + readonly PropertyAutoWrapper _bid_implied_size; + readonly PropertyAutoWrapper _bid_merged_size; + readonly PropertyAutoWrapper _ask_direct_size; + readonly PropertyAutoWrapper _ask_implied_size; + readonly PropertyAutoWrapper _ask_merged_size; + ulong _bbo_ref, _last_ref; uint? _display_qty_divisor_backing; bool _is_visible; @@ -99,7 +112,6 @@ ask_implied_size_click = new DelegateCommand(() => _show_order_ticket(MarketViewView.Columns.AskImpliedSize)); working_asks_click = new DelegateCommand(() => _show_order_book(MarketViewView.Columns.WorkingAsks)); _animation.AnimationsChanged += on_animations_changed; - void on_animations_changed() => RaisePropertyChanged(nameof(animations)); _dispose = Disposable.Create( attach_prop_changed_cb(_bid_direct_size, mk_echo_prop_changed_cb<(uint, uint)>(nameof(bid_direct_size_text))), attach_prop_changed_cb(_bid_implied_size, mk_echo_prop_changed_cb<(uint, uint)>(nameof(bid_implied_size_text))), @@ -107,25 +119,14 @@ attach_prop_changed_cb(_ask_direct_size, mk_echo_prop_changed_cb<(uint, uint)>(nameof(ask_direct_size_text))), attach_prop_changed_cb(_ask_implied_size, mk_echo_prop_changed_cb<(uint, uint)>(nameof(ask_implied_size_text))), attach_prop_changed_cb(_ask_merged_size, mk_echo_prop_changed_cb<(uint, uint)>(nameof(ask_merged_size_text))), - _orders_model.on_security_root_orders(security.Id).OnDispatcher().Subscribe(_on_orders), - _orders_model.on_security_positions(security.Id).OnDispatcher().Subscribe(t => { - var new_day_pos = t.state.Values.Sum(p => p.Item2.day_pos()); - bool day_pos_dirty = _day_position.on_next_distinct(new_day_pos); - if (day_pos_dirty) { - if (!new_day_pos.is_nan() && !day_position.is_nan()) { - _animation.animate_position(new_day_pos > _day_position.value); - } - } - bool raw_day_pos_dirty = _raw_day_position.on_next_distinct(t.state.Values.Sum(p => p.Item2.raw_day_pos())); - if (day_pos_dirty || raw_day_pos_dirty) { - raise_invalidated(); - } - }), + _orders_model.on_security_root_orders(security.Id).OnDispatcher().Subscribe(on_orders), + _orders_model.on_security_positions(security.Id).OnDispatcher().Subscribe(on_security_positions), _inside_bids.OnDispatcher().Subscribe(v => _animation.animate_working_bids_inside(v.newval)), _inside_asks.OnDispatcher().Subscribe(v => _animation.animate_working_asks_inside(v.newval)), _day_change.OnDispatcher().Subscribe(v => _animation.animate_day_change(v.newval > v.oldval)), - Disposable.Create(() => _animation.AnimationsChanged -= on_animations_changed) - ); + Disposable.Create(() => _animation.AnimationsChanged -= on_animations_changed)); + + void on_animations_changed() => RaisePropertyChanged(nameof(animations)); uint convert_display_qty_uint(uint value) => value.safe_divide(_display_qty_divisor); @@ -139,6 +140,32 @@ string fmt_display_qty_double(double value) => value.safe_divide(_display_qty_divisor).ToString(); + void on_orders(ITableUpdateTransform orders) { + foreach (var o in orders.removed) { + _order_summarizer.remove_order(o); + } + foreach (var o in orders.added) { + _order_summarizer.add_order(o); + } + bool dirty = false; + _refresh_orders(ref dirty); + if (dirty) + invalidated?.Invoke(); + } + + void on_security_positions(TableUpdate<(SecurityImmutable? sec, PositionUnitImmutable pos), int> table) { + var new_day_pos = table.state.Values.Sum(p => p.pos.day_pos()); + bool day_pos_dirty = _day_position.on_next_distinct(new_day_pos); + if (day_pos_dirty && !new_day_pos.is_nan() && !day_position.is_nan()) { + _animation.animate_position(new_day_pos > _day_position.value); + } + bool raw_day_pos_dirty = _raw_day_position.on_next_distinct( + table.state.Values.Sum(p => p.pos.raw_day_pos())); + if (day_pos_dirty || raw_day_pos_dirty) { + raise_invalidated(); + } + } + PropertyChange mk_echo_prop_changed_cb(params string[] props) => (oldval, newval) => RaisePropertyChanged(props); @@ -150,17 +177,12 @@ public event Action invalidated; + // security public SecurityMD security_md { get; } public SecurityImmutable security => security_md.security; public uint security_key => security_md.security.Id; SecurityMD ISecurityMDRow.md => security_md; - public bool is_visible { - get => _is_visible; - set => Set(ref _is_visible, value); - } - - #region Bound Properties public bool inside_bids => _inside_bids.value; public bool inside_asks => _inside_asks.value; public double day_position => _day_position.value; @@ -171,25 +193,29 @@ public bool last_price_from_spread => _last_price_from_spread.Value; public uint last_size => _last_size.value; public string last_size_text => _last_size.text; + // bid price/size public double bid_price => _bid_price.Value; public uint bid_direct_size => _bid_direct_size.model; public uint bid_implied_size => _bid_merged_size.model - _bid_direct_size.model; public uint bid_merged_size => _bid_merged_size.model; + // bid size text public string bid_direct_size_text => _bid_direct_size.view.ToString(); public string bid_implied_size_text => _bid_implied_size.view.ToString(); public string bid_merged_size_text => _bid_merged_size.view.ToString(); + // ask price/size public double ask_price => _ask_price.Value; public uint ask_direct_size => _ask_direct_size.model; public uint ask_implied_size => _ask_implied_size.model; public uint ask_merged_size => _ask_merged_size.model; + // ask size text public string ask_direct_size_text => _ask_direct_size.view.ToString(); public string ask_implied_size_text => _ask_implied_size.view.ToString(); public string ask_merged_size_text => _ask_merged_size.view.ToString(); - // + public ulong volume => _volume.value; public string volume_text => _volume.text; public double settlement => _settlement.Value; @@ -210,7 +236,8 @@ security.ContractSpec); public double working_best_bid => _working_best_bid.value; public double working_best_ask => _working_best_ask.value; - // ice props + + // ice public string market_description => security.market_description(); public string cleared_alias => security.cleared_alias(); public string product_description => security.product_name(); @@ -234,6 +261,12 @@ // animations public IList animations => _animation.get_animations().ToList(); public ObservableCollection row_animations { get; } = new ObservableCollection(); + + public bool is_visible { + get => _is_visible; + set => Set(ref _is_visible, value); + } + // commands public ICommand bid_price_click { get; } public ICommand bid_merged_size_click { get; } @@ -247,9 +280,6 @@ public ICommand working_asks_click { get; } public ICommand default_command { get; } - public IReadOnlyList cell_stores => new DIYGrid.IGridCellStore[0]; - #endregion - uint _display_qty_divisor => _display_qty_divisor_backing ?? (_display_qty_divisor_backing = _orders_model.security_auxiliary_model.get_display_quantity_divisor(security)).Value; IMDConsumerHandle _md => security_md.md; @@ -273,19 +303,22 @@ _ask_price.set(a.price); _refresh_inside_working_orers(ref dirty); } + if (_md.get_last_trade(ref _last_ref, out NativePriceSize ps, out DateTime ts, out ulong v, out bool from_spread)) { _last_price.set(ps.price); _last_price_from_spread.set(from_spread); _last_size.on_next_distinct(ps.size, ref dirty); _volume.on_next_distinct(v, ref dirty); } + dirty |= _settlement.set_new(_md.settlement_price) | _session_low.set_new(_md.session_low) | _session_high.set_new(_md.session_high) | _day_change.set_new(last_price - settlement); - if (dirty) + if (dirty) { invalidated?.Invoke(); + } } public bool Equals(Row other) => @@ -298,7 +331,6 @@ public override int GetHashCode() => security_key.GetHashCode(); - #region Show Windows void _show_ladder() => _bus.post(SparkTags.ShowLadderTag, security_md); void _show_order_book(MarketViewView.Columns col) { @@ -353,19 +385,6 @@ break; } } - #endregion - - #region Callbacks - void _on_orders(ITableUpdateTransform orders) { - foreach (var o in orders.removed) - _order_summarizer.remove_order(o); - foreach (var o in orders.added) - _order_summarizer.add_order(o); - bool dirty = false; - _refresh_orders(ref dirty); - if (dirty) - invalidated?.Invoke(); - } void _refresh_orders(ref bool dirty) { _working_bid_volume.on_next_distinct(_order_summarizer.working_bid_qty, ref dirty); @@ -387,7 +406,6 @@ _inside_bids.on_next_distinct(!double.IsNaN(working_best_bid) && OrderDataHelper.PriceComparer.Compare(working_best_bid, bid_price) >= 0, ref dirty); _inside_asks.on_next_distinct(!double.IsNaN(working_best_ask) && OrderDataHelper.PriceComparer.Compare(working_best_ask, ask_price) <= 0, ref dirty); } - #endregion class MyOrderSummarizer { SortedSetMap _bids, _asks; From 6c6bf492b00a7828569caf45c458ba25413334f4 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Thu, 27 Jan 2022 11:56:43 -0500 Subject: [PATCH 3/5] fix: Show candidate output in vs grid readonly cells --- src/client/spark/AW2/ViewModel/Grid/VolSurfaceColumn.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/spark/AW2/ViewModel/Grid/VolSurfaceColumn.cs b/src/client/spark/AW2/ViewModel/Grid/VolSurfaceColumn.cs index d246b6bf7..1afebd397 100644 --- a/src/client/spark/AW2/ViewModel/Grid/VolSurfaceColumn.cs +++ b/src/client/spark/AW2/ViewModel/Grid/VolSurfaceColumn.cs @@ -48,7 +48,7 @@ namespace mbts.spark.VolSurface { view.SetBinding(FrameworkElement.DataContextProperty, new Binding() { Converter = _data_context_converter }); - view.SetBinding(TextBlock.TextProperty, new Binding(nameof(VolGridCellVM.committed_value)) { + view.SetBinding(TextBlock.TextProperty, new Binding(nameof(VolGridCellVM.candidate_value)) { Converter = ValueConverter.create(volsurface_column.format) }); return view; From 95f638175d0db5cca07dba133a85580927444fa8 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Thu, 27 Jan 2022 12:51:33 -0500 Subject: [PATCH 4/5] refactor: Use 'is null' in null asserts, add msg param --- src/client/spark_api/utils/Log.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/client/spark_api/utils/Log.cs b/src/client/spark_api/utils/Log.cs index b5d6a7073..3f3e91bc4 100644 --- a/src/client/spark_api/utils/Log.cs +++ b/src/client/spark_api/utils/Log.cs @@ -134,12 +134,13 @@ namespace bts { Environment.Exit(-1); } } - public static void notnull(T o) where T : class { - assert(o != null); - } - public static void isnull(T o) where T : class { - assert(o == null); - } + + public static void notnull(T obj, string msg = "") where T : class => + assert(obj is not null, msg); + + public static void isnull(T obj, string msg = "") where T : class => + assert(obj is null, msg); + delegate void on_crash_callback([MarshalAs(UnmanagedType.LPStr)]string msg, [MarshalAs(UnmanagedType.LPStr)] string details); internal static void system_is_crashing(string message, object details) { OnSystemCrashing?.Invoke(message, details); From 39d7ab0b76b6419c164aeae66bd8fa3a218b4e25 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Thu, 27 Jan 2022 12:56:05 -0500 Subject: [PATCH 5/5] fix: Remove bad assert statement in SparkWindow Bugs (fixed): * PNL window crashes on open --- src/client/spark/view/Spark/SparkWindow.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/client/spark/view/Spark/SparkWindow.cs b/src/client/spark/view/Spark/SparkWindow.cs index 9a0773af4..1b862778e 100644 --- a/src/client/spark/view/Spark/SparkWindow.cs +++ b/src/client/spark/view/Spark/SparkWindow.cs @@ -193,9 +193,8 @@ namespace bts.spark { public string thread_id { get; } public void thread_init() { - Log.assert(_thread_init != null, "Thread init has already been executed."); + Log.notnull(_thread_init, "Thread init has already been executed."); (_content, _commands, _get_save_state, _ui_thread_dispose) = _thread_init(); - Log.isnull(_ui_thread_dispose); _thread_init = null; }