diff --git a/src/client/spark/Modules/Trading/PNL/VM/PNLRowVM.cs b/src/client/spark/Modules/Trading/PNL/VM/PNLRowVM.cs index fabc674b8..0558a5994 100644 --- a/src/client/spark/Modules/Trading/PNL/VM/PNLRowVM.cs +++ b/src/client/spark/Modules/Trading/PNL/VM/PNLRowVM.cs @@ -22,7 +22,13 @@ namespace bts.shell.pnl { bool _refresh_normalized_data = true, _is_selected; PNLNormalizedData _normalized_data; - public PNLRowVM(PNLRowData data, ImmutableDictionary default_appearances, IReadOnlyList> triggers) { + public PNLRowVM( + PNLRowData data, + ImmutableDictionary default_appearances, + IReadOnlyList> triggers, + Func fmt_fill_price, + Func fmt_market_price) { + // this.data = data; _animator = new PNLCellEmbeddedAnimationModel(default_appearances, triggers); _animator.on_row(data); @@ -73,6 +79,7 @@ namespace bts.shell.pnl { last_price = _cell_map.add_price_double(ColumnKeys.LastPrice, d => d.last_price); settlement_price = _cell_map.add_price_double(ColumnKeys.SettlementPrice, d => d.settlement_price); + _set_price_formatting_delegates(fmt_fill_price, fmt_market_price); _cell_map.on_row(data); _cell_map.set_appearances(_animator.cell_appearances); _dispose = _cell_map.animation_model.OnDispatcher().Subscribe(new_animations => { @@ -231,15 +238,10 @@ namespace bts.shell.pnl { _cell_map.set_appearances(_animator.cell_appearances); } - public void on_settings(ImmutableDictionary defaults, IReadOnlyList> triggers, Func fmt_market_price, Func fmt_fill_price) { + public void on_settings(ImmutableDictionary defaults, IReadOnlyList> triggers, Func fmt_fill_price, Func fmt_market_price) { _animator.on_settings(defaults, triggers); _cell_map.set_appearances(_animator.cell_appearances); - foreach (var cell in _market_price_cells) { - cell.format = fmt_market_price; - } - foreach (var cell in _fill_price_cells) { - cell.format = fmt_fill_price; - } + _set_price_formatting_delegates(fmt_fill_price, fmt_market_price); } public bool Equals(PNLRowVM other) => @@ -250,5 +252,14 @@ namespace bts.shell.pnl { public override string ToString() => $"account: {account_name} exchange: {exchange} symbol: {symbol} security: {security} buy_quantity: {day_long_pos} sell_quantity: {day_short_pos} pnl: {total_pnl}"; + + void _set_price_formatting_delegates(Func fmt_fill_price, Func fmt_market_price) { + foreach (var cell in _fill_price_cells) { + cell.format = fmt_fill_price; + } + foreach (var cell in _market_price_cells) { + cell.format = fmt_market_price; + } + } } } diff --git a/src/client/spark/Modules/Trading/PNL/VM/PNLVM.cs b/src/client/spark/Modules/Trading/PNL/VM/PNLVM.cs index ab2622cae..e443df017 100644 --- a/src/client/spark/Modules/Trading/PNL/VM/PNLVM.cs +++ b/src/client/spark/Modules/Trading/PNL/VM/PNLVM.cs @@ -41,6 +41,9 @@ namespace bts.shell.pnl { readonly IBus _bus; readonly OrdersModel _orders_model; readonly IObservableCollectionAddRemoveOnly _selected_rows = new ObservableSortedCollection(PNLRowVM.key_comparer); + /// treat and + /// as IReadOnlyLists - don't call any mutation methods. + /// The only reason they are ILists is for the binary_search methods. readonly IList _rows_data_wrapper; readonly IList _rows_key_wrapper; readonly DeferrableActionWrapper _refresh_filter; @@ -51,6 +54,7 @@ namespace bts.shell.pnl { IReadOnlyList<(ColumnKeys key, ListSortDirection direction)> _sorting_hierarchy; Brush _selection_highlight; Color _grid_background_color = Colors.Transparent; + Func _fmt_fill_price_backing, _fmt_market_price_backing; bool _is_paused; // default appearances ImmutableDictionary @@ -74,7 +78,7 @@ namespace bts.shell.pnl { PNLVM(IBus bus, OrdersModel orders_model, PNLSettings settings, IObservable> pnl_source) { _bus = bus; _orders_model = orders_model; - _rows_data_wrapper = rows.WrapSelector(r => r.data, d => new PNLRowVM(d, _default_appearances, _triggers)); + _rows_data_wrapper = rows.WrapSelector(r => r.data, null); _rows_key_wrapper = rows.WrapSelector(r => r.key, null); _rows_view = new PNLRowCollectionView(rows, _default_group_appearances, _group_triggers); _calculation_type = backing(nameof(calculation_type), PNLCalculationType.Waterfall); @@ -244,6 +248,15 @@ namespace bts.shell.pnl { IEnumerable> _all_filters => _filter_getters.Select(get => get(this)); + Func _fmt_fill_price { + get => _fmt_fill_price_backing ?? FormattingDelegates.Price.Value; + set => _fmt_fill_price_backing = value; + } + Func _fmt_market_price { + get => _fmt_market_price_backing ?? FormattingDelegates.Price.Value; + set => _fmt_market_price_backing = value; + } + public static IComparer get_column_comparer(ColumnKeys column) => _get_column_comparer(column).row_comparer; @@ -366,10 +379,10 @@ namespace bts.shell.pnl { _triggers = settings.triggers(); _group_triggers = settings.group_triggers(); _header_triggers = settings.header_triggers(); - var fmt_market_price = settings.data_formatting?.market_price_display?.get_formatting_delegate(); - var fmt_fill_price = settings.data_formatting?.fill_price_display?.get_formatting_delegate(); + _fmt_fill_price = settings.data_formatting?.fill_price_display?.get_formatting_delegate(); + _fmt_market_price = settings.data_formatting?.market_price_display?.get_formatting_delegate(); foreach (var r in rows) - r.on_settings(_default_appearances, _triggers, fmt_market_price, fmt_fill_price); + r.on_settings(_default_appearances, _triggers, _fmt_fill_price, _fmt_market_price); total_aggregate.on_settings(settings.header_background_color, _default_header_appearances, _header_triggers); selected_aggregate.on_settings(settings.header_background_color,_default_header_appearances, _header_triggers); void map_appearances(ref ImmutableDictionary from, IEnumerable col_settings, PNLCellAppearance fallback_appearance) { @@ -753,7 +766,7 @@ namespace bts.shell.pnl { } } foreach (var v in filtered.added) { - var r = new PNLRowVM(v.with(calc_type: calculation_type), _default_appearances, _triggers); + var r = new PNLRowVM(v.with(calc_type: calculation_type), _default_appearances, _triggers, _fmt_fill_price, _fmt_market_price); rows.InsertSorted(r, PNLRowVM.key_comparer); total_pnl += r.normalized_data; }