diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs b/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs index b87ccf35f..2d782efa7 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs @@ -42,7 +42,7 @@ namespace mbts.spark { _orders_model = orders_model; _security_text = smd.security.ToString(); _security_key_text = security_key.ToString(); - string format_price(double price) => security.format(price); + string format_price(double price) => security.ContractSpec.format(price); _position = new CellProperty(0); _bid_price = backing(nameof(bid_price), double.NaN); _ask_price = backing(nameof(ask_price), double.NaN); @@ -106,8 +106,8 @@ namespace mbts.spark { public double session_high => _session_high.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(_order_summarizer.best_working_bid, _order_summarizer.best_working_bid_qty, _order_summarizer.working_bid_qty, security); - public string working_asks_text => OrderUtils.order_collection_summary(_order_summarizer.best_working_ask, _order_summarizer.best_working_ask_qty, _order_summarizer.working_ask_qty, security); + public string working_bids_text => OrderUtils.order_collection_summary(_order_summarizer.best_working_bid, _order_summarizer.best_working_bid_qty, _order_summarizer.working_bid_qty, security.ContractSpec); + public string working_asks_text => OrderUtils.order_collection_summary(_order_summarizer.best_working_ask, _order_summarizer.best_working_ask_qty, _order_summarizer.working_ask_qty, security.ContractSpec); public double working_best_bid => _working_best_bid.value; public double working_best_ask => _working_best_ask.value; public IList animations => _animation.get_animations().ToList(); diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs b/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs index a4209a52e..24100958e 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewVM.cs @@ -76,7 +76,7 @@ namespace mbts.spark { BindingBase price_binding(string prop) { var mb = new MultiBinding { Converter = price_converter }; mb.Bindings.Add(new Binding(prop) { Mode = BindingMode.OneWay }); - mb.Bindings.Add(new Binding($"{nameof(Row.security)}") { Mode = BindingMode.OneWay }); + mb.Bindings.Add(new Binding($"{nameof(Row.security)}.{nameof(SecurityImmutable.ContractSpec)}") { Mode = BindingMode.OneWay }); return mb; } // diff --git a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesVM.cs b/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesVM.cs index 86c7db401..2d5a8ea8e 100644 --- a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesVM.cs +++ b/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesVM.cs @@ -101,7 +101,7 @@ namespace mbts.spark { show_ladder = new DelegateCommand(() => parent._show_ladder_async(this).ignore()); _security_text = security.ToString(); _time_text = time.ToString("M/d h:mm:ss tt"); - _price_text = security.format(price); + _price_text = security.ContractSpec.format(price); _size_text = size.ToString(); _trade_key_text = _trade_key.ToString(); _security_key_text = security_key.ToString(); diff --git a/src/client/spark/Orders/OrderActivitySummarizer.cs b/src/client/spark/Orders/OrderActivitySummarizer.cs index 1ea102cac..98e6d7375 100644 --- a/src/client/spark/Orders/OrderActivitySummarizer.cs +++ b/src/client/spark/Orders/OrderActivitySummarizer.cs @@ -38,23 +38,23 @@ namespace bts.spark { #region formatting - SecurityImmutable? get_security(uint security_key) { + (SecurityImmutable?, ContractSpecificationImmutable?) get_security(uint security_key) { if (_security.TryGetValue(security_key, out SecurityMD md)) { - return md.security; + return (md.security, md.security.ContractSpec); } - return null; + return (null, null); } - string format_order_success(uint key, double price, uint size, Side side, SecurityImmutable? security) { - return $"({key}) {side.ToString().ToLower()} {size} @ {security.format(price)}"; + string format_order_success(uint key, double price, uint size, Side side, ContractSpecificationImmutable? spec) { + return $"({key}) {side.ToString().ToLower()} {size} @ {spec.format(price)}"; } - string format_order_fail(double price, uint size, Side side, SecurityImmutable? security, string error) { - return $"Failed to {side.ToString().ToLower()} {size} @ {security.format(price)}. {error}"; + string format_order_fail(double price, uint size, Side side, ContractSpecificationImmutable? spec, string error) { + return $"Failed to {side.ToString().ToLower()} {size} @ {spec.format(price)}. {error}"; } - string format_cancel_success(OrderRecordImmutable order, SecurityImmutable? security) { - return $"({order.Key}) Canceled {order.short_description(security)}, was working {order.working_quantity()}"; + string format_cancel_success(OrderRecordImmutable order, ContractSpecificationImmutable? spec) { + return $"({order.Key}) Canceled {order.short_description(spec)}, was working {order.working_quantity()}"; } - string format_cancel_error(OrderRecordImmutable order, SecurityImmutable? security, string error) { - return $"({order.Key}) Failed to cancel {order.short_description(security)}: {error}"; + string format_cancel_error(OrderRecordImmutable order, ContractSpecificationImmutable? spec, string error) { + return $"({order.Key}) Failed to cancel {order.short_description(spec)}: {error}"; } string format_fill_summary(OrderRecordImmutable before, OrderRecordImmutable after) { int fb = (int)before.State.FilledQuantity; @@ -65,14 +65,14 @@ namespace bts.spark { return $"({key}) Status changed from {old_status} to {new_status}"; } - public static string modified_description(OrderRecordImmutable old_order, OrderRecordImmutable new_order, SecurityImmutable? security) { + public static string modified_description(OrderRecordImmutable old_order, OrderRecordImmutable new_order, ContractSpecificationImmutable? spec) { double old_price = old_order.State.Price, new_price = new_order.State.Price; uint old_size = old_order.State.Quantity, new_size = new_order.State.Quantity; string modified_size_partial_description(int working_size) { return $"size from {old_size} to {new_size}, working {working_size}"; } string modified_price_partial_description() { - return $"price from {security.format(old_price)} to {security.format(new_price)}"; + return $"price from {spec.format(old_price)} to {spec.format(new_price)}"; } if (old_price != new_price || old_size != new_size) { StringBuilder sb = new StringBuilder($"({old_order.Key}) Changed "); @@ -102,7 +102,7 @@ namespace bts.spark { foreach (var order in added) { if (!string.IsNullOrEmpty(order.State.LastMsg) && order.State.Created.ToDateTime().Date == DateTime.Today) { - var security = get_security(order.Def.SecurityKey); + (var security, var spec) = get_security(order.Def.SecurityKey); if (security.HasValue) { log_status(ActivityLogCategory.warn, security, order.State.LastMsg); } @@ -111,10 +111,10 @@ namespace bts.spark { foreach (var neworder in changed) { var oldorder = removed[neworder.Key]; - var security = get_security(neworder.Def.SecurityKey); + (var security, var spec) = get_security(neworder.Def.SecurityKey); // // description - var mod_desc = modified_description(oldorder, neworder, security); + var mod_desc = modified_description(oldorder, neworder, spec); if (!string.IsNullOrEmpty(mod_desc)) { log_status(ActivityLogCategory.modify, security, mod_desc); } @@ -145,31 +145,31 @@ namespace bts.spark { } internal void on_send_order(OrderDefinitionImmutable order, double price, uint size, uint? key, string error) { - var security = get_security(order.SecurityKey); + (var security, var spec) = get_security(order.SecurityKey); log_status(ActivityLogCategory.order, security, key.HasValue ? - format_order_success(key.Value, price, size, order.Side, security) : - format_order_fail(price, size, order.Side, security, error)); + format_order_success(key.Value, price, size, order.Side, spec) : + format_order_fail(price, size, order.Side, spec, error)); } internal void on_cancel_order(OrderRecordImmutable order, bool success, string error) { - var security = get_security(order.Def.SecurityKey); + (var security, var spec) = get_security(order.Def.SecurityKey); log_status(ActivityLogCategory.cancel, security, success ? - format_cancel_success(order, security): - format_cancel_error(order, security, error)); + format_cancel_success(order, spec): + format_cancel_error(order, spec, error)); } internal void update_order(OrderRecordImmutable order, double price, uint size) { - var security = get_security(order.Def.SecurityKey); + (var security, var spec) = get_security(order.Def.SecurityKey); log_status(ActivityLogCategory.modify, security, - $"({order.Key}) change from {order.State.Quantity}@{security.format(order.State.Price)} to {size}@{security.format(price)}"); + $"({order.Key}) change from {order.State.Quantity}@{spec.format(order.State.Price)} to {size}@{spec.format(price)}"); } internal void update_order_failed(OrderRecordImmutable order, double price, uint size) { - var security = get_security(order.Def.SecurityKey); + (var security, var spec) = get_security(order.Def.SecurityKey); log_status(ActivityLogCategory.modify, security, - $"({order.Key}) failed to change from {order.State.Quantity}@{security.format(order.State.Price)} to {size}@{security.format(price)}"); + $"({order.Key}) failed to change from {order.State.Quantity}@{spec.format(order.State.Price)} to {size}@{spec.format(price)}"); } } diff --git a/src/client/spark/Orders/OrderModificationControl.xaml b/src/client/spark/Orders/OrderModificationControl.xaml index 15b07348b..5aedfca87 100644 --- a/src/client/spark/Orders/OrderModificationControl.xaml +++ b/src/client/spark/Orders/OrderModificationControl.xaml @@ -74,7 +74,7 @@ - + diff --git a/src/client/spark/Orders/OrderModificationDialog.xaml b/src/client/spark/Orders/OrderModificationDialog.xaml index c329b2372..d35448046 100644 --- a/src/client/spark/Orders/OrderModificationDialog.xaml +++ b/src/client/spark/Orders/OrderModificationDialog.xaml @@ -77,7 +77,7 @@ - + @@ -85,7 +85,7 @@ - + diff --git a/src/client/spark/Orders/OrderTicket.xaml b/src/client/spark/Orders/OrderTicket.xaml index 907b8a094..c51185737 100644 --- a/src/client/spark/Orders/OrderTicket.xaml +++ b/src/client/spark/Orders/OrderTicket.xaml @@ -126,7 +126,7 @@ - + @@ -134,7 +134,7 @@ - + diff --git a/src/client/spark/Orders/OrderTypeVMs/StopLimitOrderVM.cs b/src/client/spark/Orders/OrderTypeVMs/StopLimitOrderVM.cs index 582ca2663..c2fb47863 100644 --- a/src/client/spark/Orders/OrderTypeVMs/StopLimitOrderVM.cs +++ b/src/client/spark/Orders/OrderTypeVMs/StopLimitOrderVM.cs @@ -1,6 +1,7 @@ using bts.api; using bts.api.orderman; - +using mbts.spark.utilities; +using mbts.utils; namespace mbts.spark { static partial class OrderTypeVMFactory { private class StopLimitOrderVM : OrderTypeVMBase { @@ -16,8 +17,8 @@ namespace mbts.spark { } } - public SecurityImmutable security { get; private set; } = - SecurityDataHelper.Defaults.Security; + public ContractSpecificationImmutable spec { get; private set; } = + SecurityDataHelper.Defaults.ContractSpecificationImmutable; public override void assign_to(CustomOrderDefinition value) { if (!HasErrors) { diff --git a/src/client/spark/view/Controls/DIYGrid/CellRender/PriceCell.cs b/src/client/spark/view/Controls/DIYGrid/CellRender/PriceCell.cs index 14af77732..52578cdf8 100644 --- a/src/client/spark/view/Controls/DIYGrid/CellRender/PriceCell.cs +++ b/src/client/spark/view/Controls/DIYGrid/CellRender/PriceCell.cs @@ -21,7 +21,7 @@ namespace mbts.ui.controls { double _glyph_width, _font_size, _value; GlyphRun _glyph_run; GlyphContext _glyph_context; - SecurityImmutable _security; + ContractSpecificationImmutable _spec; static PriceCell() => WPFHelper.override_metadata( @@ -41,7 +41,7 @@ namespace mbts.ui.controls { _padding = Padding; _font_size = FontSize; _value = Value; - _security = Security; + _spec = ContractSpec; _glyph_context = GlyphContext.create(FontFamily, FontWeight); } @@ -147,20 +147,20 @@ namespace mbts.ui.controls { public double Value { get => (double)GetValue(ValueProperty); set => SetValue(ValueProperty, value); } #endregion - #region Security - public static readonly DependencyProperty SecurityProperty = - WPFHelper.create_dp( - nameof(Security), + #region ContractSpec + public static readonly DependencyProperty ContractSpecProperty = + WPFHelper.create_dp( + nameof(ContractSpec), FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender, (p, v) => { - p._security = v; + p._spec = v; p._glyph_run = null; - }, SecurityDataHelper.Defaults.SecurityImmutable); + }, SecurityDataHelper.Defaults.ContractSpecificationImmutable); - public SecurityImmutable Security { - get => (SecurityImmutable)GetValue(SecurityProperty); - set => SetValue(SecurityProperty, value); + public ContractSpecificationImmutable ContractSpec { + get => (ContractSpecificationImmutable)GetValue(ContractSpecProperty); + set => SetValue(ContractSpecProperty, value); } #endregion @@ -178,7 +178,7 @@ namespace mbts.ui.controls { } void _set_glyph(Size size) { - _glyph_run = _glyph_context.get_glyph_run(_security.format(_value), _font_size, size, _horizontal_alignment, VerticalAlignment.Center, _padding); + _glyph_run = _glyph_context.get_glyph_run(_spec.format(_value), _font_size, size, _horizontal_alignment, VerticalAlignment.Center, _padding); _glyph_width = _glyph_run == null ? 0 : _glyph_run.AdvanceWidths.Sum(); } diff --git a/src/client/spark/view/Controls/DIYGrid/Columns/FrameworkElementColumns/PriceColumn.cs b/src/client/spark/view/Controls/DIYGrid/Columns/FrameworkElementColumns/PriceColumn.cs index 98740af1f..d38b95eef 100644 --- a/src/client/spark/view/Controls/DIYGrid/Columns/FrameworkElementColumns/PriceColumn.cs +++ b/src/client/spark/view/Controls/DIYGrid/Columns/FrameworkElementColumns/PriceColumn.cs @@ -22,7 +22,7 @@ namespace mbts.ui.controls { public override FrameworkElement view_factory() { var v = new PriceCell(); v.SetBinding(PriceCell.ValueProperty, _binding_factory()); - v.SetBinding(PriceCell.SecurityProperty, _spec_binding_factory()); + v.SetBinding(PriceCell.ContractSpecProperty, _spec_binding_factory()); return v; } } diff --git a/src/client/spark/view/Controls/Order/OrderDetailsPopupControl.xaml b/src/client/spark/view/Controls/Order/OrderDetailsPopupControl.xaml index 8267e375f..0e8969a2a 100644 --- a/src/client/spark/view/Controls/Order/OrderDetailsPopupControl.xaml +++ b/src/client/spark/view/Controls/Order/OrderDetailsPopupControl.xaml @@ -70,7 +70,7 @@ Stop Price - + @@ -82,7 +82,7 @@ Stop Price - + diff --git a/src/client/spark/view/Controls/PriceEntryControl.xaml.cs b/src/client/spark/view/Controls/PriceEntryControl.xaml.cs index a73750489..b02202ec9 100644 --- a/src/client/spark/view/Controls/PriceEntryControl.xaml.cs +++ b/src/client/spark/view/Controls/PriceEntryControl.xaml.cs @@ -107,4 +107,4 @@ namespace mbts.ui.spark { } } } -} +} \ No newline at end of file diff --git a/src/client/spark/view/Converters/TickDisplayConverter.cs b/src/client/spark/view/Converters/TickDisplayConverter.cs index 822ea1008..c46772891 100644 --- a/src/client/spark/view/Converters/TickDisplayConverter.cs +++ b/src/client/spark/view/Converters/TickDisplayConverter.cs @@ -16,9 +16,9 @@ namespace mbts.ui.spark.converters { } public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { var price = get_val(values, 0); - var security = get_val(values, 1); - if (security == null) return price.ToString(); - return security.Value.format(price); + var spec = get_val(values, 1); + if (spec == null) return price.ToString(); + return spec.Value.format(price); } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) => @@ -26,17 +26,16 @@ namespace mbts.ui.spark.converters { } class TickDisplayTwoWayConverter : IValueConverter { - public SecurityImmutable? Security { get; set; } = - SecurityDataHelper.Defaults.SecurityImmutable; + public ContractSpecificationImmutable? ContractSpec { get; set; } = SecurityDataHelper.Defaults.ContractSpecificationImmutablePennies; public double DisplayMultiplier { get; set; } = double.NaN; public bool ShowCommas { get; set; } = false; public string NaNText { get; set; } = string.Empty; public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => - Security.format((double)value, DisplayMultiplier, ShowCommas, NaNText); + ContractSpec.format((double)value, DisplayMultiplier, ShowCommas, NaNText); public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => - Security.parse(value as string, DisplayMultiplier, NaNText); + ContractSpec.parse(value as string, DisplayMultiplier, NaNText); } } \ No newline at end of file diff --git a/src/client/spark/view/Spark/Core/OrderUtils.cs b/src/client/spark/view/Spark/Core/OrderUtils.cs index bcff6111e..71689bd8b 100644 --- a/src/client/spark/view/Spark/Core/OrderUtils.cs +++ b/src/client/spark/view/Spark/Core/OrderUtils.cs @@ -1,6 +1,8 @@ using bts.api; using bts.api.orderman; using System; +using System.Collections.Generic; +using System.Linq; using System.Text; using System.Text.RegularExpressions; using static mbts.ui.utilities.DisplayNameHelper; @@ -73,7 +75,7 @@ namespace mbts.spark { if (order.HasDef) { sec_key_text = $"Security: {order.Def.SecurityKey}"; if (order.HasState) { - sb.AppendLine($"{order.Def.Side}: {security.format(order.State.Price)}"); + sb.AppendLine($"{order.Def.Side}: {TickUtils.format(security.ContractSpec, order.State.Price)}"); sb.AppendLine($"Filled: {filled(order)} / {order.State.Quantity}"); } else { sb.AppendLine($"{order.Def.Side}: (price-unknown)"); @@ -95,8 +97,8 @@ namespace mbts.spark { return sb.ToString(); } - public static string short_description(this OrderRecordImmutable order, SecurityImmutable? security) => - $"{(order.HasDef ? order.Def.Side.ToString() : "(unknown-side)")} {(order.HasState ? ($@"{security.format(order.State.Price)} @ {order.State.Quantity}") : "(unknown-price) @ (unknown-quantity)")}"; + public static string short_description(this OrderRecordImmutable order, ContractSpecificationImmutable? spec) => + $"{(order.HasDef ? order.Def.Side.ToString() : "(unknown-side)")} {(order.HasState ? ($@"{spec.format(order.State.Price)} @ {order.State.Quantity}") : "(unknown-price) @ (unknown-quantity)")}"; public static bool has_parent(this OrderRecordImmutable order) => order.ParentKey != 0; @@ -119,12 +121,12 @@ namespace mbts.spark { public static string order_type_display_name(CustomOrderDefinition.CustomOneofCase order_type) => camel_to_title_case(Regex.Replace(order_type.ToString(), "Order", string.Empty, RegexOptions.IgnoreCase)); - public static string order_collection_summary(double best_price, int best_price_volume, int total_volume, SecurityImmutable security) { + public static string order_collection_summary(double best_price, int best_price_volume, int total_volume, ContractSpecificationImmutable spec) { if (total_volume == 0) return string.Empty; return total_volume == best_price_volume ? - $"{best_price_volume} @ {security.format(best_price)}" : - $"{best_price_volume} ({total_volume}) @ {security.format(best_price)}"; + $"{best_price_volume} @ {spec.format(best_price)}" : + $"{best_price_volume} ({total_volume}) @ {spec.format(best_price)}"; } public static string past_tense(this Side side) { diff --git a/src/client/spark/view/Spark/Grid/ISecurityRow.cs b/src/client/spark/view/Spark/Grid/ISecurityRow.cs index 88c97b79d..681460b68 100644 --- a/src/client/spark/view/Spark/Grid/ISecurityRow.cs +++ b/src/client/spark/view/Spark/Grid/ISecurityRow.cs @@ -14,6 +14,6 @@ namespace mbts.spark { static class SecurityRowExtensions { public static string format_price(this ISecurityRow row, double price) => - row.security.format(price); + row.security.ContractSpec.format(price); } } \ No newline at end of file diff --git a/src/client/spark/view/Spark/Ladder/LadderGridHost.cs b/src/client/spark/view/Spark/Ladder/LadderGridHost.cs index 4f9fc21b9..f2a4b069f 100644 --- a/src/client/spark/view/Spark/Ladder/LadderGridHost.cs +++ b/src/client/spark/view/Spark/Ladder/LadderGridHost.cs @@ -306,13 +306,13 @@ namespace mbts.spark { _settings.row_height, _price_list, column.settings, - security); + security.ContractSpec); break; case ColumnType.Ask: render_market_col(_asks); break; } void render_market_col(NativePriceSize[] depth) { var mid = LadderRender.index_of(_price_list, _last_origin_price, _price_comparer); - LadderRender.render_sizes(column.visual_tup.visual, column.visual_tup.glyph_context, mid, _price_list, depth, _settings.row_height, security, column.settings); + LadderRender.render_sizes(column.visual_tup.visual, column.visual_tup.glyph_context, mid, _price_list, depth, _settings.row_height, security.ContractSpec, column.settings); } } _apply_column_visual_offset(); @@ -390,8 +390,8 @@ namespace mbts.spark { SparkUtils.lazy_warn(!double.IsNaN(_mkt_break_lines.origin) && _mkt_break_lines.origin >= low && _mkt_break_lines.origin <= high, () => fmt_log_msg($"market break ({_mkt_break_lines.origin}) is unacceptable for the market range ({low} - {high})")); int prev_row_count = _row_count; - int n_ticks_to_low = TickUtils.normalized_tick_diff(security, _mkt_break_lines.origin, low); - int n_ticks_to_high = TickUtils.normalized_tick_diff(security, high, _mkt_break_lines.origin); + int n_ticks_to_low = TickUtils.normalized_tick_diff(security.ContractSpec, _mkt_break_lines.origin, low); + int n_ticks_to_high = TickUtils.normalized_tick_diff(security.ContractSpec, high, _mkt_break_lines.origin); int desired_row_count = Math.Max(n_ticks_to_low, n_ticks_to_high) * 2 + 1; _row_count = Math.Min(_max_row_count, desired_row_count); if (_row_count != prev_row_count) { @@ -412,7 +412,7 @@ namespace mbts.spark { } if (update_prices) { var prev_price_list = _price_list; - _price_list = LadderRender.render_prices(_price_vis_tup.visual, _price_vis_tup.glyph_context, _mkt_break_lines.origin, _row_count, _settings.row_height, _settings.price_column, security); + _price_list = LadderRender.render_prices(_price_vis_tup.visual, _price_vis_tup.glyph_context, _mkt_break_lines.origin, _row_count, _settings.row_height, _settings.price_column, security.ContractSpec); _ordershost.update_settings(_price_list, _price_comparer, _settings.row_height, _settings.orders_column); if (prev_price_list != null) { // maintain previous visible price range if possible @@ -447,8 +447,8 @@ namespace mbts.spark { if (update_prices || depth_changed) { Logger.assert_d(_price_list != null); int origin_index = LadderRender.index_of(_price_list, _mkt_break_lines.origin, _price_comparer); - LadderRender.render_sizes(_bid_vis_tup.visual, _bid_vis_tup.glyph_context, origin_index, _price_list, _bids, _settings.row_height, security, _settings.bid_column); - LadderRender.render_sizes(_ask_vis_tup.visual, _ask_vis_tup.glyph_context, origin_index, _price_list, _asks, _settings.row_height, security, _settings.ask_column); + LadderRender.render_sizes(_bid_vis_tup.visual, _bid_vis_tup.glyph_context, origin_index, _price_list, _bids, _settings.row_height, security.ContractSpec, _settings.bid_column); + LadderRender.render_sizes(_ask_vis_tup.visual, _ask_vis_tup.glyph_context, origin_index, _price_list, _asks, _settings.row_height, security.ContractSpec, _settings.ask_column); } _last_origin_price = _mkt_break_lines.origin; _price_dirty = false; @@ -472,7 +472,7 @@ namespace mbts.spark { double best_bid = _get_top_price(_bids); double best_ask = _get_top_price(_asks); return double.IsNaN(best_bid) ? - double.IsNaN(best_ask) ? _vm.low : security.tickdown(best_ask) : + double.IsNaN(best_ask) ? _vm.low : security.ContractSpec.tickdown(best_ask) : best_bid; } @@ -480,15 +480,15 @@ namespace mbts.spark { double best_bid = _get_top_price(_bids); double best_ask = _get_top_price(_asks); return double.IsNaN(best_ask) ? - double.IsNaN(best_bid) ? security.tickdown(_vm.high) : best_bid : - security.tickdown(best_ask); + double.IsNaN(best_bid) ? security.ContractSpec.tickdown(_vm.high) : best_bid : + security.ContractSpec.tickdown(best_ask); } double _get_mid_market_break() { double best_bid = _get_top_price(_bids); double best_ask = _get_top_price(_asks); return double.IsNaN(best_bid) ? - double.IsNaN(best_ask) ? 0.5 * (_vm.low + _vm.high) : security.tickdown(best_ask) : + double.IsNaN(best_ask) ? 0.5 * (_vm.low + _vm.high) : security.ContractSpec.tickdown(best_ask) : double.IsNaN(best_ask) ? best_bid : TickUtils.mid_tick(security.ContractSpec, best_bid, best_ask); } diff --git a/src/client/spark/view/Spark/Ladder/LadderOrderVM.cs b/src/client/spark/view/Spark/Ladder/LadderOrderVM.cs index ef4189c3b..4ab0a8dbb 100644 --- a/src/client/spark/view/Spark/Ladder/LadderOrderVM.cs +++ b/src/client/spark/view/Spark/Ladder/LadderOrderVM.cs @@ -98,7 +98,7 @@ namespace mbts.spark { if (_orders.Count > 0) { - summary = _orders.Values.Select(order => order.short_description(_parent.security)).Aggregate((s1, s2) => $"{s1}{Environment.NewLine}{Environment.NewLine}{s2}"); + summary = _orders.Values.Select(order => order.short_description(_parent.security.ContractSpec)).Aggregate((s1, s2) => $"{s1}{Environment.NewLine}{Environment.NewLine}{s2}"); description = _orders.Values.Select(order => order.full_description(_parent.security)).Aggregate((s1, s2) => $"{s1}{Environment.NewLine}{Environment.NewLine}{s2}"); } _set_badge_text(); @@ -196,4 +196,4 @@ namespace mbts.spark { return $"Price: {this.price} Order Count: {this.orders.Count()}"; } } -} \ No newline at end of file +} diff --git a/src/client/spark/view/Spark/Ladder/LadderView.xaml b/src/client/spark/view/Spark/Ladder/LadderView.xaml index 078ae5bc9..3f5f82027 100644 --- a/src/client/spark/view/Spark/Ladder/LadderView.xaml +++ b/src/client/spark/view/Spark/Ladder/LadderView.xaml @@ -317,7 +317,7 @@ - + @@ -325,7 +325,7 @@ - + @@ -333,7 +333,7 @@ - + @@ -341,7 +341,7 @@ - + @@ -349,7 +349,7 @@ - + diff --git a/src/client/spark/view/Spark/Ladder/LaderRender.cs b/src/client/spark/view/Spark/Ladder/LaderRender.cs index 4218865bc..105a754e7 100644 --- a/src/client/spark/view/Spark/Ladder/LaderRender.cs +++ b/src/client/spark/view/Spark/Ladder/LaderRender.cs @@ -57,7 +57,7 @@ namespace mbts.spark { public static GlyphRun format_text(string text, int row, double row_height, LadderColumnSettings settings, GlyphContext glyph_context) => glyph_context.get_glyph_run(text, settings.font_size, settings.width, row_height, HorizontalAlignment.Center, 0, VerticalAlignment.Center, row * row_height, true); - public static double[] gen_prices(double mid, int row_count, SecurityImmutable security) { + public static double[] gen_prices(double mid, int row_count, ContractSpecificationImmutable spec) { // require odd number Logger.assert(row_count % 2 == 1); var result = new double[row_count]; @@ -67,32 +67,32 @@ namespace mbts.spark { double up = mid, down = mid; // Starting from the middle iterate out to the edges for (int x = 1; x <= range; ++x) { - up = security.tickup(up); - down = security.tickdown(down); + up = spec.tickup(up); + down = spec.tickdown(down); result[middle - x] = up; result[middle + x] = down; } return result; } - public static GlyphRun[] format_prices(double[] prices, double row_height, LadderColumnSettings settings, GlyphContext glyph_context, SecurityImmutable security) { + public static GlyphRun[] format_prices(double[] prices, double row_height, LadderColumnSettings settings, GlyphContext glyph_context, ContractSpecificationImmutable spec) { var result = new GlyphRun[prices.Length]; Parallel.For(0, prices.Length, i => - result[i] = format_text(security.format(prices[i]), i, row_height, settings, glyph_context)); + result[i] = format_text(spec.format(prices[i]), i, row_height, settings, glyph_context)); return result; } public static double[] render_prices(DrawingVisual price, GlyphContext glyph_context, double mid, int row_count, double row_height, - LadderColumnSettings settings, SecurityImmutable security) { - var dprices = gen_prices(mid, row_count, security); - render_prices(price, glyph_context, row_count, row_height, dprices, settings, security); + LadderColumnSettings settings, ContractSpecificationImmutable spec) { + var dprices = gen_prices(mid, row_count, spec); + render_prices(price, glyph_context, row_count, row_height, dprices, settings, spec); return dprices; } - public static void render_prices(DrawingVisual price, GlyphContext glyph_context, int row_count, double row_height, double[] dprices, LadderColumnSettings settings, SecurityImmutable security) { + public static void render_prices(DrawingVisual price, GlyphContext glyph_context, int row_count, double row_height, double[] dprices, LadderColumnSettings settings, ContractSpecificationImmutable spec) { var foreground = settings.foreground.rgb_brush(); //var background = new SolidColorBrush(settings.background.rgb_color()); - var fprices = format_prices(dprices, row_height, settings, glyph_context, security); + var fprices = format_prices(dprices, row_height, settings, glyph_context, spec); using (var dc = price.RenderOpen()) using (_draw_with_clip(dc, settings, row_height, row_count)) { //dc.DrawRectangle(background, null, new Rect(0, 0, settings.width, row_count * row_height)); @@ -126,7 +126,7 @@ namespace mbts.spark { double[] prices, NativePriceSize[] rungs, double row_height, - SecurityImmutable security, + ContractSpecificationImmutable spec, LadderColumnSettings settings ) { //var background = new SolidColorBrush(settings.background.rgb_color()); @@ -143,7 +143,7 @@ namespace mbts.spark { double price = nps.price; ushort size = nps.size; // prices are in descending order, so get diff from curr_price - price - int tick_diff = TickUtils.normalized_tick_diff(security, curr_price, price); + int tick_diff = TickUtils.normalized_tick_diff(spec, curr_price, price); curr_index += tick_diff; curr_price = price; if (curr_index >= 0 && curr_index < prices.Length) { diff --git a/src/client/spark/view/Spark/Shell/CVOrderBook/CVOrderBookRowVM.cs b/src/client/spark/view/Spark/Shell/CVOrderBook/CVOrderBookRowVM.cs index e1480170a..877f21089 100644 --- a/src/client/spark/view/Spark/Shell/CVOrderBook/CVOrderBookRowVM.cs +++ b/src/client/spark/view/Spark/Shell/CVOrderBook/CVOrderBookRowVM.cs @@ -76,7 +76,7 @@ namespace mbts.spark { _status_store = CellFactory.create(this, _book_vm.columns.status_column, nameof(status), r => _order.status(), r => r._status_store); _last_msg_store = CellFactory.create(this, _book_vm.columns.last_message_column, nameof(last_msg), r => _order.last_msg(), r => r._last_msg_store); // - string format_price(double v) => _security.HasValue ? _security.Value.format(v) : + string format_price(double v) => _security.HasValue ? _security.Value.ContractSpec.format(v) : Math.Round(v, _unknown_security_price_num_fractional_digits, MidpointRounding.AwayFromZero).ToString(_unknown_security_price_format_string); string format_date(DateTime v) => $"{v:M/d} {v:h:mm:ss.fff tt}"; string format_sub_type(OrderSubType v) { diff --git a/src/client/spark/view/Spark/Shell/OrderBook/OrderBookColumns.cs b/src/client/spark/view/Spark/Shell/OrderBook/OrderBookColumns.cs index ccab878e8..401900572 100644 --- a/src/client/spark/view/Spark/Shell/OrderBook/OrderBookColumns.cs +++ b/src/client/spark/view/Spark/Shell/OrderBook/OrderBookColumns.cs @@ -41,7 +41,7 @@ namespace mbts.spark { public static GlyphContext get_glyph_context(OrderBookRowVM r) => r.is_child ? _child_glyph_context : TextUtils.StandardGlyphContext; public static Brush get_side_brush(OrderBookRowVM r) => r.side == Side.Buy ? BTSColors.MarketData.bid : BTSColors.MarketData.ask; public static BindingBase get_font_weight_binding() => new Binding(nameof(OrderBookRowVM.is_child)) { Converter = _font_weight_converter }; - public static string format_price(OrderBookRowVM row, double price) => row.security.HasValue ? row.security.Value.format(price) : row.price.ToString(); + public static string format_price(OrderBookRowVM row, double price) => row.security.HasValue ? row.security.Value.ContractSpec.format(price) : row.price.ToString(); } abstract class OrderbookColumnBase : ColumnBase, IKeyedColumn, IFilterableColumn {