diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs b/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs index a623c5665..e5583491c 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs @@ -13,10 +13,8 @@ using System.Linq; using System.Reactive.Linq; using System.Windows.Input; -namespace mbts.spark -{ - partial class MarketViewVM - { +namespace mbts.spark { + partial class MarketViewVM { public class Row : SecurityMDRow, IDisposable { readonly IBus _bus; readonly OrdersModel _orders_model; @@ -28,7 +26,7 @@ namespace mbts.spark readonly Property _bid_size, _ask_size, _last_size; readonly Property _volume; readonly Property _inside_bids, _inside_asks; - readonly DelegateProperty _working_bid_volume, _working_ask_volume; + readonly DelegateProperty _working_bid_volume, _working_ask_volume; readonly DelegateProperty _working_best_bid, _working_best_ask; ulong _bbo_ref, _last_ref; @@ -88,8 +86,8 @@ namespace mbts.spark public double day_change => _day_change.Value; public double session_low => _session_low.Value; public double session_high => _session_high.Value; - public uint working_bid_volume => _working_bid_volume.Value; - public uint working_ask_volume => _working_ask_volume.Value; + public int working_bid_volume => _working_bid_volume.Value; + public int working_ask_volume => _working_ask_volume.Value; public string working_bids_text => OrderUtils.order_collection_summary(_working_bids, (x, y) => x.CompareTo(y), security.ContractSpec); public string working_asks_text => OrderUtils.order_collection_summary(_working_asks, (x, y) => y.CompareTo(x), security.ContractSpec); public double working_best_bid => _working_best_bid.Value; diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs b/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs index 45acd0134..75c7014c2 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs @@ -63,8 +63,8 @@ namespace mbts.spark public IDataGridColumnPersistentFilter session_low_filter { get; } = new DoubleMinMax(r => r.session_low, nameof(Row.session_low)); public IDataGridColumnPersistentFilter session_high_filter { get; } = new DoubleMinMax(r => r.session_high, nameof(Row.session_high)); public IDataGridColumnPersistentFilter position_filter { get; } = new IntMinMax(r => r.position, nameof(Row.position)); - public IDataGridColumnPersistentFilter working_bid_volume_filter { get; } = new UIntMinMax(r => r.working_bid_volume, nameof(Row.working_bid_volume)); - public IDataGridColumnPersistentFilter working_ask_volume_filter { get; } = new UIntMinMax(r => r.working_ask_volume, nameof(Row.working_ask_volume)); + public IDataGridColumnPersistentFilter working_bid_volume_filter { get; } = new IntMinMax(r => r.working_bid_volume, nameof(Row.working_bid_volume)); + public IDataGridColumnPersistentFilter working_ask_volume_filter { get; } = new IntMinMax(r => r.working_ask_volume, nameof(Row.working_ask_volume)); public IDataGridColumnPersistentFilter volume_filter { get; } = new ULongMinMax(r => r.volume, nameof(Row.volume)); public IDataGridColumnPersistentFilter security_key_filter { get; } = new RegexFinder(r => r.security_key.ToString(), nameof(Row.security_key)); diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs b/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs index ee3760521..c7212dbff 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewWindowFactory.cs @@ -9,10 +9,8 @@ using System.Reactive.Linq; using System.Threading.Tasks; using static mbts.spark.DataGridColumnFilters; -namespace bts.shell -{ - class MarketViewWindowFactory : ShellWindowFactory - { +namespace bts.shell { + class MarketViewWindowFactory : ShellWindowFactory { readonly IBus _bus; readonly OrdersModel _orders_model; @@ -76,9 +74,9 @@ namespace bts.shell [ProtoMember(12)] public IntMinMaxState position; [ProtoMember(13)] - public UIntMinMaxState working_bid_volume; + public IntMinMaxState working_bid_volume; [ProtoMember(14)] - public UIntMinMaxState working_ask_volume; + public IntMinMaxState working_ask_volume; [ProtoMember(15)] public ULongMinMaxState volume; [ProtoMember(16)] diff --git a/src/client/spark/view/Converters/Numeric/IntTextConverter.cs b/src/client/spark/view/Converters/Numeric/IntTextConverter.cs index 590d413d7..4a560a874 100644 --- a/src/client/spark/view/Converters/Numeric/IntTextConverter.cs +++ b/src/client/spark/view/Converters/Numeric/IntTextConverter.cs @@ -3,32 +3,42 @@ using System.Globalization; using System.Windows.Controls; using System.Windows.Data; -namespace mbts.ui.converters -{ - internal class IntTextConverter : IValueConverter - { +namespace mbts.ui.converters { + class IntTextConverter : IValueConverter { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { + if (!(value is int)) return new ValidationResult(false, null); + else return value.ToString(); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { + var text = value as string; + if (string.IsNullOrWhiteSpace(text) || !int.TryParse(text, out int result)) return new ValidationResult(false, null); + else return result; + } + } + + [ValueConversion(typeof(int?), typeof(string))] + class NullableIntTextConverter : IValueConverter { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => + value?.ToString(); + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { + var text = value as string; + if (string.IsNullOrWhiteSpace(text) || !int.TryParse(text, out int result)) return null; + else return result; + } + } + + [ValueConversion(typeof(int?), typeof(int))] + class NullableIntConverter : IValueConverter { + public int DefaultValue { get; set; } = 0; + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - if (!(value is int)) return new ValidationResult(false, null); - else return value.ToString(); + var ni = value as int?; + return ni.HasValue ? ni.Value : DefaultValue; } - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { - var text = value as string; - if (string.IsNullOrWhiteSpace(text) || !int.TryParse(text, out int result)) return new ValidationResult(false, null); - else return result; - } - } - - internal class NullableIntTextConverter : IValueConverter - { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - return value?.ToString(); - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { - var text = value as string; - if (string.IsNullOrWhiteSpace(text) || !int.TryParse(text, out int result)) return null; - else return result; - } + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => + value is int ? new int?((int)value) : null; } } \ No newline at end of file diff --git a/src/client/spark/view/Resources/Converters.xaml b/src/client/spark/view/Resources/Converters.xaml index 4f12cdb89..4d7b9e50b 100644 --- a/src/client/spark/view/Resources/Converters.xaml +++ b/src/client/spark/view/Resources/Converters.xaml @@ -39,9 +39,10 @@ + + - diff --git a/src/client/spark/view/Spark/Core/OrderUtils.cs b/src/client/spark/view/Spark/Core/OrderUtils.cs index f276d0a9a..037df5158 100644 --- a/src/client/spark/view/Spark/Core/OrderUtils.cs +++ b/src/client/spark/view/Spark/Core/OrderUtils.cs @@ -17,8 +17,8 @@ namespace mbts.spark { return filled(order) / (double)size; } - public static uint working_quantity(this OrderRecordImmutable order) => - order.State.Quantity > order.State.FilledQuantity ? order.State.Quantity - order.State.FilledQuantity : 0; + public static int working_quantity(this OrderRecordImmutable order) => + (int)order.State.Quantity - (int)order.State.FilledQuantity; public static string full_description(this OrderRecordImmutable order, SecurityImmutable security) { StringBuilder sb = new StringBuilder(); @@ -68,7 +68,7 @@ namespace mbts.spark { var best_price_volume = best_price.Sum(o => o.working_quantity()); return price_lookup.Count == 1 ? $"{spec.format(best_price.Key)} @ {best_price_volume}" : - $"{spec.format(best_price.Key)} @ {best_price_volume} ({best_price_volume + price_lookup.Skip(1).SelectMany(g => g).Sum(o => o.working_quantity())})"; + $"{spec.format(best_price.Key)} @ {best_price_volume} ({best_price_volume + price_lookup.Where(g => g.Key != best_price.Key).SelectMany(g => g).Sum(o => o.working_quantity())})"; } } } \ No newline at end of file diff --git a/src/client/spark/view/Spark/Ladder/OrderVM.cs b/src/client/spark/view/Spark/Ladder/OrderVM.cs index 539c19d28..b70ec800a 100644 --- a/src/client/spark/view/Spark/Ladder/OrderVM.cs +++ b/src/client/spark/view/Spark/Ladder/OrderVM.cs @@ -57,7 +57,7 @@ namespace mbts.spark { } public void update(OrderRecordImmutable neworder) { - Logger.assert(neworder.Key == id, $"OrderVM.update was called with an order with a different Key({neworder.Key}) than original({id})"); + Logger.assert(neworder.Key == id, $"OrderVM.update was called with an order with a different Key({neworder.Key}) from original({id})"); using (detect_property_changes()) _init(neworder); } @@ -70,7 +70,7 @@ namespace mbts.spark { public string text => ""; string _buy_sell_indicator => _order.Def.Side == Side.Buy ? "B" : "S"; public string line1 => $"{_buy_sell_indicator}:{OrderUtils.filled(_order)}"; - public string line2 => $"W:{_order.State.Quantity - OrderUtils.filled(_order)}"; + public string line2 => $"W:{_order.working_quantity()}"; public string summary => _order.short_description(_parent.security.ContractSpec); public string description => _order.full_description(_parent.security); diff --git a/src/client/spark/view/Spark/Orders/OrderModificationControl.xaml b/src/client/spark/view/Spark/Orders/OrderModificationControl.xaml index 4b0b6e06b..e2e695128 100644 --- a/src/client/spark/view/Spark/Orders/OrderModificationControl.xaml +++ b/src/client/spark/view/Spark/Orders/OrderModificationControl.xaml @@ -60,7 +60,7 @@ - + diff --git a/src/client/spark/view/Spark/Orders/OrderTicketVM.cs b/src/client/spark/view/Spark/Orders/OrderTicketVM.cs index b6dc0cabe..4941be144 100644 --- a/src/client/spark/view/Spark/Orders/OrderTicketVM.cs +++ b/src/client/spark/view/Spark/Orders/OrderTicketVM.cs @@ -101,7 +101,7 @@ namespace mbts.spark public double price { get; set; } = double.NaN; public double? working_price { get; set; } public CalculatorLogic size_calculator { get; } - public uint? working_size { get; set; } + public int? working_size { get; set; } public IEnumerable time_in_forces => EnumHelper.get_values(); public TimeInForce selected_time_in_force { get => _def.TimeInForce; set => _def = _def.with(time_in_force: value); } public string[] accounts { get; } @@ -135,9 +135,10 @@ namespace mbts.spark public readonly OrderDefinitionImmutable def; public readonly uint key; public readonly double? price, wprice; - public readonly uint? size, wsize; + public readonly uint? size; + public readonly int? wsize; - public OrderParams(SecurityMD smd, OrderDefinitionImmutable def, uint key=0, double? price=null, double? wprice=null, uint? size=null, uint? wsize=null) { + public OrderParams(SecurityMD smd, OrderDefinitionImmutable def, uint key=0, double? price=null, double? wprice=null, uint? size=null, int? wsize=null) { this.smd = smd; this.def = def; this.key = key; diff --git a/src/client/spark/view/Spark/Orders/OrdersModel.cs b/src/client/spark/view/Spark/Orders/OrdersModel.cs index c8bd0d10f..206698387 100644 --- a/src/client/spark/view/Spark/Orders/OrdersModel.cs +++ b/src/client/spark/view/Spark/Orders/OrdersModel.cs @@ -277,8 +277,8 @@ namespace mbts.spark if (lookup.success) { var o = lookup.result; if (o.State.Price == price) return true; - uint wq = o.working_quantity(); - if (wq != 0) return await orders_model.update_order(order, price, wq); + int wq = o.working_quantity(); + if (wq > 0) return await orders_model.update_order(order, price, (uint)wq); } return false; } @@ -287,9 +287,11 @@ namespace mbts.spark var lookup = await order_from_key(orders_model, order); if (lookup.success) { var o = lookup.result; - uint wq = o.working_quantity(); - if (wq == size) return true; - return await orders_model.update_order(order, o.State.Price, wq); + int wq = o.working_quantity(); + if (wq > 0) { + if (wq == size) return true; + return await orders_model.update_order(order, o.State.Price, (uint)wq); + } } return false; }