diff --git a/src/client/spark/Orders/OrdersModel.cs b/src/client/spark/Orders/OrdersModel.cs index 7ecda28c1..70ae0bfc9 100644 --- a/src/client/spark/Orders/OrdersModel.cs +++ b/src/client/spark/Orders/OrdersModel.cs @@ -32,7 +32,9 @@ namespace mbts.spark { _spreader = spreader; _error = error; on_orders = _service.subscribei_orders().Table().Replay(1).RefCount(); - working_orders = on_orders.Scan(new HashSet(), (worders, table) => _update_order_set(worders, table, o => o.is_active())).Replay(1).RefCount(); + IReadOnlyDictionary empty_orders = new Dictionary(); + working_orders = + on_orders.Scan(empty_orders, (worders, table) => _update_working_orders(worders, table)).Replay(1).RefCount(); on_fills = _service.subscribei_fills().Table().Replay(1).RefCount(); _activity = new OrderActivitySummarizer(bus, on_orders); on_fill_tuples = FillTupleSource.create_observable(bus.subscribe(SparkTags.SecuritiesTag), on_orders, on_fills); @@ -51,7 +53,7 @@ namespace mbts.spark { public IObservable> on_orders { get; } public IObservable> on_fills { get; } public IObservable> on_fill_tuples { get; } - public IObservable> working_orders { get; } + public IObservable> working_orders { get; } public IObservable> on_security_orders(uint security) => _security_orders_demuxer.subscribe(security).Table(); @@ -115,15 +117,15 @@ namespace mbts.spark { public void Dispose() => Disposable.dispose(ref _dispose); - static HashSet _update_order_set(HashSet target, TableUpdate table, Func where) { - var clone = new HashSet(target); + static IReadOnlyDictionary _update_working_orders(IReadOnlyDictionary target, TableUpdate table) { + var clone = new Dictionary((IDictionary)target); foreach (var o in table.removed) { - if (where(o)) - clone.Remove(o); + if (o.is_active()) + clone.Remove(o.Key); } foreach (var o in table.added) { - if (where(o)) - clone.Add(o); + if (o.is_active()) + clone.Add(o.Key, o); } return clone; } diff --git a/src/client/spark/view/Spark/Ladder/LadderVM.cs b/src/client/spark/view/Spark/Ladder/LadderVM.cs index c8d7ef305..2b5eb4f61 100644 --- a/src/client/spark/view/Spark/Ladder/LadderVM.cs +++ b/src/client/spark/view/Spark/Ladder/LadderVM.cs @@ -72,13 +72,13 @@ namespace mbts.spark { bus.subscribe(SparkTags.LogActivity).ObserveOnDispatcher().Subscribe(status_update), // need to subscribe to all orders, and cache them, because parent orders don't necessarily have the same security // and OrderVM needs access to parent orders, if there are any - model.order_gateway.on_orders.ObserveOnDispatcher().Subscribe(t => { - under_orders.sync_with(t.state.Values.Where(o => o.Def.SecurityKey == security.Id && o.is_non_terminal())); + model.order_gateway.working_orders.ObserveOnDispatcher().Subscribe(working => { + under_orders.sync_with(working.Values.Where(o => o.Def.SecurityKey == security.Id && o.is_non_terminal())); Logger.assert(under_orders.Count == orders.Count); for (int x = 0; x < under_orders.Count; ++x) { orders[x].update(under_orders[x]); } - orders_cache = t.state; + orders_cache = working; }), WorkLoop.Start($"Ladder '{security}'", _tick) ); diff --git a/src/client/spark/view/Spark/Shell/OrderBook/OrderBookWindow.cs b/src/client/spark/view/Spark/Shell/OrderBook/OrderBookWindow.cs index 53e407ad1..679107e09 100644 --- a/src/client/spark/view/Spark/Shell/OrderBook/OrderBookWindow.cs +++ b/src/client/spark/view/Spark/Shell/OrderBook/OrderBookWindow.cs @@ -88,12 +88,12 @@ namespace mbts.spark { ); _cancel_buy_orders_command = SparkCommands.CancelBuyOrders.complete( - _model.working_orders.Select(os => os.Where(o => o.side() == Side.Buy).Select(o => o.Key)), + _model.working_orders.Select(os => os.Values.Where(o => o.side() == Side.Buy).Select(o => o.Key)), wbids => wbids.Any() ); _cancel_sell_orders_command = SparkCommands.CancelSellOrders.complete( - _model.working_orders.Select(os => os.Where(o => o.side() == Side.Sell).Select(o => o.Key)), + _model.working_orders.Select(os => os.Values.Where(o => o.side() == Side.Sell).Select(o => o.Key)), wasks => wasks.Any() );