From 1d4dc47a62a2f0557a73fcf5084cbb5e099ad390 Mon Sep 17 00:00:00 2001 From: Pedro Pinto Date: Mon, 15 Jun 2020 09:28:23 -0400 Subject: [PATCH 1/5] Added missing update to session/high low. --- src/server/sparkd/md/platforms/ice_onixs/ICEListener.cpp | 4 ++++ 1 file changed, 4 insertions(+) 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) ); } } From ec0b726751b4eeaec56d91b515bb6ada67ceb307 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 16 Jun 2020 16:40:28 -0500 Subject: [PATCH 2/5] ladder mid tick rounds down for negative numbers (still rounds up for positive) --- src/client/spark/view/Spark/Core/TickUtils.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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) { From b21cd12cea375546d906d91a22224d4b7cb4a534 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Wed, 17 Jun 2020 12:24:31 -0500 Subject: [PATCH 3/5] copy AppendTable extension from another branch --- .../spark_core/utils/UpdateExtensions.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) 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); From 7a4dca9589d52425d8a89f2402e2919cdb8be4b1 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Wed, 17 Jun 2020 12:29:44 -0500 Subject: [PATCH 4/5] PNLWindow uses special pnl_symbol (taha will implement pnl_symbol method later, returns regular symbol in meantime) --- .../spark/Modules/Trading/PNL/Data/PNLData.cs | 7 +++++++ .../spark/Modules/Trading/PNL/VM/PNLRowVM.cs | 2 +- .../spark/Modules/Trading/PNL/VM/PNLVM.cs | 18 +++++++++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) 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..6693c338a 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()); @@ -187,7 +192,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 +547,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) { From a2a0d88a8150d277c4f983bacfc761548e3c8b23 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Wed, 17 Jun 2020 12:39:59 -0500 Subject: [PATCH 5/5] pnl window disposes filters of type IDisposable --- src/client/spark/Modules/Trading/PNL/VM/PNLVM.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/client/spark/Modules/Trading/PNL/VM/PNLVM.cs b/src/client/spark/Modules/Trading/PNL/VM/PNLVM.cs index 6693c338a..632c9aad9 100644 --- a/src/client/spark/Modules/Trading/PNL/VM/PNLVM.cs +++ b/src/client/spark/Modules/Trading/PNL/VM/PNLVM.cs @@ -116,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(); }));