diff --git a/src/client/spark/view/Spark/Core/OrderUtils.cs b/src/client/spark/view/Spark/Core/OrderUtils.cs index e83c0107d..b1314fb0a 100644 --- a/src/client/spark/view/Spark/Core/OrderUtils.cs +++ b/src/client/spark/view/Spark/Core/OrderUtils.cs @@ -26,6 +26,9 @@ namespace mbts.spark { return $"({after.Key}) Filled {(fa - fb)} ({fa} total), still working {after.working_quantity()}"; } + public static string log_summary(OrderRecordImmutable order, string msg) => + $"({order.Key}) {msg} [Status]{order.State.Status}, [Price]{order.State.Price}, [Size]{order.State.Quantity}, [Working]{order.working_quantity()}, [Type]{order.State.CustomCase}"; + public static string full_description(this OrderRecordImmutable order, SecurityImmutable security) { StringBuilder sb = new StringBuilder(); sb.AppendLine($"{order.Def.Side}: {TickUtils.format(security.ContractSpec, order.State.Price)}"); diff --git a/src/client/spark/view/Spark/Ladder/LadderVM.cs b/src/client/spark/view/Spark/Ladder/LadderVM.cs index fe3abe92c..e81feb66d 100644 --- a/src/client/spark/view/Spark/Ladder/LadderVM.cs +++ b/src/client/spark/view/Spark/Ladder/LadderVM.cs @@ -11,6 +11,7 @@ using System.Linq; using System.Reactive.Linq; using System.Threading.Tasks; using System.Windows.Input; +using System.Windows.Media; namespace mbts.spark { static class OrderLogCategories { @@ -21,6 +22,8 @@ namespace mbts.spark { public static ILogViewerCategory fill = new LogViewerCategory("Fill", BTSColors.Orders.filled_dark); public static ILogViewerCategory cancel = new LogViewerCategory("Cancel", BTSColors.Orders.working_cancel); public static ILogViewerCategory modify = new LogViewerCategory("Modify", BTSColors.Orders.modified); + // used warn instead of error, bc cancel already uses red, and this is probably not permament, just trying to track down the cert-order-price bug + public static ILogViewerCategory warn = new LogViewerCategory("Warn", Brushes.Gold); } class LadderVM : DisposableViewModelBase, IKeyListener { @@ -33,14 +36,15 @@ namespace mbts.spark { order_category = OrderLogCategories.order, cancel_category = OrderLogCategories.cancel, modify_category = OrderLogCategories.modify, - fill_category = OrderLogCategories.fill; + fill_category = OrderLogCategories.fill, + warn_category = OrderLogCategories.warn; public LadderVM(IBus bus, LadderModel model, IObservable settings) { _bus = bus; _model = model; _order_template = new OrderDefinitionImmutable(_model.order_gateway.factory.order(_model.security)); - log_categories = new[] { order_category, cancel_category, modify_category, fill_category }; + log_categories = new[] { order_category, cancel_category, modify_category, fill_category, warn_category }; _high = backing(nameof(high), ""); _low = backing(nameof(low), ""); @@ -75,18 +79,45 @@ namespace mbts.spark { // 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 => { - var e = t.evaluate(o => o.Key, o => o.Def.SecurityKey == security.Id && o.is_active()); - foreach (var o in e.true_removed) + var e = t.evaluate(o => o.Key, o => o.Def.SecurityKey == security.Id && o.is_non_terminal()); + var old_keys = orders.Select(o => o.id).ToList(); + List true_removed = e.true_removed.ToList(), true_added = e.true_added.ToList(), true_changed = e.changed.ToList(); + foreach (var o in true_removed) orders.removeFirst(vm => vm.id == o.Key); - foreach (var o in e.changed) + foreach (var o in true_changed) orders.ApplyToFirst(vm => vm.id == o.Key, vm => vm.update(o)); - foreach (var o in e.true_added) + foreach (var o in true_added) orders.Add(new OrderVM(o, this, _bus)); + var new_keys = orders.Select(o => o.id).ToList(); + // verify that everything is right, trying to track down this cert-spreader-child-order-wrong-price bug + foreach (var kv in t.state) { + if (kv.Value.Def.SecurityKey == security.Id) { + if (kv.Value.is_non_terminal()) { + var vm = orders.FirstOrDefault(o => o.id == kv.Key); + if (vm == null) { + string was_in_ui = old_keys.Contains(kv.Key) ? "(was there before update)" : "(was not there before update)"; + _log_warning(OrderUtils.log_summary(kv.Value, $"Absent from UI, {was_in_ui}")); + } else { + if (vm.price != kv.Value.State.Price) { + if (!vm.has_phantom_price) + _log_warning(OrderUtils.log_summary(kv.Value, $"Price diff ({vm.price}) in UI.")); + else + _log_warning(OrderUtils.log_summary(kv.Value, $"Phantom price diff (vm phantom {vm.price} vm real{vm.real_price}) in UI.")); + } + } + } + } + } orders_cache = t.state; }), WorkLoop.Start(tick) ); } + + void _log_warning(string msg) { + log_messages.AddLog(new LogViewerMessage(warn_category, msg)); + Logger.error(bts.log.Subsystem.Ui, msg); + } public event Action on_tick; diff --git a/src/client/spark/view/Spark/Ladder/OrderVM.cs b/src/client/spark/view/Spark/Ladder/OrderVM.cs index f45c6a3b6..248a7de48 100644 --- a/src/client/spark/view/Spark/Ladder/OrderVM.cs +++ b/src/client/spark/view/Spark/Ladder/OrderVM.cs @@ -74,6 +74,7 @@ namespace mbts.spark { public uint id => _order.Key; public uint security_key => _parent.security.Id; public double price { get => double.IsNaN(_phantom_price) ? _real_price : _phantom_price; } + public double real_price => _real_price; public Side side => _order.Def.Side; public string text => ""; @@ -84,6 +85,7 @@ namespace mbts.spark { public string summary => _order.short_description(_parent.security.ContractSpec); public string description => _order.full_description(_parent.security); public bool has_parent => _order.has_parent(); + public bool has_phantom_price => !double.IsNaN(_phantom_price); public ICommand shatter_command => new DelegateCommand(() => _execute_command(model.order_gateway.crack_order(_order.Key).ignore) , () => !has_parent); public ICommand cancel_command => new DelegateCommand(() => _execute_command(_cancel_order), () => !has_parent);