From 612cd4a4c8d0b1ca68926c0eece1fc35386e5622 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Thu, 15 Sep 2022 00:27:06 -0400 Subject: [PATCH] fix: Remove refs to invalid 'default' SecurityImmutable It's most (probably all) cases where a static 'default' SecurityImmutable is used, a Nullable would more accurately represent the state, which could likely (probably always) be described as "waiting for my real security from an asynchronous source." Bugs (fixed): * [Race] When Fills window opens, an exception is thrown if the sec-filter's items are sorted with a 'default' SecurityImmutable. Cause: The static default SecurityImmutable doesn't have an underlying sec type (i.e., ContractOneofCase == None). The compare fn doesn't support this. TODO (maybe): It might be a good idea to 'fix' the compare fn as well (i.e., make it support 'None' sec types) TODO (probably): Remove remaining references to the static default SecurityImmutable --- .../spark/Modules/Market/MarketView/MarketViewRow.cs | 10 +++++----- .../Modules/Spreader/SyntheticManagementWindow.cs | 6 ++++-- .../Data/Events/OrderCanceledEventPredicate.cs | 4 ++-- .../Data/Events/OrderCompletedEventPredicate.cs | 4 ++-- .../Data/Events/OrderEventPredicateHelper.cs | 10 +++++----- .../Data/Events/OrderFilledEventPredicate.cs | 4 ++-- .../Predicates/Data/OrderRecordTuplePredicate.cs | 2 +- src/client/spark/Predicates/Data/SecurityPredicate.cs | 11 +++++++---- src/client/spark/core/Bus/SparkTags.cs | 4 ++-- 9 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs b/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs index 21442a6f2..688f75744 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs @@ -114,9 +114,9 @@ _ask_merged_size = backing(nameof(ask_qty), 0u, convert_display_qty_uint); _working_best_bid = new CellProperty( - this, nameof(working_best_bid), fmt_price, double.NaN); + this, nameof(working_best_bid), format_price, double.NaN); _working_best_ask = new CellProperty( - this, nameof(working_best_ask), fmt_price, double.NaN); + this, nameof(working_best_ask), format_price, double.NaN); // greeks _greeks = backing(nameof(greeks), GreeksTuple.empty); @@ -171,9 +171,6 @@ string fmt_display_qty_double(double value) => value.safe_divide(_display_qty_divisor).ToString(); - string fmt_price(double price) => - security.ContractSpec.format(price); - void on_orders(ITableUpdateTransform orders) { foreach (var o in orders.removed) { _order_summarizer.remove_order(o); @@ -322,6 +319,9 @@ (_display_qty_divisor_backing = _orders_model.security_auxiliary_model.get_display_quantity_divisor(security)).Value; IMDConsumerHandle _md => security_md.md; + public string format_price(double price) => + security.ContractSpec.format(price); + public void raise_invalidated() => _raise_invalidated.Invoke(); diff --git a/src/client/spark/Modules/Spreader/SyntheticManagementWindow.cs b/src/client/spark/Modules/Spreader/SyntheticManagementWindow.cs index f2864a0d7..d0fdef973 100644 --- a/src/client/spark/Modules/Spreader/SyntheticManagementWindow.cs +++ b/src/client/spark/Modules/Spreader/SyntheticManagementWindow.cs @@ -90,8 +90,10 @@ namespace mbts.spark { .complete(curr_row.SelectSeries(observe_mod_params), can_modify, select_security_id), SparkCommand.create("Change", Icons.ModifySynthetic, SparkTags.ShowSyntheticStrategyTag) - .complete(curr_row, r => - (r?.security).HasValue, r => r?.security ?? Security.Defaults.SecurityImmutable), + .complete( + curr_row, + r => (r?.security).HasValue, + r => (r?.security)?.Id ?? 0), SparkCommand.create("Clone", Icons.CloneSynthetic, SparkTags.ShowSyntheticCloneTag) .complete( diff --git a/src/client/spark/Predicates/Data/Events/OrderCanceledEventPredicate.cs b/src/client/spark/Predicates/Data/Events/OrderCanceledEventPredicate.cs index e4ea289cf..0c5dbad2e 100644 --- a/src/client/spark/Predicates/Data/Events/OrderCanceledEventPredicate.cs +++ b/src/client/spark/Predicates/Data/Events/OrderCanceledEventPredicate.cs @@ -64,10 +64,10 @@ namespace mbts { o.HasState && o.State.Status == OrderStatus.Canceled; class MyToaster : INotificationPredicate, IEquatable { - readonly IPredicate _security_predicate; + readonly IPredicate _security_predicate; readonly INotificationServiceDataCache _data_cache; - public MyToaster(IPredicate security_predicate, INotificationServiceDataCache data_cache) { + public MyToaster(IPredicate security_predicate, INotificationServiceDataCache data_cache) { _security_predicate = security_predicate; _data_cache = data_cache; } diff --git a/src/client/spark/Predicates/Data/Events/OrderCompletedEventPredicate.cs b/src/client/spark/Predicates/Data/Events/OrderCompletedEventPredicate.cs index 52930c5ce..c4073ee55 100644 --- a/src/client/spark/Predicates/Data/Events/OrderCompletedEventPredicate.cs +++ b/src/client/spark/Predicates/Data/Events/OrderCompletedEventPredicate.cs @@ -70,12 +70,12 @@ namespace mbts { o.HasState && o.State.Status == OrderStatus.Completed; class MyToaster : INotificationPredicate, IEquatable { - readonly IPredicate _security_predicate; + readonly IPredicate _security_predicate; readonly INotificationServiceDataCache _data_cache; readonly ISecurityMetadataStore _sec_meta_store; public MyToaster( - IPredicate security_predicate, + IPredicate security_predicate, INotificationServiceDataCache data_cache, ISecurityMetadataStore sec_meta_store) { _security_predicate = security_predicate; diff --git a/src/client/spark/Predicates/Data/Events/OrderEventPredicateHelper.cs b/src/client/spark/Predicates/Data/Events/OrderEventPredicateHelper.cs index 167cf8c1e..0c1c80873 100644 --- a/src/client/spark/Predicates/Data/Events/OrderEventPredicateHelper.cs +++ b/src/client/spark/Predicates/Data/Events/OrderEventPredicateHelper.cs @@ -10,13 +10,13 @@ namespace mbts { /// /// Checks if the order has transitioned from 'not passing the predicate, or not existing' to 'passing the predicate.' /// - public static bool check_order_transition_predicate(OrderSecurity order, Func order_predicate_core, IPredicate security_predicate, INotificationServiceDataCache data_cache) => + public static bool check_order_transition_predicate(OrderSecurity order, Func order_predicate_core, IPredicate security_predicate, INotificationServiceDataCache data_cache) => check_order_transition_trigger(order, order_predicate_core, security_predicate, data_cache, out var _); /// /// Checks if the order has transitioned from 'not passing the predicate, or not existing' to 'passing the predicate.' Oldval will be null if the order did not previously exist, or does not currently pass the predicate. /// - public static bool check_order_transition_trigger(OrderSecurity order, Func order_predicate_core, IPredicate security_predicate, INotificationServiceDataCache data_cache, out OrderSecurity? oldval) { + public static bool check_order_transition_trigger(OrderSecurity order, Func order_predicate_core, IPredicate security_predicate, INotificationServiceDataCache data_cache, out OrderSecurity? oldval) { if (check_security_predicate(order, security_predicate) && order_predicate_core(order.order)) { oldval = data_cache.get_previous_order_state(order.order.Key); return oldval == null ? !data_cache.is_first_order_update : !order_predicate_core(oldval.Value.order); @@ -28,7 +28,7 @@ namespace mbts { /// /// Checks if the 'security predicate is null,' or 'it is not null, and the order has a non-null security which passes.' /// - public static bool check_security_predicate(OrderSecurity order, IPredicate security_predicate) => + public static bool check_security_predicate(OrderSecurity order, IPredicate security_predicate) => security_predicate == null || (order.security.HasValue && security_predicate.trigger(order.security.Value)); public static OrderStatus? get_nullable_status(OrderSecurity? order) { @@ -41,11 +41,11 @@ namespace mbts { new OrderStatusTransitionPredicate(status, security_predicate?.create(), data_cache); class OrderStatusTransitionPredicate : IPredicate, IEquatable { - readonly IPredicate _security_predicate; + readonly IPredicate _security_predicate; readonly INotificationServiceDataCache _data_cache; readonly OrderStatus _status; - public OrderStatusTransitionPredicate(OrderStatus status, IPredicate security_predicate, INotificationServiceDataCache data_cache) { + public OrderStatusTransitionPredicate(OrderStatus status, IPredicate security_predicate, INotificationServiceDataCache data_cache) { _status = status; _security_predicate = security_predicate; _data_cache = data_cache; diff --git a/src/client/spark/Predicates/Data/Events/OrderFilledEventPredicate.cs b/src/client/spark/Predicates/Data/Events/OrderFilledEventPredicate.cs index 8bd70ffea..83e74efaf 100644 --- a/src/client/spark/Predicates/Data/Events/OrderFilledEventPredicate.cs +++ b/src/client/spark/Predicates/Data/Events/OrderFilledEventPredicate.cs @@ -66,10 +66,10 @@ new FillTriggerModel(nsdc, security?.create()); class FillTriggerModel { - readonly IPredicate _security_predicate; + readonly IPredicate _security_predicate; readonly INotificationServiceDataCache _data_cache; - public FillTriggerModel(INotificationServiceDataCache notification_service_data_cache, IPredicate security_predicate) { + public FillTriggerModel(INotificationServiceDataCache notification_service_data_cache, IPredicate security_predicate) { _data_cache = notification_service_data_cache; _security_predicate = security_predicate; } diff --git a/src/client/spark/Predicates/Data/OrderRecordTuplePredicate.cs b/src/client/spark/Predicates/Data/OrderRecordTuplePredicate.cs index d9f3ac373..6f06e1ee6 100644 --- a/src/client/spark/Predicates/Data/OrderRecordTuplePredicate.cs +++ b/src/client/spark/Predicates/Data/OrderRecordTuplePredicate.cs @@ -226,7 +226,7 @@ namespace mbts { public IPredicate create_predicate( INotificationServiceDataCache data_cache, ISecurityMetadataStore sec_meta_store) { switch (predicate_type_case) { - case PTOC.Security: return wrap(_security.create(), r => r.security ?? Security.Defaults.SecurityImmutable); + case PTOC.Security: return wrap(_security.create(), r => r.security); case PTOC.Time: return wrap(_time_created.create(), r => r.order.created()); case PTOC.LastChange: return wrap(_last_change.create(), r => r.order.last_change()); case PTOC.User: return wrap(_user.create(), r => r.order.user_id()); diff --git a/src/client/spark/Predicates/Data/SecurityPredicate.cs b/src/client/spark/Predicates/Data/SecurityPredicate.cs index 8adef5bea..4cd935fc8 100644 --- a/src/client/spark/Predicates/Data/SecurityPredicate.cs +++ b/src/client/spark/Predicates/Data/SecurityPredicate.cs @@ -48,7 +48,7 @@ _criteria == null ? PTOC.None : _negate ? PTOC.NotInCriteria : PTOC.InCriteria; - public IPredicate create() => _criteria.is_defined() ? new MyPredicate(_criteria, _negate) : null; + public IPredicate create() => _criteria.is_defined() ? new MyPredicate(_criteria, _negate) : null; public bool Equals(SecurityPredicate other) => other != null && @@ -69,7 +69,7 @@ _negate = negate; } - class MyPredicate : IPredicate { + class MyPredicate : IPredicate { readonly SecurityCriteria _criteria; readonly bool _negate; @@ -78,8 +78,11 @@ _negate = negate; } - public bool trigger(SecurityImmutable security) => _criteria.includes(security) != _negate; - public bool trigger(object obj) => obj is SecurityImmutable s && trigger(s); + public bool trigger(SecurityImmutable? security) => + security.HasValue && _criteria.includes(security.Value) != _negate; + + public bool trigger(object obj) => + obj is SecurityImmutable s && trigger(s); public bool Equals(MyPredicate other) => other != null && _criteria.Equals(other._criteria) && _negate == other._negate; diff --git a/src/client/spark/core/Bus/SparkTags.cs b/src/client/spark/core/Bus/SparkTags.cs index 991aa1050..a353d79d0 100644 --- a/src/client/spark/core/Bus/SparkTags.cs +++ b/src/client/spark/core/Bus/SparkTags.cs @@ -111,8 +111,8 @@ namespace mbts.spark { public static ITag ShowSyntheticCreateTag { get; } = _mk_tag(); - public static ITag ShowSyntheticStrategyTag { get; } = - _mk_tag(); + public static ITag ShowSyntheticStrategyTag { get; } = + _mk_tag(); public static ITag ShowSyntheticManagementTag { get; } = _mk_tag();