ui (reconcile rep): Match all undefined positions
Now, all positions without real non-zero quantities are considered matches
This commit is contained in:
1 parent
45987c7652
commit
fe6226baa5
5 files changed
+49
-16
No files matched your search
@@ -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);
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -85,6 +85,9 @@ namespace bts.utils {
|
||||
public static bool is_real_non_zero<T>(this T value) where T : IFloatingPoint<T> =>
|
||||
MathUtils.is_real_non_zero(value);
|
||||
|
||||
public static bool is_real_non_zero<T>(this T? value) where T : struct, IFloatingPoint<T> =>
|
||||
value.HasValue && MathUtils.is_real_non_zero(value.Value);
|
||||
|
||||
public static bool is_real_non_positive<T>(this T value) where T : IFloatingPoint<T> =>
|
||||
MathUtils.is_real_non_positive(value);
|
||||
|
||||
|
||||
@@ -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>(T argument, string name)
|
||||
where T : IFloatingPoint<T> {
|
||||
if (T.IsInfinity(argument)) {
|
||||
throw ExceptionBuilder.NumericArgument.must_not_be_infinity(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class InvalidOperation {
|
||||
|
||||
@@ -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>(T value) => $"{Messages.LessThan} {value}";
|
||||
public static string LessThan<T>(T value, T actual) => $"{Messages.LessThan} {value}";
|
||||
public static string LessThanOrEqualTo<T>(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";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user