fix ticks merge from prod to master

This commit is contained in:
John Colvin committed 2018-07-18 18:14:24 -04:00
1 parent 2a452d3201
commit 656c7104f6
21 files changed
+105 -103

No files matched your search

@@ -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<int>(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<CellAnimation> animations => _animation.get_animations().ToList();
@@ -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;
}
//
@@ -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();
@@ -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)}");
}
}
@@ -74,7 +74,7 @@
<usp:PriceEntryControl
Grid.ColumnSpan="2"
usp:OrderModificationControl.IsDirty="{Binding price_dirty, FallbackValue={x:Null}}"
Security="{Binding security}"
ContractSpec="{Binding security.ContractSpec}"
Focusable="false"
TickDefaultValue="{Binding current_price, Converter={StaticResource TickDefaultPriceConverter}, FallbackValue={u:Double 0}}"
Value="{Binding price}"
@@ -97,13 +97,13 @@
<Button Command="{Binding set_price_command}" CommandParameter="{Binding bbo.bid}" Foreground="{u:BTSColor MarketData.bid}" FontWeight="Bold">
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
<Binding Path="bbo.bid"/>
<Binding Path="security"/>
<Binding Path="security.ContractSpec"/>
</MultiBinding>
</Button>
<Button Grid.Column="2" Command="{Binding set_price_command}" CommandParameter="{Binding bbo.ask}" Foreground="{u:BTSColor MarketData.ask}" FontWeight="Bold">
<MultiBinding Converter="{StaticResource TickDisplayConverter}">
<Binding Path="bbo.ask"/>
<Binding Path="security"/>
<Binding Path="security.ContractSpec"/>
</MultiBinding>
</Button>
</Grid>
@@ -77,7 +77,7 @@
<Run.Text>
<MultiBinding Converter="{StaticResource TickDisplayConverter}" Mode="OneWay">
<Binding Path="bid"/>
<Binding Path="security"/>
<Binding Path="security.ContractSpec"/>
</MultiBinding>
</Run.Text>
</Run>
@@ -85,7 +85,7 @@
<Run.Text>
<MultiBinding Converter="{StaticResource TickDisplayConverter}" Mode="OneWay">
<Binding Path="ask"/>
<Binding Path="security"/>
<Binding Path="security.ContractSpec"/>
</MultiBinding>
</Run.Text>
</Run>
+2 -2
View File
@@ -126,7 +126,7 @@
<Run.Text>
<MultiBinding Converter="{StaticResource TickDisplayConverter}" Mode="OneWay">
<Binding Path="bid"/>
<Binding Path="security"/>
<Binding Path="security.ContractSpec"/>
</MultiBinding>
</Run.Text>
</Run>
@@ -134,7 +134,7 @@
<Run.Text>
<MultiBinding Converter="{StaticResource TickDisplayConverter}" Mode="OneWay">
<Binding Path="ask"/>
<Binding Path="security"/>
<Binding Path="security.ContractSpec"/>
</MultiBinding>
</Run.Text>
</Run>
@@ -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<StopLimitOrderDefinition> {
@@ -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) {
@@ -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<HorizontalAlignment, PriceCell>(
@@ -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<SecurityImmutable, PriceCell>(
nameof(Security),
#region ContractSpec
public static readonly DependencyProperty ContractSpecProperty =
WPFHelper.create_dp<ContractSpecificationImmutable, PriceCell>(
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();
}
@@ -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;
}
}
@@ -70,7 +70,7 @@
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock VerticalAlignment="Center">Stop Price</TextBlock>
<usp:PriceEntryControl Grid.Column="1" Margin="12,0,0,0" Width="80" Value="{Binding stop_price}" Security="{Binding security}"/>
<usp:PriceEntryControl Grid.Column="1" Margin="12,0,0,0" Width="80" Value="{Binding stop_price}" ContractSpec="{Binding spec}"/>
</Grid>
</DataTemplate>
</usp:OrderModificationTemplateSelector.StopLimitOrderTemplate>
@@ -82,7 +82,7 @@
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock VerticalAlignment="Center">Stop Price</TextBlock>
<usp:PriceEntryControl Grid.Column="1" Margin="12,0,0,0" Width="80" Value="{Binding stop_price}" Security="{Binding security}"/>
<usp:PriceEntryControl Grid.Column="1" Margin="12,0,0,0" Width="80" Value="{Binding stop_price}" ContractSpec="{Binding spec}"/>
</Grid>
</DataTemplate>
</usp:OrderModificationTemplateSelector.StopMarketOrderTemplate>
@@ -107,4 +107,4 @@ namespace mbts.ui.spark {
}
}
}
}
}
@@ -16,9 +16,9 @@ namespace mbts.ui.spark.converters {
}
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) {
var price = get_val<double>(values, 0);
var security = get_val<SecurityImmutable?>(values, 1);
if (security == null) return price.ToString();
return security.Value.format(price);
var spec = get_val<ContractSpecificationImmutable?>(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);
}
}
@@ -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) {
@@ -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);
}
}
@@ -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);
}
@@ -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()}";
}
}
}
}
@@ -317,7 +317,7 @@
<TextBlock.Text>
<MultiBinding Converter="{StaticResource TickDisplayConverter}" Mode="OneWay">
<Binding Path="change"/>
<Binding Path="security"/>
<Binding Path="security.ContractSpec"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
@@ -325,7 +325,7 @@
<TextBlock.Text>
<MultiBinding Converter="{StaticResource TickDisplayConverter}" Mode="OneWay">
<Binding Path="high"/>
<Binding Path="security"/>
<Binding Path="security.ContractSpec"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
@@ -333,7 +333,7 @@
<TextBlock.Text>
<MultiBinding Converter="{StaticResource TickDisplayConverter}" Mode="OneWay">
<Binding Path="low"/>
<Binding Path="security"/>
<Binding Path="security.ContractSpec"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
@@ -341,7 +341,7 @@
<TextBlock.Text>
<MultiBinding Converter="{StaticResource TickDisplayConverter}" Mode="OneWay">
<Binding Path="open"/>
<Binding Path="security"/>
<Binding Path="security.ContractSpec"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
@@ -349,7 +349,7 @@
<TextBlock.Text>
<MultiBinding Converter="{StaticResource TickDisplayConverter}" Mode="OneWay">
<Binding Path="settlement"/>
<Binding Path="security"/>
<Binding Path="security.ContractSpec"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
@@ -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) {
@@ -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) {
@@ -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<Columns>, IKeyedColumn<Columns>, IFilterableColumn {