From 3b27fedcd306ca984bb039d44cfe2804c825a65e Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 7 May 2019 11:17:57 -0500 Subject: [PATCH] SPARK-2402 piq merge broke the orderbook mini-ladder order filter --- .../Modules/Trading/Ladder/LadderModel.cs | 9 +++---- .../Modules/Trading/Ladder/VM/LadderVM.cs | 18 ++----------- src/client/spark/Orders/OrdersModel.cs | 25 +++++++------------ 3 files changed, 14 insertions(+), 38 deletions(-) diff --git a/src/client/spark/Modules/Trading/Ladder/LadderModel.cs b/src/client/spark/Modules/Trading/Ladder/LadderModel.cs index f2e234f67..a5a42f77f 100644 --- a/src/client/spark/Modules/Trading/Ladder/LadderModel.cs +++ b/src/client/spark/Modules/Trading/Ladder/LadderModel.cs @@ -2,11 +2,8 @@ using bts.api; using bts.api.core; using bts.api.orderman; -using bts.collections; using mbts.co2; using System; -using System.Collections.Generic; -using System.Reactive.Linq; using System.Threading.Tasks; namespace mbts.spark { @@ -16,9 +13,9 @@ namespace mbts.spark { public LadderModel(SecurityMD source, OrdersModel ordergw, Func order_filter = null) { security_md = source; _order_gateway = ordergw; - orders = ordergw.on_security_working_orders(source.security.Id); + orders = ordergw.on_security_working_orders_with_piq(source.security.Id); if (order_filter != null) - orders = orders.Filter(o => order_filter(new OrderSecurity(source.security, o)), o => o.Key); + orders = orders.Filter(order_filter, o => o.order.Key); } public enum CancelType { All, Bids, Asks } @@ -27,7 +24,7 @@ namespace mbts.spark { public SecurityImmutable security => security_md.security; public MDConsumerHandle md => security_md.md; public OrdersModel order_gateway => _order_gateway; - public IObservable> orders { get; } + public IObservable> orders { get; } public Task cancel_orders(CancelType ct) { switch (ct) { diff --git a/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs b/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs index 9a650fb04..d4aadd186 100644 --- a/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs +++ b/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs @@ -146,24 +146,10 @@ namespace mbts.spark { size_calculator = new CalculatorLogic(0, _settings_manager.subscribe_current().Select(s => s.calculator_buttons)), bus.subscribe(SparkTags.LogActivity).OnDispatcher().Subscribe(status_update), // we need to hook this up to model.orders which is filtered for just the security - model.order_gateway.working_orders_with_piq.OnDispatcher().Subscribe(working => { + model.orders.OnDispatcher().Subscribe(working => { // Here we manage N orders to 1 price slot in the ladder Dictionary> orders_used_in_this_update = new Dictionary>(_equality); - - // In master we originally had something similar to this snippet to restrict the foreach to just the orders - // for this ladder. In 1944, at one point we made use of model.orders, which made use of the on_security_working_orders demuxer. - // When we merged PIQ into 1944, we moved from that demuxer to working_orders_with_piq, so we reintroduce this little snippet here - // to once again restrict the processing to those working orders that match the criteria. Check with John to see if we can - // make a demuxer from working_orders_with_piq, which is an IReadOnlyDictionary; that probably won't work, but I have no doubt - // there is a better way. - var ladders_orders = - working.Values - .Where(o => - o.order.Def.SecurityKey == security.Id && - (o.order.HasState && o.order.State.DisplayStatus == OrderState.Types.DisplayStatus.Visible)) - .ToReadOnlyDictionary(os => os.order.Key, os => os); - - _cache = ladders_orders; + _cache = working.state; foreach (var os in _cache.Values) { var wo = os.order; diff --git a/src/client/spark/Orders/OrdersModel.cs b/src/client/spark/Orders/OrdersModel.cs index 9fad1a990..6487abd6b 100644 --- a/src/client/spark/Orders/OrdersModel.cs +++ b/src/client/spark/Orders/OrdersModel.cs @@ -37,7 +37,8 @@ namespace mbts.spark { readonly ErrorReporter _error; readonly DynamicOrderHelper _dynamic_helper; readonly OrderActivitySummarizer _activity; - readonly TableUpdateDemuxer _security_orders_demuxer, _security_working_orders_demuxer; + readonly TableUpdateDemuxer _security_orders_demuxer; + readonly TableUpdateDemuxer _security_working_orders_with_piq_demuxer; readonly TableUpdateDemuxer _security_positions_demuxer; IDisposable _dispose; static readonly bool _piq_enabled = Configuration.get().enabled; @@ -82,7 +83,7 @@ namespace mbts.spark { _activity = new OrderActivitySummarizer(bus, on_orders); _security_orders_demuxer = new TableUpdateDemuxer(o => o.Key, o => o.security_key()); - _security_working_orders_demuxer = new TableUpdateDemuxer(o => o.Key, o => o.security_key()); + _security_working_orders_with_piq_demuxer = new TableUpdateDemuxer(o => o.order.Key, o => o.order.security_key()); _security_positions_demuxer = new TableUpdateDemuxer(o => o.RecordId, p => p.SecurityId); var algo_meta_join = algo_model.definitions.LeftJoin( algo_model.metadata_service.subscribe_metadata().Table(m => m.id), @@ -114,13 +115,7 @@ namespace mbts.spark { (osam, _) => new OrderSecurity(osam.security, osam.order, null, osam.algo, osam.meta), osp => osp.order.Key) .Cache(); - - working_orders_with_piq = - on_order_tuples_with_piq.Scan( - ImmutableDictionary.Empty, - (workers, table) => _update_working_orders(workers, table)) - .Replay(1).RefCount(); - + // fills var on_fills = _service.subscribei_fills() .Naggle(interval, scheduler) @@ -152,10 +147,9 @@ namespace mbts.spark { .Cache(); _dispose = Disposable.Create( on_orders.Select(t => t.order, o => o.Key).Subscribe(_security_orders_demuxer), - on_orders - .Filter(order => order.order.is_active() && order.order.HasState && order.order.State.DisplayStatus == OrderState.Types.DisplayStatus.Visible, key => key.order.Key) - .Select(t => t.order, o => o.Key) - .Subscribe(_security_working_orders_demuxer), + on_order_tuples_with_piq + .Filter(os => os.order.is_active() && os.order.State.DisplayStatus == OrderState.Types.DisplayStatus.Visible, key => key.order.Key) + .Subscribe(_security_working_orders_with_piq_demuxer), on_positions.Subscribe(_security_positions_demuxer), _bus.subscribe(SparkTags.CreateOrder).Subscribe(a => send_order(a.definition, a.price, a.size).ignore()), _bus.subscribe(SparkTags.RecreateOrder).Subscribe(a => a.ForEach(x => send_order(x.definition, x.price, x.size).ignore())), @@ -177,14 +171,13 @@ namespace mbts.spark { public IObservable> on_order_securities { get; } public IObservable> on_fill_tuples { get; } public IObservable> working_orders { get; } - public IObservable> working_orders_with_piq { get; } public IObservable> on_positions { get; } public AdminModel admin_model { get; } public IAlgoStudioModel algo_model { get; } - public IObservable> on_security_working_orders(uint security) => - _security_working_orders_demuxer.subscribe(security); + public IObservable> on_security_working_orders_with_piq(uint security) => + _security_working_orders_with_piq_demuxer.subscribe(security); public IObservable> on_security_orders(uint security) => _security_orders_demuxer.subscribe(security);