diff --git a/src/client/spark/Orders/OrderDataHelper.cs b/src/client/spark/Orders/OrderDataHelper.cs index 21ed57abb..27df49a4c 100644 --- a/src/client/spark/Orders/OrderDataHelper.cs +++ b/src/client/spark/Orders/OrderDataHelper.cs @@ -304,6 +304,29 @@ namespace mbts.spark.utilities { public static OneofDescriptor oneof_descriptor => _oneof_desc; + const double _price_error_margin = 0.0000001; + const decimal _price_error_margin_decimal = 0.0000001m; + + public static readonly IComparer PriceComparer = Comparer.Create((a, b) => { + if (double.IsNaN(a)) { + return double.IsNaN(b) ? 0 : -1; + } else if (double.IsNaN(b)) { + return 1; + } else { + double diff = a - b; + if (diff <= _price_error_margin && diff >= -_price_error_margin) + return 0; + return diff > 0 ? 1 : -1; + } + }); + + public static readonly IComparer PriceComparerDecimal = Comparer.Create((a, b) => { + decimal diff = a - b; + if (diff <= _price_error_margin_decimal && diff >= -_price_error_margin_decimal) + return 0; + return diff > 0 ? 1 : -1; + }); + const string _primary_child_field = "child"; // algo-type-case maps // Note: obv this will break if we change the name of the 'CustomOneofCase' field