SPARK-1635 Ladder - position button should show "-" (NaN) for accounts with no orders (let 0 indicate the sum of fills is 0)

This commit is contained in:
John Colvin committed 2018-08-24 13:42:40 -04:00
1 parent ffc316f50c
commit d019ae287c
3 files changed
+10 -8

No files matched your search

+5 -3
View File
@@ -206,9 +206,11 @@ namespace mbts.spark {
public static IObservable<double> security_total_position(this OrdersModel orders_model, uint security_key, string account) =>
// PositionUnit.Account is actually the clearing account; this code assumes that clearing account and account are equivalent.
// However, it still must match account to PositionUnit.Account.Trimmed() because the exchange likes to slap spaces on the end.
orders_model.on_security_positions(security_key).filter(p => p.Account == account).Scan(0.0, (pos, table) =>
// the state should always have 1 element, since the PositionUnit-identity is security + account
pos + (table.added.Sum(p => p.total_pos()) - table.removed.Sum(p => p.total_pos())));
orders_model.on_security_positions(security_key)
.filter(p => p.Account == account)
// the state should always have 1 element, since the PositionUnit-identity is security + account
.Scan(0.0, (pos, table) => pos + (table.added.Sum(p => p.total_pos()) - table.removed.Sum(p => p.total_pos())))
.StartWith(double.NaN);
public static IObservable<ITableUpdateTransform<OrderRecordImmutable, uint>> on_security_root_orders(this OrdersModel orders_model, uint security_key) =>
orders_model.on_security_orders(security_key).Scan(new RootOrderData(), (rod, table) => {
@@ -13,18 +13,17 @@ namespace mbts.ui.converters
Minimum = Double.NaN;
Maximum = Double.NaN;
Multiplier = Double.NaN;
HideNaN = true;
}
public double Minimum { get; set; }
public double Maximum { get; set; }
public double Multiplier { get; set; }
public string Format { get; set; }
public bool HideNaN { get; set; }
public string NaNText { get; set; } = string.Empty;
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
var text = (value as string ?? string.Empty).Trim().ToLower();
if (text == string.Empty || text == "nan") return double.NaN;
if (text == string.Empty || text == "nan" || text == NaNText) return double.NaN;
if (double.TryParse(text, out double d) && !double.IsNaN(d)) {
if ((!double.IsNaN(Minimum) && d < Minimum) || (!double.IsNaN(Maximum) && d > Maximum)) return new ValidationResult(false, null);
return double.IsNaN(Multiplier) ? d : d / Multiplier;
@@ -40,7 +39,7 @@ namespace mbts.ui.converters
return string.IsNullOrEmpty(Format) ? d.ToString() : d.ToString(Format);
}
}
return HideNaN ? string.Empty : "NaN";
return NaNText;
}
}
@@ -26,6 +26,7 @@
</converters:BooleanToObjectConverter.ValueForFalse>
</converters:BooleanToObjectConverter>
<converters:EnumCharacterCasingConverter x:Key="casing_converter"/>
<converters:DoubleTextConverter x:Key="PositionTextConverter" Format="0" NaNText="-"/>
<Style TargetType="GridViewColumnHeader">
<Setter Property="Background" Value="{mbts:BTSColor header}"/>
<Setter Property="Foreground" Value="{mbts:BTSColor header_text}"/>
@@ -375,7 +376,7 @@
<Button
Margin="2"
Command="{Binding position_click_command}"
Content="{Binding position}"
Content="{Binding position, Converter={StaticResource PositionTextConverter}}"
FontWeight="Bold"
Foreground="{Binding position, Converter={StaticResource NumericSignBrushConverter}}"
>