diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs b/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs index 73a84082c..e4e5e6e9b 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs @@ -45,28 +45,28 @@ namespace mbts.spark { _security_text = smd.security.ToString(); _security_key_text = security_key.ToString(); string format_price(double price) => security.ContractSpec.format(price); - _position = new CellProperty(0); + _position = new CellProperty(this, nameof(position), 0); _bid_price = backing(nameof(bid_price), double.NaN); _ask_price = backing(nameof(ask_price), double.NaN); _last_price = backing(nameof(last_price), double.NaN); - _last_size = new CellProperty(0); + _last_size = new CellProperty(this, nameof(last_size), 0); _day_change = backing(nameof(day_change), double.NaN); _session_low = backing(nameof(session_low), double.NaN); _session_high = backing(nameof(session_high), double.NaN); _settlement = backing(nameof(settlement), double.NaN); - _volume = new CellProperty(0); - _inside_bids = new CellProperty(); - _inside_asks = new CellProperty(); - _working_bid_volume = new CellProperty(); - _working_ask_volume = new CellProperty(); + _volume = new CellProperty(this, nameof(volume), 0); + _inside_bids = new CellProperty(this, nameof(inside_bids)); + _inside_asks = new CellProperty(this, nameof(inside_asks)); + _working_bid_volume = new CellProperty(this, nameof(working_bid_volume)); + _working_ask_volume = new CellProperty(this, nameof(working_ask_volume)); // _working_orders = new ObservableFilterCollection(_orders, o => o.is_active()); _working_bids = new ObservableFilterCollection(_working_orders, o => o.Def.Side == Side.Buy); _working_asks = new ObservableFilterCollection(_working_orders, o => o.Def.Side == Side.Sell); - _working_best_bid = new CellProperty(format_price, double.NaN); - _working_best_ask = new CellProperty(format_price, double.NaN); - _working_bids_text = new CellProperty(string.Empty); - _working_asks_text = new CellProperty(string.Empty); + _working_best_bid = new CellProperty(this, nameof(working_best_bid), format_price, double.NaN); + _working_best_ask = new CellProperty(this, nameof(working_best_ask), format_price, double.NaN); + _working_bids_text = new CellProperty(this, nameof(working_bids_text), string.Empty); + _working_asks_text = new CellProperty(this, nameof(working_asks_text), string.Empty); // default_command = new DelegateCommand(_show_ladder); bid_price_click = new DelegateCommand(() => _show_order_ticket(MarketViewView.Columns.Bid)); @@ -267,17 +267,17 @@ namespace mbts.spark { _inside_bids.on_next_distinct(_order_summarizer.best_working_bid >= bid_price, ref dirty); _inside_asks.on_next_distinct(_order_summarizer.best_working_ask <= ask_price, ref dirty); - // Here we need to RaisePropertyChanged for the non-Property<> cols that are bound to a filter - // (Property implements INotifyPropretyChanged, so this is taken for us autmagically) + // Here we need to RaisePropertyChanged for the non-Property/CellProperty<> cols that are bound to a filter + // (Property and CellProperty implement INotifyPropretyChanged and/or IRaiseNotifyPropertyChanged, so this is taken care of for us autmagically) // This is so that when the data changes behind the filter, the filter runs again for evaulation // on whether to show or hide the row RaisePropertyChanged( nameof(security), - nameof(volume), + // volume is a CellProperty<> // last price is a Property<> - nameof(last_size), - nameof(position), - nameof(working_bid_volume), + // last_size is a CellProperty<> + // position is a CellProperty<> + // working_bid_volume is a CellProperty<> nameof(bid_implied_size), nameof(bid_direct_size), nameof(bid_merged_size), @@ -286,7 +286,7 @@ namespace mbts.spark { nameof(ask_merged_size), nameof(ask_direct_size), nameof(ask_implied_size), - nameof(working_ask_volume), + // working_ask_volume is a CellProperty // setlltement is a Property<> // change is a Property<> // low is a Property<> diff --git a/src/client/spark/view/Controls/DIYGrid/CellProperty.cs b/src/client/spark/view/Controls/DIYGrid/CellProperty.cs index 758d0474d..754ee552d 100644 --- a/src/client/spark/view/Controls/DIYGrid/CellProperty.cs +++ b/src/client/spark/view/Controls/DIYGrid/CellProperty.cs @@ -1,16 +1,21 @@ -using System; +using mbts.ui.shell; +using System; using System.Reactive.Linq; using System.Reactive.Subjects; namespace mbts.spark { class CellProperty : ISubject { readonly Func _format; + readonly IRaiseNotifyPropertyChanged _owner; + readonly string _prop_name; string _text; - public CellProperty(T initial_value = default) - : this(t => t.ToString(), initial_value) { } + public CellProperty(IRaiseNotifyPropertyChanged owner, string prop_name, T initial_value = default) + : this(owner, prop_name, t => t.ToString(), initial_value) { } - public CellProperty(Func format, T initial_value = default) { + public CellProperty(IRaiseNotifyPropertyChanged owner, string prop_name, Func format, T initial_value = default) { + _owner = owner; + _prop_name = prop_name; _format = format; value = initial_value; } @@ -24,6 +29,7 @@ namespace mbts.spark { if (!value.Equals(this.value)) { OnNext(value); dirty = true; + _owner.raise_notify_property_changed(_prop_name); } } diff --git a/src/client/spark/view/Spark/PAndL/PnLSummaryRow.cs b/src/client/spark/view/Spark/PAndL/PnLSummaryRow.cs index c571fbd3b..a107179d3 100644 --- a/src/client/spark/view/Spark/PAndL/PnLSummaryRow.cs +++ b/src/client/spark/view/Spark/PAndL/PnLSummaryRow.cs @@ -15,7 +15,7 @@ namespace mbts.spark { class PnLSummaryRow : ViewModelBase, IEquatable, DIYGrid.IRowVM { static readonly SignedDataStore _brushes; readonly PnLDoubleBrushCell _start_pnl, _day_pnl, _total_pnl; - readonly PnLPriceCell _pnl_price, _weighted_average_buy, _weighted_average_sell; + readonly CellProperty _pnl_price, _weighted_average_buy, _weighted_average_sell; (string account, Venue? exchange, string symbol, SecurityImmutable? security, SecurityMD? sec_md, SecurityType? sec_type) key; IEnumerable _fills; double _driver; @@ -38,9 +38,9 @@ namespace mbts.spark { day_short_quantity = day_sell_quant; total_net_position = net_pos; start_net_position = sod_pos; - _pnl_price = new PnLPriceCell(this, nameof(pnl_price)); - _weighted_average_buy = new PnLPriceCell(this, nameof(weighted_average_buy), wavg_buy); - _weighted_average_sell = new PnLPriceCell(this, nameof(weighted_average_sell), wavg_sell); + _pnl_price = new CellProperty(this, nameof(pnl_price), price => this.security.spec_or_default().format(price), 0); + _weighted_average_buy = new CellProperty(this, nameof(weighted_average_buy), price => this.security.spec_or_default().format(price), wavg_buy); + _weighted_average_sell = new CellProperty(this, nameof(weighted_average_sell), price => this.security.spec_or_default().format(price), wavg_sell); _fills = fills; // set the initial pnl and pnl_price when there has been a @@ -193,10 +193,9 @@ namespace mbts.spark { class PnLDoubleBrushCell : CellProperty { Brush _background; - public PnLDoubleBrushCell(PnLSummaryRow owner, string prop) : base(d => double.IsNaN(d) ? string.Empty : d.ToString("N2"), double.NaN) => + public PnLDoubleBrushCell(PnLSummaryRow owner, string prop) : base(owner, prop, d => double.IsNaN(d) ? string.Empty : d.ToString("N2"), double.NaN) => _value_set += _ => { _background = null; - owner.RaisePropertyChanged(prop); }; public Brush background => _background ?? (_background = _brushes.get(value)); @@ -204,8 +203,7 @@ namespace mbts.spark { class PnLPriceCell : CellProperty { public PnLPriceCell(PnLSummaryRow owner, string prop, double init = 0) - : base(price => owner.security.spec_or_default().format(price), init) => - _value_set += _ => owner.RaisePropertyChanged(prop); + : base(owner, prop, price => owner.security.spec_or_default().format(price), init) { } } } } \ No newline at end of file