From f22e68f4bc695b7b855ed392d2cd814da1890078 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Mon, 12 Aug 2019 12:46:42 -0500 Subject: [PATCH] added OrderDataHelper.PriceComparers for double and decimal --- src/client/spark/Orders/OrderDataHelper.cs | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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