SPARK-1183 3-5 1000 lot iceberg orders can lag/lock up the UI
This commit is contained in:
1 parent
4378947e44
commit
036550aaae
3 files changed
+15
-13
No files matched your search
@@ -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<OrderRecordImmutable>(), (worders, table) => _update_order_set(worders, table, o => o.is_active())).Replay(1).RefCount();
|
||||
IReadOnlyDictionary<uint, OrderRecordImmutable> empty_orders = new Dictionary<uint, OrderRecordImmutable>();
|
||||
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<TableUpdate<OrderRecordImmutable, uint>> on_orders { get; }
|
||||
public IObservable<TableUpdate<FillImmutable, string>> on_fills { get; }
|
||||
public IObservable<ITableUpdateTransform<FillTuple, string>> on_fill_tuples { get; }
|
||||
public IObservable<HashSet<OrderRecordImmutable>> working_orders { get; }
|
||||
public IObservable<IReadOnlyDictionary<uint,OrderRecordImmutable>> working_orders { get; }
|
||||
|
||||
public IObservable<TableUpdate<OrderRecordImmutable, uint>> 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<OrderRecordImmutable> _update_order_set(HashSet<OrderRecordImmutable> target, TableUpdate<OrderRecordImmutable, uint> table, Func<OrderRecordImmutable, bool> where) {
|
||||
var clone = new HashSet<OrderRecordImmutable>(target);
|
||||
static IReadOnlyDictionary<uint, OrderRecordImmutable> _update_working_orders(IReadOnlyDictionary<uint, OrderRecordImmutable> target, TableUpdate<OrderRecordImmutable, uint> table) {
|
||||
var clone = new Dictionary<uint, OrderRecordImmutable>((IDictionary<uint, OrderRecordImmutable>)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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
);
|
||||
|
||||
@@ -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()
|
||||
);
|
||||
|
||||
|
||||
Reference in new issue
Block a user