diff --git a/src/client/spark/Modules/Trading/ReconcileReport/ReconcileReportRowData.cs b/src/client/spark/Modules/Trading/ReconcileReport/ReconcileReportRowData.cs
index dc4d84423..647f64ea6 100644
--- a/src/client/spark/Modules/Trading/ReconcileReport/ReconcileReportRowData.cs
+++ b/src/client/spark/Modules/Trading/ReconcileReport/ReconcileReportRowData.cs
@@ -6,6 +6,8 @@ namespace Spark.Trading {
using bts.api.position;
using bts.utils;
+ using mbts.utils;
+
using Spark.Api.Position;
using System;
@@ -122,8 +124,35 @@ namespace Spark.Trading {
public static double sys_price(this ReconcileReportRowData rd) =>
rd.sys_position?.total_net_avg_price() ?? double.NaN;
+ public static bool has_exch_position(this ReconcileReportRowData rd) =>
+ (rd.exch_position?.Position).is_real_non_zero();
+
+ public static bool has_sys_position(this ReconcileReportRowData rd) =>
+ (rd.sys_position?.total_pos()).is_real_non_zero();
+
public static bool is_match(this ReconcileReportRowData rd) =>
- rd.sys_quantity().epsilon_equals(rd.exch_quantity()) &&
- rd.sys_price().epsilon_equals(rd.exch_price());
+ rd.match_type() ==
+ (ReconcileReportMatchType.Quantity | ReconcileReportMatchType.Price);
+
+ ///
+ /// Determines which components of the system/exchange positions (if any) match. If both
+ /// positions are undefined (i.e., the quantity is finite positive), then the position is
+ /// considered a proper match, and both the 'price' and 'quantity' flags are returned.
+ ///
+ public static ReconcileReportMatchType match_type(this ReconcileReportRowData rd) {
+ if (!rd.has_exch_position() && !rd.has_sys_position()) {
+ return ReconcileReportMatchType.Price | ReconcileReportMatchType.Quantity;
+ }
+
+ var mt = ReconcileReportMatchType.None;
+ // allow for rounding error
+ if (rd.sys_quantity().epsilon_equals(rd.exch_quantity())) {
+ mt |= ReconcileReportMatchType.Quantity;
+ }
+ if (rd.sys_price().epsilon_equals(rd.exch_price())) {
+ mt |= ReconcileReportMatchType.Price;
+ }
+ return mt;
+ }
}
}
diff --git a/src/client/spark/Modules/Trading/ReconcileReport/ReconcileReportRowVM.cs b/src/client/spark/Modules/Trading/ReconcileReport/ReconcileReportRowVM.cs
index 6303801f4..7297189aa 100644
--- a/src/client/spark/Modules/Trading/ReconcileReport/ReconcileReportRowVM.cs
+++ b/src/client/spark/Modules/Trading/ReconcileReport/ReconcileReportRowVM.cs
@@ -55,18 +55,7 @@ namespace Spark.Trading {
public double exchange_quantity => _data.exch_quantity();
public double price => _data.sys_price();
public double exchange_price => _data.exch_price();
- public ReconcileReportMatchType match_type {
- get {
- var mt = ReconcileReportMatchType.None;
- if (quantity.epsilon_equals(exchange_quantity)) {
- mt |= ReconcileReportMatchType.Quantity;
- }
- if (price.epsilon_equals(exchange_price)) {
- mt |= ReconcileReportMatchType.Price;
- }
- return mt;
- }
- }
+ public ReconcileReportMatchType match_type => _data.match_type();
public bts.api.domain.TickDisplaySettingsImmutable quantity_display {
get => _quantity_display;
@@ -79,7 +68,7 @@ namespace Spark.Trading {
}
public bool is_match =>
- quantity.epsilon_equals(exchange_quantity) && price.epsilon_equals(exchange_price);
+ _data.is_match();
public bool has_system_position => _data.sys_position.HasValue;
public bool has_exchange_position => _data.exch_position.HasValue;
diff --git a/src/client/spark_api/utils/NumericExtensions.cs b/src/client/spark_api/utils/NumericExtensions.cs
index 517cebd27..2244fd8e1 100644
--- a/src/client/spark_api/utils/NumericExtensions.cs
+++ b/src/client/spark_api/utils/NumericExtensions.cs
@@ -85,6 +85,9 @@ namespace bts.utils {
public static bool is_real_non_zero(this T value) where T : IFloatingPoint =>
MathUtils.is_real_non_zero(value);
+ public static bool is_real_non_zero(this T? value) where T : struct, IFloatingPoint =>
+ value.HasValue && MathUtils.is_real_non_zero(value.Value);
+
public static bool is_real_non_positive(this T value) where T : IFloatingPoint =>
MathUtils.is_real_non_positive(value);
diff --git a/src/client/spark_core/utils/Exceptions/ExceptionAssert.cs b/src/client/spark_core/utils/Exceptions/ExceptionAssert.cs
index 195325359..af623ee40 100644
--- a/src/client/spark_core/utils/Exceptions/ExceptionAssert.cs
+++ b/src/client/spark_core/utils/Exceptions/ExceptionAssert.cs
@@ -1,4 +1,4 @@
-using bts.utils;
+using bts.utils;
using System;
using System.Collections.Generic;
@@ -139,6 +139,13 @@ namespace mbts.utils {
throw ExceptionBuilder.NumericArgument.must_be_real_non_positive(name);
}
}
+
+ public static void not_infinity(T argument, string name)
+ where T : IFloatingPoint {
+ if (T.IsInfinity(argument)) {
+ throw ExceptionBuilder.NumericArgument.must_not_be_infinity(name);
+ }
+ }
}
public static class InvalidOperation {
diff --git a/src/client/spark_core/utils/Exceptions/ExceptionBuilder.cs b/src/client/spark_core/utils/Exceptions/ExceptionBuilder.cs
index 2bb121620..be4bd8190 100644
--- a/src/client/spark_core/utils/Exceptions/ExceptionBuilder.cs
+++ b/src/client/spark_core/utils/Exceptions/ExceptionBuilder.cs
@@ -42,6 +42,9 @@ namespace mbts.utils {
public static ArgumentException must_be_real_positive(string name) =>
new(Format.MustBe(NumericTerms.real_positive()), name);
+
+ public static ArgumentException must_not_be_infinity(string name) =>
+ new(Format.must_not_be(NumericTerms.not_infinity()), name);
}
public static class IndexOutOfRange {
@@ -71,6 +74,7 @@ namespace mbts.utils {
public static class Format {
public static string MustBe(string condition) => $"Must be {condition}";
+ public static string must_not_be(string condition) => $"Must not be {condition}";
public static string LessThan(T value) => $"{Messages.LessThan} {value}";
public static string LessThan(T value, T actual) => $"{Messages.LessThan} {value}";
public static string LessThanOrEqualTo(T value) => $"{Messages.LessThanOrEqualTo} {value}";
@@ -107,6 +111,7 @@ namespace mbts.utils {
public static string real_non_positive() => "real non-positive";
public static string real_positive() => "real positive";
public static string real_negative() => "real negative";
+ public static string not_infinity() => "not infinity";
}
}
}