diff --git a/src/client/spark/Modules/Trading/OrderBook/OrderBookRowVM.cs b/src/client/spark/Modules/Trading/OrderBook/OrderBookRowVM.cs index 02bd76fbf..557a5d052 100644 --- a/src/client/spark/Modules/Trading/OrderBook/OrderBookRowVM.cs +++ b/src/client/spark/Modules/Trading/OrderBook/OrderBookRowVM.cs @@ -31,29 +31,65 @@ namespace mbts.spark { OrderBookRowVM _parent; OrderBookVM.BranchFilterSource _branch_filter_source; // Core - IOrderBookCellStore _order_key_store; - IOrderBookCellStore _parent_order_key_store; - IOrderBookCellStore _security_key_store; - IOrderBookCellStore _security_store; - IOrderBookCellStore _exchange_store; - IOrderBookCellStore _symbol_store; + IOrderBookCellStore _order_key_store_backing; + IOrderBookCellStore _parent_order_key_store_backing; + IOrderBookCellStore _security_key_store_backing; + IOrderBookCellStore _security_store_backing; + IOrderBookCellStore _exchange_store_backing; + IOrderBookCellStore _symbol_store_backing; // Def - IOrderBookCellStore _order_type_store; - IOrderBookCellStore _side_store; - IOrderBookCellStore _user_store; - IOrderBookCellStore _account_store; - IOrderBookCellStore _time_in_force_store; - IOrderBookCellStore _time_created_store; + IOrderBookCellStore _order_type_store_backing; + IOrderBookCellStore _side_store_backing; + IOrderBookCellStore _user_store_backing; + IOrderBookCellStore _account_store_backing; + IOrderBookCellStore _time_in_force_store_backing; + IOrderBookCellStore _time_created_store_backing; // State - IOrderBookCellStore _last_change_store; - IOrderBookCellStore _status_store; - IOrderBookCellStore _price_store; - IOrderBookCellStore _quantity_store; - IOrderBookCellStore _filled_quantity_store; - IOrderBookCellStore _last_price_store; - IOrderBookCellStore _avg_price_store; - IOrderBookCellStore _last_msg_store; - IOrderBookCellStore _order_sub_type_store; + IOrderBookCellStore _last_change_store_backing; + IOrderBookCellStore _status_store_backing; + IOrderBookCellStore _price_store_backing; + IOrderBookCellStore _quantity_store_backing; + IOrderBookCellStore _filled_quantity_store_backing; + IOrderBookCellStore _last_price_store_backing; + IOrderBookCellStore _avg_price_store_backing; + IOrderBookCellStore _last_msg_store_backing; + IOrderBookCellStore _order_sub_type_store_backing; + // Core + IOrderBookCellStore _order_key_store => _order_key_store_backing ?? (_order_key_store_backing = CellFactory.create(this, _book_vm.columns.order_key_column, nameof(order_key), r => r._order.Key, r => r._order_key_store)); + IOrderBookCellStore _parent_order_key_store => _parent_order_key_store_backing ?? (_parent_order_key_store_backing = CellFactory.create(this, _book_vm.columns.parent_key_column, nameof(parent_order_key), r => r._order.ParentKey, r => r._parent_order_key_store)); + IOrderBookCellStore _security_key_store => _security_key_store_backing ?? (_security_key_store_backing = CellFactory.create(this, _book_vm.columns.security_key_column, nameof(security_key), r => r._order.security_key(), r => r._security_key_store)); + IOrderBookCellStore _security_store => _security_store_backing ?? (_security_store_backing = CellFactory.create_nullable(this, _book_vm.columns.security_column, nameof(security), r => r._security, r => r._security_store, v => v.display_name())); + IOrderBookCellStore _exchange_store => _exchange_store_backing ?? (_exchange_store_backing = CellFactory.create(this, _book_vm.columns.exchange_column, nameof(exchange), r => r._security.HasValue ? _security.Value.Exchange : Venue.Unset, r => r._exchange_store)); + IOrderBookCellStore _symbol_store => _symbol_store_backing ?? (_symbol_store_backing = CellFactory.create(this, _book_vm.columns.symbol_column, nameof(symbol), r => r._symbol, r => r._symbol_store, v => !String.IsNullOrEmpty(v) ? v : "unknown symbol")); + // Def + IOrderBookCellStore _order_type_store => _order_type_store_backing ?? (_order_type_store_backing = CellFactory.create(this, _book_vm.columns.order_type_column, nameof(order_type), r => r._order.order_type(), r => r._order_type_store)); + IOrderBookCellStore _side_store => _side_store_backing ?? (_side_store_backing = CellFactory.create(this, _book_vm.columns.side_column, nameof(side), r => r._order.side(), r => r._side_store)); + IOrderBookCellStore _user_store => _user_store_backing ?? (_user_store_backing = CellFactory.create(this, _book_vm.columns.user_column, nameof(user), r => _order.user(), r => r._user_store)); + IOrderBookCellStore _account_store => _account_store_backing ?? (_account_store_backing = CellFactory.create(this, _book_vm.columns.account_column, nameof(account), r => r._order.account(), r => r._account_store)); + IOrderBookCellStore _time_in_force_store => _time_in_force_store_backing ?? (_time_in_force_store_backing = CellFactory.create(this, _book_vm.columns.time_in_force_column, nameof(time_in_force), r => r._order.time_in_force(), r => r._time_in_force_store)); + IOrderBookCellStore _time_created_store => _time_created_store_backing ?? (_time_created_store_backing = CellFactory.create(this, _book_vm.columns.time_created_column, nameof(time_created), r => r._order.created(), r => r._time_created_store, format_date)); + // State + IOrderBookCellStore _last_change_store => _last_change_store_backing ?? (_last_change_store_backing = CellFactory.create(this, _book_vm.columns.last_change_column, nameof(last_change), r => _order.last_change(), r => r._last_change_store, format_date)); + IOrderBookCellStore _status_store => _status_store_backing ?? (_status_store_backing = CellFactory.create(this, _book_vm.columns.status_column, nameof(status), r => _order.status(), r => r._status_store)); + IOrderBookCellStore _price_store => _price_store_backing ?? (_price_store_backing = CellFactory.create(this, _book_vm.columns.price_column, nameof(price), r => _order.price(), r => r._price_store, format_price)); + IOrderBookCellStore _quantity_store => _quantity_store_backing ?? (_quantity_store_backing = CellFactory.create(this, _book_vm.columns.qty_column, nameof(quantity), r => _order.quantity(), r => r._quantity_store)); + IOrderBookCellStore _filled_quantity_store => _filled_quantity_store_backing ?? (_filled_quantity_store_backing = CellFactory.create(this, _book_vm.columns.filled_qty_column, nameof(filled_quantity), r => _order.filled(), r => r._filled_quantity_store)); + IOrderBookCellStore _last_price_store => _last_price_store_backing ?? (_last_price_store_backing = CellFactory.create(this, _book_vm.columns.last_price_column, nameof(last_price), r => _order.last_price(), r => r._last_price_store, format_price)); + IOrderBookCellStore _avg_price_store => _avg_price_store_backing ?? (_avg_price_store_backing = CellFactory.create(this, _book_vm.columns.avg_price_column, nameof(avg_price), r => _order.avg_price(), r => r._avg_price_store, format_price)); + IOrderBookCellStore _last_msg_store => _last_msg_store_backing ?? (_last_msg_store_backing = CellFactory.create(this, _book_vm.columns.last_message_column, nameof(last_msg), r => _order.last_msg(), r => r._last_msg_store)); + IOrderBookCellStore _order_sub_type_store => _order_sub_type_store_backing ?? (_order_sub_type_store_backing = CellFactory.create(this, _book_vm.columns.sub_type_column, nameof(order_sub_type), r => r._order.sub_type(), r => r._order_sub_type_store, format_sub_type)); + + static string format_date(DateTime v) => $"{v:M/d} {v:h:mm:ss.fff tt}"; + string format_price(double v) => _security.HasValue ? + _security.Value.ContractSpec.format(v) : + Math.Round(v, _unknown_security_price_num_fractional_digits, MidpointRounding.AwayFromZero).ToString(_unknown_security_price_format_string); + static string format_sub_type(OrderSubType v) { + switch (v) { + case OrderSubType.HedgingLeg: return "H"; + case OrderSubType.QuotingLeg: return "Q"; + default: return string.Empty; + } + } public OrderBookRowVM(IBus bus, OrderBookVM source_vm, OrdersModel model, OrderRecordImmutable record, SecurityMD? s) { _book_vm = source_vm; @@ -62,42 +98,6 @@ namespace mbts.spark { _security_md = s; _symbol = _security_md.HasValue ? _security_md.Value.security.Symbol : null; animator = new PredicateAnimator(this); - // cells - cell_stores = new DIYGrid.IGridCellStore[] { - _security_store = CellFactory.create_nullable(this, _book_vm.columns.security_column, nameof(security), r => r._security, r => r._security_store, v => v.display_name()), - _security_key_store = CellFactory.create(this, _book_vm.columns.security_key_column, nameof(security_key), r => r._order.security_key(), r => r._security_key_store), - _parent_order_key_store = CellFactory.create(this, _book_vm.columns.parent_key_column, nameof(parent_order_key), r => r._order.ParentKey, r => r._parent_order_key_store), - _order_key_store = CellFactory.create(this, _book_vm.columns.order_key_column, nameof(order_key), r => r._order.Key, r => r._order_key_store), - _symbol_store = CellFactory.create(this, _book_vm.columns.symbol_column, nameof(symbol), r => r._symbol, r => r._symbol_store, v => !String.IsNullOrEmpty(v) ? v : "unknown symbol"), - _time_created_store = CellFactory.create(this, _book_vm.columns.time_created_column, nameof(time_created), r => r._order.created(), r => r._time_created_store, format_date), - _user_store = CellFactory.create(this, _book_vm.columns.user_column, nameof(user), r => _order.user(), r => r._user_store), - _account_store = CellFactory.create(this, _book_vm.columns.account_column, nameof(account), r => r._order.account(), r => r._account_store), - _exchange_store = CellFactory.create(this, _book_vm.columns.exchange_column, nameof(exchange), r => r._security.HasValue ? _security.Value.Exchange : Venue.Unset, r => r._exchange_store), - _time_in_force_store = CellFactory.create(this, _book_vm.columns.time_in_force_column, nameof(time_in_force), r => r._order.time_in_force(), r => r._time_in_force_store), - _order_type_store = CellFactory.create(this, _book_vm.columns.order_type_column, nameof(order_type), r => r._order.order_type(), r => r._order_type_store), - _order_sub_type_store = CellFactory.create(this, _book_vm.columns.sub_type_column, nameof(order_sub_type), r => r._order.sub_type(), r => r._order_sub_type_store, format_sub_type), - _side_store = CellFactory.create(this, _book_vm.columns.side_column, nameof(side), r => r._order.side(), r => r._side_store), - _last_change_store = CellFactory.create(this, _book_vm.columns.last_change_column, nameof(last_change), r => _order.last_change(), r => r._last_change_store, format_date), - _price_store = CellFactory.create(this, _book_vm.columns.price_column, nameof(price), r => _order.price(), r => r._price_store, format_price), - _quantity_store = CellFactory.create(this, _book_vm.columns.qty_column, nameof(quantity), r => _order.quantity(), r => r._quantity_store), - _filled_quantity_store = CellFactory.create(this, _book_vm.columns.filled_qty_column, nameof(filled_quantity), r => _order.filled(), r => r._filled_quantity_store), - _avg_price_store = CellFactory.create(this, _book_vm.columns.avg_price_column, nameof(avg_price), r => _order.avg_price(), r => r._avg_price_store, format_price), - _last_price_store = CellFactory.create(this, _book_vm.columns.last_price_column, nameof(last_price), r => _order.last_price(), r => r._last_price_store, format_price), - _status_store = CellFactory.create(this, _book_vm.columns.status_column, nameof(status), r => _order.status(), r => r._status_store), - _last_msg_store = CellFactory.create(this, _book_vm.columns.last_message_column, nameof(last_msg), r => _order.last_msg(), r => r._last_msg_store), - }; - // - string format_price(double v) => _security.HasValue ? _security.Value.ContractSpec.format(v) : - Math.Round(v, _unknown_security_price_num_fractional_digits, MidpointRounding.AwayFromZero).ToString(_unknown_security_price_format_string); - string format_date(DateTime v) => $"{v:M/d} {v:h:mm:ss.fff tt}"; - string format_sub_type(OrderSubType v) { - switch (v) { - case OrderSubType.HedgingLeg: return "H"; - case OrderSubType.QuotingLeg: return "Q"; - default: return string.Empty; - } - } - // _visible = backing(nameof(is_visible), true); _expanded = backing(nameof(is_expanded), false); _depth_level = backing(nameof(depth_level), () => { @@ -212,7 +212,31 @@ namespace mbts.spark { } public ObservableCollection row_animations { get; } = new ObservableCollection(); - public IReadOnlyList cell_stores { get; } + + DIYGrid.IGridCellStore[] _cell_stores_backing; + public IReadOnlyList cell_stores => _cell_stores_backing ?? (_cell_stores_backing = new DIYGrid.IGridCellStore[] { + _security_store, + _security_key_store, + _parent_order_key_store, + _order_key_store, + _symbol_store, + _time_created_store, + _user_store, + _account_store, + _exchange_store, + _time_in_force_store, + _order_type_store, + _order_sub_type_store, + _side_store, + _last_change_store, + _price_store, + _quantity_store, + _filled_quantity_store, + _avg_price_store, + _last_price_store, + _status_store, + _last_msg_store + }); public static Stack lineage(OrderBookRowVM node) { var rv = new Stack();