diff --git a/src/client/spark/Modules/Trading/PNL/Data/PNLData.cs b/src/client/spark/Modules/Trading/PNL/Data/PNLData.cs index 687f1d310..347f025bd 100644 --- a/src/client/spark/Modules/Trading/PNL/Data/PNLData.cs +++ b/src/client/spark/Modules/Trading/PNL/Data/PNLData.cs @@ -335,6 +335,8 @@ namespace bts.shell.pnl { AskLTESettle = Ask | Settle | 1 << 7 } + public string symbol => security?.pnl_symbol() ?? string.Empty; + /// Market/Calc public double mid_price => (bid_price + ask_price) / 2; public double pnl_price { @@ -591,6 +593,11 @@ namespace bts.shell.pnl { } static class PNLDataExtensions { + public static string pnl_symbol(this SecurityImmutable security) { + // TODO: actual impl + return security.Symbol; + } + // Note: PNLRowData is passed by ref because it is fairly large struct, and since it is a readonly struct, we know it cannot be modified (so might as well avoid excessive copying). public static PNLRowData with(this PNLRowData pnl_data, SecurityImmutable? security = null, string account_name = null, WorkingOrderData? working = null, PNLCalculationType? calc_type = null) => new PNLRowData( diff --git a/src/client/spark/Modules/Trading/PNL/VM/PNLRowVM.cs b/src/client/spark/Modules/Trading/PNL/VM/PNLRowVM.cs index 4c57212d7..c0b03a08a 100644 --- a/src/client/spark/Modules/Trading/PNL/VM/PNLRowVM.cs +++ b/src/client/spark/Modules/Trading/PNL/VM/PNLRowVM.cs @@ -30,7 +30,7 @@ namespace bts.shell.pnl { account_name_cell = _cell_map.add(ColumnKeys.Account, d => d.account_name); security_type_cell = _cell_map.add(ColumnKeys.SecurityType, d => d.security?.ContractCase ?? Security.ContractOneofCase.None); exchange_cell = _cell_map.add(ColumnKeys.Exchange, d => d.security?.Exchange ?? Venue.Unset); - symbol_cell = _cell_map.add(ColumnKeys.Symbol, d => d.security?.Symbol ?? string.Empty); + symbol_cell = _cell_map.add(ColumnKeys.Symbol, d => d.symbol); security_cell = _cell_map.add(ColumnKeys.Security, d => (d.security), null, EqualityComparer.Default, Comparer.Default.to_nullable()); security_key = _cell_map.add(ColumnKeys.SecurityKey, d => d.key.security_id); cpp = _cell_map.add(ColumnKeys.CPP, d => d.cpp); diff --git a/src/client/spark/Modules/Trading/PNL/VM/PNLVM.cs b/src/client/spark/Modules/Trading/PNL/VM/PNLVM.cs index ffef9f99f..632c9aad9 100644 --- a/src/client/spark/Modules/Trading/PNL/VM/PNLVM.cs +++ b/src/client/spark/Modules/Trading/PNL/VM/PNLVM.cs @@ -88,6 +88,11 @@ namespace bts.shell.pnl { }); // filters account_filter = DiscreteValuesFilterVM.Common.account(orders_model, r => new AccountTuple(r.key.account_id, r.account_name), nameof(PNLRowVM.account_name)); + symbol_filter = DiscreteValuesFilterVM.Create( + _symbols_source(pnl_source), + r => r.symbol, + selection => selection.ToArray(), + selection => Observable.Return(selection)); _refresh_filter = new DeferrableActionWrapper(() => _filter_changed?.Invoke(get_filters_states().build_predicate())); var filter_src = Observable.Create>(o => { o.OnNext(get_filters_states().build_predicate()); @@ -111,6 +116,7 @@ namespace bts.shell.pnl { Disposable.Create(() => { foreach (var f in _all_filters) f.filter_changed -= _refresh_filter.execute; + _all_filters.OfType().DisposeAll(); rows.DisposeAll(); _rows_view.Groups.OfTypeSafe().DisposeAll(); })); @@ -187,7 +193,7 @@ namespace bts.shell.pnl { /// security public IDataGridColumnPersistentFilter account_filter { get; } public IDataGridColumnPersistentFilter exchange_filter { get; } = DiscreteValuesFilterVM.Common.exchange(r => r.security.exchange_or_default(), nameof(PNLRowVM.exchange)); - public IDataGridColumnPersistentFilter symbol_filter { get; } = DiscreteValuesFilterVM.Common.symbol(r => r.security.symbol_or_default(), nameof(PNLRowVM.symbol)); + public IDataGridColumnPersistentFilter symbol_filter { get; } public IDataGridColumnPersistentFilter security_filter { get; } = new RegexFilterVM(r => r.security?.ToString(), nameof(PNLRowData.security)); public IDataGridColumnPersistentFilter security_key_filter { get; } = new RegexFilterVM(r => r.key.security_id.ToString()); public IDataGridColumnPersistentFilter security_type_filter { get; } = DiscreteValuesFilterVM.Create( @@ -542,6 +548,17 @@ namespace bts.shell.pnl { yield return col_hash.Contains(c.id) ? c.with(is_visible: false) : c; } + // combines the known system symbols + static IObservable<(IEnumerable added, IEnumerable removed)> _symbols_source(IObservable> pnl_source) => + pnl_source + // ensure this fires once immediatey, because the known symbols are appended to the first update + // (observers shouldn't have to wait for the pnl source to tick to see them). + .StartWith(TableUpdate.mk_empty(PNLRowData.key_fn)) + .distinct_on(PNLRowData.key_fn, r => r.symbol, s => s) + .Filter(sym => !string.IsNullOrEmpty(sym)) + .AppendTable(mbts.co2.UserSymbol.get_all().Select(u => u.symbol).Distinct().ToList()) + .Select(t => (t.added, t.removed)); + #region Fills Popup Utils static void _append_key_filters(fills.FillsFilterStates f, ColumnKeys key) { switch (key) { diff --git a/src/client/spark/view/Spark/Core/TickUtils.cs b/src/client/spark/view/Spark/Core/TickUtils.cs index af1c1b184..2bc29007f 100644 --- a/src/client/spark/view/Spark/Core/TickUtils.cs +++ b/src/client/spark/view/Spark/Core/TickUtils.cs @@ -111,7 +111,9 @@ namespace mbts.spark { raw_mid = (bid + ask) / 2.0; } double tick_size = spec.ticksize(raw_mid); - return raw_mid - (raw_mid % tick_size); + return raw_mid < 0 ? + raw_mid + (raw_mid % tick_size) : + raw_mid - (raw_mid % tick_size); } public static TickFactors deduce_ticks(IEnumerable contract_specs) { diff --git a/src/client/spark_core/utils/UpdateExtensions.cs b/src/client/spark_core/utils/UpdateExtensions.cs index 389803a8d..e8bc817dd 100644 --- a/src/client/spark_core/utils/UpdateExtensions.cs +++ b/src/client/spark_core/utils/UpdateExtensions.cs @@ -11,6 +11,35 @@ using System.Reactive.Linq; namespace bts.utils { public static class UpdateExtensions { + public static IObservable> AppendTable(this IObservable> source, IEnumerable append_items) where TKey : IEquatable { + HashSet append_keys = null; + Func append_key_filter = null; + return Observable.Create>(o => { + TableUpdate output = null; + return source.Subscribe(table => { + if (output == null) { + // first update - initialize output, and (maybe) append_keys/append_key_filter + // Note: append_keys/filter can be shared among all subscriptions because, and only needs to be initialized once; + // once initialized, the append_keys/filter will not change. + output = table; + if (append_keys == null) { + append_keys = new HashSet(append_items.Select(table.key_extractor)); + append_key_filter = v => !append_keys.Contains(table.key_extractor(v)); + } + // filter append_items out of the normal source (ensures that they will be immune to removes/changes). + output = TableUpdate.FilterHelper.on_predicate_changed(output, table.state, null, append_key_filter); + // add the append_items to the output table (only need to do this once) + output = TableUpdate.update(output, append_items, Enumerable.Empty>(), Enumerable.Empty(), table.key_extractor); + output = output.as_snapshot(); + } else { + output = TableUpdate.FilterHelper.on_source_changed( + output, table.added, table.changes, table.removed, append_key_filter); + } + o.OnNext(output); + }); + }); + } + public static TableUpdate with_added(this TableUpdate table, IEnumerable added) where TKey : IEquatable => TableUpdate.update(table, added, Enumerable.Empty>(), Enumerable.Empty(), table.key_extractor); diff --git a/src/server/sparkd/md/platforms/ice_onixs/ICEListener.cpp b/src/server/sparkd/md/platforms/ice_onixs/ICEListener.cpp index 0ef7f1cfb..d75931ad7 100644 --- a/src/server/sparkd/md/platforms/ice_onixs/ICEListener.cpp +++ b/src/server/sparkd/md/platforms/ice_onixs/ICEListener.cpp @@ -187,7 +187,11 @@ void ICEListener::onMarketStatistics(const onixs_ice::MarketStatistics& msg, con if (data != nullptr) { bts_assert(data->id == msg.marketId); + auto ts = utils::TimeStamp::now(); + auto deal_denominator = data->handle.security().ice_deal_denominator; data->handle.set_total_volume(msg.volume); + data->handle.update_session_high( ts, double_of_price(msg.high, deal_denominator) ); + data->handle.update_session_low( ts, double_of_price(msg.low, deal_denominator) ); } }