fix: Remove refs to invalid 'default' SecurityImmutable

It's most (probably all) cases where a static 'default' SecurityImmutable is
used, a Nullable<SecurityImmutable> 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
This commit is contained in:
John Colvin committed 2022-09-15 15:39:38 -04:00
1 parent b3828dfc53
commit 612cd4a4c8
9 files changed
+30 -25

No files matched your search

@@ -114,9 +114,9 @@
_ask_merged_size = backing(nameof(ask_qty), 0u, convert_display_qty_uint);
_working_best_bid = new CellProperty<double>(
this, nameof(working_best_bid), fmt_price, double.NaN);
this, nameof(working_best_bid), format_price, double.NaN);
_working_best_ask = new CellProperty<double>(
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<OrderRecordImmutable, uint> 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();
@@ -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(
@@ -64,10 +64,10 @@ namespace mbts {
o.HasState && o.State.Status == OrderStatus.Canceled;
class MyToaster : INotificationPredicate<OrderSecurity>, IEquatable<MyToaster> {
readonly IPredicate<SecurityImmutable> _security_predicate;
readonly IPredicate<SecurityImmutable?> _security_predicate;
readonly INotificationServiceDataCache _data_cache;
public MyToaster(IPredicate<SecurityImmutable> security_predicate, INotificationServiceDataCache data_cache) {
public MyToaster(IPredicate<SecurityImmutable?> security_predicate, INotificationServiceDataCache data_cache) {
_security_predicate = security_predicate;
_data_cache = data_cache;
}
@@ -70,12 +70,12 @@ namespace mbts {
o.HasState && o.State.Status == OrderStatus.Completed;
class MyToaster : INotificationPredicate<OrderSecurity>, IEquatable<MyToaster> {
readonly IPredicate<SecurityImmutable> _security_predicate;
readonly IPredicate<SecurityImmutable?> _security_predicate;
readonly INotificationServiceDataCache _data_cache;
readonly ISecurityMetadataStore _sec_meta_store;
public MyToaster(
IPredicate<SecurityImmutable> security_predicate,
IPredicate<SecurityImmutable?> security_predicate,
INotificationServiceDataCache data_cache,
ISecurityMetadataStore sec_meta_store) {
_security_predicate = security_predicate;
@@ -10,13 +10,13 @@ namespace mbts {
/// <summary>
/// Checks if the order has transitioned from 'not passing the predicate, or not existing' to 'passing the predicate.'
/// </summary>
public static bool check_order_transition_predicate(OrderSecurity order, Func<OrderRecordImmutable, bool> order_predicate_core, IPredicate<SecurityImmutable> security_predicate, INotificationServiceDataCache data_cache) =>
public static bool check_order_transition_predicate(OrderSecurity order, Func<OrderRecordImmutable, bool> order_predicate_core, IPredicate<SecurityImmutable?> security_predicate, INotificationServiceDataCache data_cache) =>
check_order_transition_trigger(order, order_predicate_core, security_predicate, data_cache, out var _);
/// <summary>
/// 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.
/// </summary>
public static bool check_order_transition_trigger(OrderSecurity order, Func<OrderRecordImmutable, bool> order_predicate_core, IPredicate<SecurityImmutable> security_predicate, INotificationServiceDataCache data_cache, out OrderSecurity? oldval) {
public static bool check_order_transition_trigger(OrderSecurity order, Func<OrderRecordImmutable, bool> order_predicate_core, IPredicate<SecurityImmutable?> 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 {
/// <summary>
/// Checks if the 'security predicate is null,' or 'it is not null, and the order has a non-null security which passes.'
/// </summary>
public static bool check_security_predicate(OrderSecurity order, IPredicate<SecurityImmutable> security_predicate) =>
public static bool check_security_predicate(OrderSecurity order, IPredicate<SecurityImmutable?> 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<OrderSecurity>, IEquatable<OrderStatusTransitionPredicate> {
readonly IPredicate<SecurityImmutable> _security_predicate;
readonly IPredicate<SecurityImmutable?> _security_predicate;
readonly INotificationServiceDataCache _data_cache;
readonly OrderStatus _status;
public OrderStatusTransitionPredicate(OrderStatus status, IPredicate<SecurityImmutable> security_predicate, INotificationServiceDataCache data_cache) {
public OrderStatusTransitionPredicate(OrderStatus status, IPredicate<SecurityImmutable?> security_predicate, INotificationServiceDataCache data_cache) {
_status = status;
_security_predicate = security_predicate;
_data_cache = data_cache;
@@ -66,10 +66,10 @@
new FillTriggerModel(nsdc, security?.create());
class FillTriggerModel {
readonly IPredicate<SecurityImmutable> _security_predicate;
readonly IPredicate<SecurityImmutable?> _security_predicate;
readonly INotificationServiceDataCache _data_cache;
public FillTriggerModel(INotificationServiceDataCache notification_service_data_cache, IPredicate<SecurityImmutable> security_predicate) {
public FillTriggerModel(INotificationServiceDataCache notification_service_data_cache, IPredicate<SecurityImmutable?> security_predicate) {
_data_cache = notification_service_data_cache;
_security_predicate = security_predicate;
}
@@ -226,7 +226,7 @@ namespace mbts {
public IPredicate<OrderSecurity> 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());
@@ -48,7 +48,7 @@
_criteria == null ? PTOC.None :
_negate ? PTOC.NotInCriteria : PTOC.InCriteria;
public IPredicate<SecurityImmutable> create() => _criteria.is_defined() ? new MyPredicate(_criteria, _negate) : null;
public IPredicate<SecurityImmutable?> 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<SecurityImmutable> {
class MyPredicate : IPredicate<SecurityImmutable?> {
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;
+2 -2
View File
@@ -111,8 +111,8 @@ namespace mbts.spark {
public static ITag<SecurityCriteria> ShowSyntheticCreateTag { get; } = _mk_tag<SecurityCriteria>();
public static ITag<SecurityImmutable> ShowSyntheticStrategyTag { get; } =
_mk_tag<SecurityImmutable>();
public static ITag<uint> ShowSyntheticStrategyTag { get; } =
_mk_tag<uint>();
public static ITag<Nothing> ShowSyntheticManagementTag { get; } =
_mk_tag<Nothing>();