diff --git a/doc/user/content/release_notes/_index.md b/doc/user/content/release_notes/_index.md index a0dcfe3d9..0a6db8b6e 100644 --- a/doc/user/content/release_notes/_index.md +++ b/doc/user/content/release_notes/_index.md @@ -7,6 +7,17 @@ insert_anchor_links = "right" [extra] page_description = "Release notes for BTS Spark" +++ +## 2.13.0 +### User Visible Changes + - Added the name of the spreader to the parent algo badge (for spreader child orders), in the fills, orderbook and floating orderbook windows + - Added support for sounds for new orders + - Added a new quoting throttle parameter for the spreader, that throttles quotes that are moving toward the inside market but are still a configurable number of ticks away + - Enabled the ladder to remember the left panel scroll position across front end restarts +### Bug Fixes + - Fixed the local fills window so that it does not show the admin fills + - Removed the deleted accounts from the ladder accounts dropdown + - Fixed the orderbook price for iceberg of spreaders + ## 2.12.0 ### User Visible Changes - Added support for ICE market data and order execution diff --git a/src/client/spark/Admin/AdminModel.cs b/src/client/spark/Admin/AdminModel.cs index 2bbf79243..77a6829d6 100644 --- a/src/client/spark/Admin/AdminModel.cs +++ b/src/client/spark/Admin/AdminModel.cs @@ -25,7 +25,7 @@ namespace mbts.spark { usr.UserData.AccountPermissions.AccountPermissions .Where(kv => (kv.Value.TradingPermission != null && kv.Value.TradingPermission.HasPermissions) || kv.Value.AdminPermission.HasPermissions) .Select(kv => ad.Accounts.Where(a => a.Id == kv.Key).TryGetSingle(out var acc) ? acc : (BTSAccountImmutable?)null) - .Where(acc => acc.HasValue) + .Where(acc => acc.HasValue && acc.Value.IsPresent) .Select(acc => acc.Value) .ToDictionary(acc => acc.Id, acc => acc.Name) : new Dictionary(0)) diff --git a/src/client/spark/Modules/Spreader/SyntheticDataHelper.cs b/src/client/spark/Modules/Spreader/SyntheticDataHelper.cs index 2b35df0f2..3d68bd7a8 100644 --- a/src/client/spark/Modules/Spreader/SyntheticDataHelper.cs +++ b/src/client/spark/Modules/Spreader/SyntheticDataHelper.cs @@ -81,9 +81,9 @@ namespace bts.shell { #region QuoteParams public static QuoteParams QuoteParams => new QuoteParams { LeanQuantityRatio = 1, - QuoteInsideMarketDistance = QuoteInsideMarketDistance, + //QuoteInsideMarketDistance = QuoteInsideMarketDistance, QuoteMaxOrderMove = QuoteMaxOrderMove, - QuoteMuteZone = QuoteMuteZone, + //QuoteMuteZone = QuoteMuteZone, QuoteRepriceThrottle = QuoteRepriceThrottle, QuoteInsideMarketDistanceWithTravel = QuoteInsideMarketDistanceWithTravel, }; @@ -113,6 +113,7 @@ namespace bts.shell { }; public static QuoteInsideMarketDistanceWithTravel QuoteInsideMarketDistanceWithTravel => new QuoteInsideMarketDistanceWithTravel { Priority = RulePriority }; public static QuoteInsideMarketDistance QuoteInsideMarketDistance => new QuoteInsideMarketDistance { Priority = RulePriority }; + public static QuoteInsideMarketDistanceThrottle QuoteInsideMarketDistanceThrottle => new QuoteInsideMarketDistanceThrottle(); #endregion #region PreHedge diff --git a/src/client/spark/Modules/Spreader/VM/ParameterRows/Quote/InsideMarketDistance/QuoteInsideMarketDistanceEnabledModel.cs b/src/client/spark/Modules/Spreader/VM/ParameterRows/Quote/InsideMarketDistance/QuoteInsideMarketDistanceEnabledModel.cs new file mode 100644 index 000000000..15ebf0481 --- /dev/null +++ b/src/client/spark/Modules/Spreader/VM/ParameterRows/Quote/InsideMarketDistance/QuoteInsideMarketDistanceEnabledModel.cs @@ -0,0 +1,33 @@ +using bts.shell; +using mbts.ui.spark; + +namespace mbts.spark { + partial class SyntheticEditorVM { + class QuoteInsideMarketDistanceEnabledModel : RowModelBase { + readonly QuoteInsideMarketDistanceTowardModel _toward; + + public QuoteInsideMarketDistanceEnabledModel(QuoteInsideMarketDistanceTowardModel toward) => + _toward = toward; + + public override string display_name { get; } = string.Empty; + public override string help_text { get; } = string.Empty; + public override string man_page { get; } = string.Empty; + public override ParameterSection[] section_path { get; } = new[] { Sections.Quote, Subsections.InsideMarketDistance }; + + public override bool get_value(LegSpreaderParamsTuple leg_tup) => + leg_tup.leg_params.QuoteParams.QuoteInsideMarketDistanceThrottle != null; + + public override void set_value(LegSpreaderParamsTuple leg_tup, bool value) { + if (value) { + if (leg_tup.leg_params.QuoteParams.QuoteInsideMarketDistanceThrottle == null) { + leg_tup.leg_params.QuoteParams.QuoteInsideMarketDistanceThrottle = SyntheticDataHelper.Defaults.QuoteInsideMarketDistanceThrottle; + _toward.apply_value(leg_tup); + } + } else { + leg_tup.leg_params.QuoteParams.QuoteInsideMarketDistanceThrottle = null; + } + _toward.set_enabled(leg_tup, value); + } + } + } +} \ No newline at end of file diff --git a/src/client/spark/Modules/Spreader/VM/ParameterRows/Quote/InsideMarketDistance/QuoteInsideMarketDistanceTowardModel.cs b/src/client/spark/Modules/Spreader/VM/ParameterRows/Quote/InsideMarketDistance/QuoteInsideMarketDistanceTowardModel.cs new file mode 100644 index 000000000..f38365209 --- /dev/null +++ b/src/client/spark/Modules/Spreader/VM/ParameterRows/Quote/InsideMarketDistance/QuoteInsideMarketDistanceTowardModel.cs @@ -0,0 +1,39 @@ +using bts.spark; +using mbts.ui.spark; +using System.Collections.Generic; + +namespace mbts.spark { + partial class SyntheticEditorVM { + class QuoteInsideMarketDistanceTowardModel : RowModelBase { + IDictionary _value_store = new Dictionary(); + + public override string display_name { get; } = "Toward Distance"; + public override string help_text { get; } = string.Empty; + public override string man_page { get; } = string.Empty; + public override ParameterSection[] section_path { get; } = new[] { Sections.Quote, Subsections.InsideMarketDistance }; + + public void apply_value(LegSpreaderParamsTuple leg_tup) => + _get_inside_market_distance(leg_tup).OnTowardDistance = _value_from_store(leg_tup); + + public override uint get_value(LegSpreaderParamsTuple leg_tup) => + _get_inside_market_distance(leg_tup) is QuoteInsideMarketDistanceThrottle inside_market_distance ? + inside_market_distance.OnTowardDistance : + _value_from_store(leg_tup); + + public override void set_value(LegSpreaderParamsTuple leg_tup, uint value) { + _value_store[leg_tup.SecurityKey] = value; + if (_get_inside_market_distance(leg_tup) is QuoteInsideMarketDistanceThrottle inside_market_distance) + inside_market_distance.OnTowardDistance = value; + } + + protected override bool _get_enabled(LegSpreaderParamsTuple leg_tup) => + _get_inside_market_distance(leg_tup) != null; + + QuoteInsideMarketDistanceThrottle _get_inside_market_distance(LegSpreaderParamsTuple leg_tup) => + leg_tup.leg_params.QuoteParams.QuoteInsideMarketDistanceThrottle; + + uint _value_from_store(LegSpreaderParamsTuple leg_tup) => + _value_store.GetValueOrDefault(leg_tup.SecurityKey); + } + } +} \ No newline at end of file diff --git a/src/client/spark/Modules/Spreader/VM/ParameterRows/RowModel.cs b/src/client/spark/Modules/Spreader/VM/ParameterRows/RowModel.cs index acb145abb..3d516614f 100644 --- a/src/client/spark/Modules/Spreader/VM/ParameterRows/RowModel.cs +++ b/src/client/spark/Modules/Spreader/VM/ParameterRows/RowModel.cs @@ -115,6 +115,11 @@ namespace mbts.spark { "dictates if this logic applies to the quoting market or to the synthetic spread " + "market"); + public static ParameterSection InsideMarketDistance => + new ParameterSection("Inside Market Distance", true, + "Reduces re-quoting by throttling quotes that are moving toward the inside market " + + "but are more than 'Toward Distance' away from the inside market"); + public static ParameterSection InsideMarketThrottleThresholds => new ParameterSection("Inside Market Throttle Thresholds", true, "Reduces re-quoting for quotes that are moving toward the inside market. " + diff --git a/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs b/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs index 143ead545..d6e81bb99 100644 --- a/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs +++ b/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs @@ -190,6 +190,8 @@ namespace mbts.spark { var quote_inside_market_throttle_ticks = new QuoteInsideMarketThrottleTicksModel(); var quote_inside_market_throttle_min_move = new QuoteInsideMarketThrottleMinMoveModel(); + var quote_inside_market_distance_toward = new QuoteInsideMarketDistanceTowardModel(); + var pre_hedge_payless_threshold = new PreHedgePaylessThresholdModel(); var pre_hedge_payless_ticks = new PreHedgePaylessTicksModel(); @@ -227,6 +229,8 @@ namespace mbts.spark { //quote_inside_market_throttle_ticks, //quote_inside_market_throttle_min_move, //new MaxTicksInsideMarketModel(), + new QuoteInsideMarketDistanceEnabledModel(quote_inside_market_distance_toward), + quote_inside_market_distance_toward, new PreHedgePaylessEnabledModel(pre_hedge_payless_threshold, pre_hedge_payless_ticks), pre_hedge_payless_threshold, pre_hedge_payless_ticks, diff --git a/src/client/spark/Modules/Trading/Fills/FillsVM.cs b/src/client/spark/Modules/Trading/Fills/FillsVM.cs index 75a876716..e370685ea 100644 --- a/src/client/spark/Modules/Trading/Fills/FillsVM.cs +++ b/src/client/spark/Modules/Trading/Fills/FillsVM.cs @@ -285,7 +285,6 @@ namespace mbts.spark { public DateTime fill_time => _fill.Timestamp.to_local_time(); public TimeInForce time_in_force => _order.time_in_force(); public OrderType order_type => _order.order_type(); - //public OrderType root_algo_type => _or public string display_name => OrderUtils.display_name(_order, fill_tuple.algo); public OrderMetadata order_metadata => _order_metadata ?? (_order_metadata = _model.factory.get_metadata(_order.Def.CustomDef.CustomCase)); public Brush badge_fill => _badge_fill ?? (_badge_fill = OrderUtils.badge_fill(fill_tuple.algo_meta, order_metadata)); @@ -304,7 +303,7 @@ namespace mbts.spark { public OrderType root_algo_order_type => _root_algo.HasValue ? _root_algo.Value.value.CustomCase : OrderType.None; public OrderMetadata root_algo_order_metadata => _model.factory.get_metadata(root_algo_order_type); public Color root_algo_badge_color => _root_algo_badge_color ?? (_root_algo_badge_color = OrderUtils.badge_color(_root_algo_meta, root_algo_order_metadata)).Value; - public string root_algo_display_name => _root_algo?.name ?? root_algo_order_type.display_name(); + public string root_algo_display_name => fill_tuple.root_order_security?.display_name() ?? OrderType.None.display_name(); public bool Equals(Row other) => other != null && other._fill.Equals(_fill) && other._order.Equals(_order); public override bool Equals(object obj) => Equals(obj as Row); diff --git a/src/client/spark/Modules/Trading/Ladder/LadderSettings.cs b/src/client/spark/Modules/Trading/Ladder/LadderSettings.cs index e1222b5af..c025e90ed 100644 --- a/src/client/spark/Modules/Trading/Ladder/LadderSettings.cs +++ b/src/client/spark/Modules/Trading/Ladder/LadderSettings.cs @@ -23,6 +23,10 @@ namespace mbts.spark { // TODO: somehow allow windows that are using the default settings to still have individual column widths. [ProtoContract] class LadderColumnSettings : IEquatable { + // this class is 100% mutable (there are literally 0 readonly members), + // so GetHashCode must return the same hash for every instance. + static readonly int _type_hash = typeof(LadderColumnSettings).GetHashCode(); + public static LadderColumnSettings Default => new LadderColumnSettings { show = true, width = 50, @@ -74,14 +78,7 @@ namespace mbts.spark { other.show == show; public override bool Equals(object obj) => Equals(obj as LadderColumnSettings); - - public override int GetHashCode() => - width.GetHashCode() + - background.GetHashCode() + - foreground.GetHashCode() + - font_family.GetHashCode() + - font_size.GetHashCode() + - font_weight.GetHashCode(); + public override int GetHashCode() => _type_hash; public static bool operator ==(LadderColumnSettings x, LadderColumnSettings y) => x.safe_equals(y); public static bool operator !=(LadderColumnSettings x, LadderColumnSettings y) => !(x == y); @@ -89,6 +86,9 @@ namespace mbts.spark { [ProtoContract] class HistogramBarAnimation : IEquatable { + // this class is 100% mutable (there are literally 0 readonly members), + // so GetHashCode must return the same hash for every instance. + static readonly int _type_hash = typeof(HistogramBarAnimation).GetHashCode(); [ProtoMember(1)] public ColorShowProto bars { get; set; } [ProtoMember(2)] @@ -102,14 +102,14 @@ namespace mbts.spark { show_numbers == other.show_numbers; public override bool Equals(object obj) => Equals(obj as HistogramBarAnimation); - public override int GetHashCode() => - EqualityComparer.aggregate_hash( - bars.GetHashCode(), - show_numbers.GetHashCode()); + public override int GetHashCode() => _type_hash; } [ProtoContract] class VolumeColumnSettings : IEquatable { + // this class is 100% mutable (there are literally 0 readonly members), + // so GetHashCode must return the same hash for every instance. + static readonly int _type_hash = typeof(VolumeColumnSettings).GetHashCode(); public static VolumeColumnSettings Default { get { var gen = LadderColumnSettings.Default; @@ -149,19 +149,14 @@ namespace mbts.spark { show_ltq.Equals(other.show_ltq); public override bool Equals(object obj) => Equals(obj as VolumeColumnSettings); - - public override int GetHashCode() => - EqualityComparer.aggregate_hash( - general.GetHashCode(), - buy.GetHashCode(), - sell.GetHashCode(), - passive.GetHashCode(), - total.GetHashCode(), - show_ltq.GetHashCode()); + public override int GetHashCode() => _type_hash; } [ProtoContract] class LadderMarketBreakLine : IEquatable { + // this class is 100% mutable (there are literally 0 readonly members), + // so GetHashCode must return the same hash for every instance. + static readonly int _type_hash = typeof(LadderMarketBreakLine).GetHashCode(); [ProtoMember(1)] public bool show { get; set; } [ProtoMember(2)] @@ -184,8 +179,7 @@ namespace mbts.spark { Equals(obj as LadderMarketBreakLine); public override int GetHashCode() => - show.GetHashCode() + - (int)color; + _type_hash; } [ProtoContract] @@ -255,6 +249,11 @@ namespace mbts.spark { const double _default_order_entry_panel_width = 110.0; const double _default_zoom_factor = 1.0; const bool _default_show_warn_on_cross = true; + public static readonly IEqualityComparer profile_equality_comparer = + EqualityComparer.Create(profile_equals); + // this class is 100% mutable (there are literally 0 readonly members), + // so GetHashCode must return the same hash for every instance. + static readonly int _type_hash = typeof(LadderSettings).GetHashCode(); // Default proto constructor // Added this so that when clients upgrade to a version with new settings, @@ -497,6 +496,9 @@ namespace mbts.spark { [ProtoMember(55)] public LadderMiniOrderBookSettings mini_ob { get; set; } + [ProtoMember(57)] + public double left_panel_scroll_position { get; set; } + public void sanitize() => sanitize(this); @@ -533,112 +535,81 @@ namespace mbts.spark { return s; } + /// + /// Determines whether or not the specified LadderSettings are 'profile equivalent.' + /// This means that 2 ladders, each with a different one of the specified settings, could share the same profile. + /// + /// + /// Note: the impetus for this version of equality is to avoid disconnecting a ladder from its profile due to 'trivial' settings changes. + /// Consider the '' property: + /// If a ladder is using a settings profile with Limit as the default algo, and the user decides to send a 'Market' order, + /// the ladder would suddenly be disconnected from the profile, because it's settings state would no longer be equal to the profile's settings, + /// since they changed the selected algo type to 'Market.' + /// To avoid such travesties, a separate equals logic is needed: this is called 'profile-equivalent' and is implemented in . + /// Devs: be sure to account for properties that are excluded in the 'profile-equals' logic in the [regular]'equals' logic. + public static bool profile_equals(LadderSettings a, LadderSettings b) => + a == null ? b == null : + b != null && + a.row_height == b.row_height && + a.grid_line_color == b.grid_line_color && + a.orders_column.safe_equals(b.orders_column) && + a.bid_column.safe_equals(b.bid_column) && + a.ask_column.safe_equals(b.ask_column) && + a.price_column.safe_equals(b.price_column) && + a.last_column.safe_equals(b.last_column) && + a.piq_column.safe_equals(b.piq_column) && + a.calculator_buttons.safe_equals(b.calculator_buttons, Enumerable.SequenceEqual) && + a.scroll_bar_visible == b.scroll_bar_visible && + a.default_account == b.default_account && + a.default_time_in_force == b.default_time_in_force && + a.size == b.size && + a.animate_recenter == b.animate_recenter && + a.badge_style == b.badge_style && + a.auto_clear == b.auto_clear && + a.bid_break_line.safe_equals(b.bid_break_line) && + a.ask_break_line.safe_equals(b.ask_break_line) && + a.mid_break_line.safe_equals(b.mid_break_line) && + a.alternate_order_size == b.alternate_order_size && + a.session_low_line.safe_equals(b.session_low_line) && + a.session_high_line.safe_equals(b.session_high_line) && + a.session_range_fill.safe_equals(b.session_range_fill) && + a.volume_column.safe_equals(b.volume_column) && + a.size_display.safe_equals(b.size_display) && + a.day_visible == b.day_visible && + a.high_visible == b.high_visible && + a.low_visible == b.low_visible && + a.open_visible == b.open_visible && + a.settle_visible == b.settle_visible && + a.volume_visible == b.volume_visible && + a.account_visible == b.account_visible && + a.tif_visible == b.tif_visible && + a.order_type_visible == b.order_type_visible && + a.account_position_visible == b.account_position_visible && + a.day_position_visible == b.day_position_visible && + a.raw_day_position_visible == b.raw_day_position_visible && + a.size_presets_visible == b.size_presets_visible && + a.cancel_buys_visible == b.cancel_buys_visible && + a.cancel_sells_visible == b.cancel_sells_visible && + a.cancel_all_visible == b.cancel_all_visible && + a.auto_clear_visible == b.auto_clear_visible && + a.clear_visible == b.clear_visible && + a.order_entry_panel_initial_width == b.order_entry_panel_initial_width && + a.zoom_slider_visible == b.zoom_slider_visible && + a.zoom_factor == b.zoom_factor && + a.use_defaults == b.use_defaults && + a.favorite_algos == b.favorite_algos && + a.net_change == b.net_change && + a.show_warn_on_cross == b.show_warn_on_cross && + a.mini_ob == b.mini_ob; + public bool Equals(LadderSettings other) => - other != null && - row_height == other.row_height && - grid_line_color == other.grid_line_color && - orders_column.safe_equals(other.orders_column) && - bid_column.safe_equals(other.bid_column) && - ask_column.safe_equals(other.ask_column) && - price_column.safe_equals(other.price_column) && - last_column.safe_equals(other.last_column) && - piq_column.safe_equals(other.piq_column) && - calculator_buttons.safe_equals(other.calculator_buttons, (a, b) => a.SequenceEqual(b)) && - scroll_bar_visible == other.scroll_bar_visible && - default_account == other.default_account && + profile_equals(this, other) && default_algo == other.default_algo && - default_time_in_force == other.default_time_in_force && - size == other.size && - animate_recenter == other.animate_recenter && - badge_style == other.badge_style && - auto_clear == other.auto_clear && - bid_break_line.safe_equals(other.bid_break_line) && - ask_break_line.safe_equals(other.ask_break_line) && - mid_break_line.safe_equals(other.mid_break_line) && - alternate_order_size == other.alternate_order_size && - session_low_line.safe_equals(other.session_low_line) && - session_high_line.safe_equals(other.session_high_line) && - session_range_fill.safe_equals(other.session_range_fill) && - volume_column.safe_equals(other.volume_column) && - size_display.safe_equals(other.size_display) && - day_visible == other.day_visible && - high_visible == other.high_visible && - low_visible == other.low_visible && - open_visible == other.open_visible && - settle_visible == other.settle_visible && - volume_visible == other.volume_visible && - account_visible == other.account_visible && - tif_visible == other.tif_visible && - order_type_visible == other.order_type_visible && - account_position_visible == other.account_position_visible && - day_position_visible == other.day_position_visible && - raw_day_position_visible == other.raw_day_position_visible && - size_presets_visible == other.size_presets_visible && - cancel_buys_visible == other.cancel_buys_visible && - cancel_sells_visible == other.cancel_sells_visible && - cancel_all_visible == other.cancel_all_visible && - auto_clear_visible == other.auto_clear_visible && - clear_visible == other.clear_visible && - order_entry_panel_initial_width == other.order_entry_panel_initial_width && - zoom_slider_visible == other.zoom_slider_visible && - zoom_factor == other.zoom_factor && - use_defaults == other.use_defaults && - favorite_algos == other.favorite_algos && - net_change == other.net_change && - show_warn_on_cross == other.show_warn_on_cross && - mini_ob == other.mini_ob; + left_panel_scroll_position == other.left_panel_scroll_position; public override bool Equals(object obj) => Equals(obj as LadderSettings); - // TODO: remove mutable props from hash logic (or conversely, make them immutable). - public override int GetHashCode() => - EqualityComparer.aggregate_hash( - row_height.GetHashCode(), - grid_line_color.GetHashCode(), - EqualityComparer.safe_get_hash_code(orders_column), - EqualityComparer.safe_get_hash_code(bid_column), - EqualityComparer.safe_get_hash_code(ask_column), - EqualityComparer.safe_get_hash_code(price_column), - EqualityComparer.safe_get_hash_code(last_column), - EqualityComparer.safe_get_hash_code(piq_column), - EqualityComparer.safe_get_hash_code(calculator_buttons), - scroll_bar_visible.GetHashCode(), - default_time_in_force.GetHashCode(), - size.GetHashCode(), - animate_recenter.GetHashCode(), - badge_style.GetHashCode(), - EqualityComparer.safe_get_hash_code(bid_break_line), - EqualityComparer.safe_get_hash_code(ask_break_line), - EqualityComparer.safe_get_hash_code(mid_break_line), - alternate_order_size.GetHashCode(), - EqualityComparer.safe_get_hash_code(session_low_line), - EqualityComparer.safe_get_hash_code(session_high_line), - EqualityComparer.safe_get_hash_code(session_range_fill), - EqualityComparer.safe_get_hash_code(volume_column), - EqualityComparer.safe_get_hash_code(size_display), - day_visible.GetHashCode(), - high_visible.GetHashCode(), - low_visible.GetHashCode(), - open_visible.GetHashCode(), - settle_visible.GetHashCode(), - volume_visible.GetHashCode(), - account_visible.GetHashCode(), - tif_visible.GetHashCode(), - order_type_visible.GetHashCode(), - account_position_visible.GetHashCode(), - size_presets_visible.GetHashCode(), - cancel_buys_visible.GetHashCode(), - cancel_sells_visible.GetHashCode(), - cancel_all_visible.GetHashCode(), - auto_clear_visible.GetHashCode(), - clear_visible.GetHashCode(), - order_entry_panel_initial_width.GetHashCode(), - zoom_slider_visible.GetHashCode(), - zoom_factor.GetHashCode(), - use_defaults.GetHashCode(), - favorite_algos.GetHashCode(), - net_change.GetHashCode(), - show_warn_on_cross.GetHashCode()); + public override int GetHashCode() => _type_hash; public struct WindowSpecifics { public readonly double order_entry_panel_width, zoom_factor; diff --git a/src/client/spark/Modules/Trading/Ladder/LadderWindowFactory.cs b/src/client/spark/Modules/Trading/Ladder/LadderWindowFactory.cs index 0d1b3ac40..2f3b64e92 100644 --- a/src/client/spark/Modules/Trading/Ladder/LadderWindowFactory.cs +++ b/src/client/spark/Modules/Trading/Ladder/LadderWindowFactory.cs @@ -81,11 +81,9 @@ namespace bts.shell { if (!_settings_hub.current.ladder_profiles.TryGetFirst(lp => lp.id == id, out var result)) { // profile was deleted id = 0; - } else { - if (!s.Equals(result.value)) { - // ladder's settings diverged from the profile (this happens when the user changes settings outside of the settings dialog, such as column widths, left panel width, etc.) - id = 0; - } + } else if (!LadderSettings.profile_equals(s, result.value)) { + // ladder's settings diverged from the profile (this happens when the user changes settings outside of the settings dialog, such as column widths, left panel width, etc.) + id = 0; } } return new LadderSaveState { security_key = vm.security.Id, settings = s, settings_id = id }; @@ -149,7 +147,7 @@ namespace bts.shell { var curr = vm.get_save_state(); if (settings_id == 0) { last_value = curr; - } else if (!curr.Equals(last_value)) { + } else if (!LadderSettings.profile_equals(curr, last_value)) { settings_id = 0; last_value = curr; } @@ -163,7 +161,7 @@ namespace bts.shell { // not on a profile, don't respond to default settings changes return; } else if (us.ladder_profiles.TryGetFirst(p => p.id == settings_id, out var profile)) { - if (!last_value.Equals(vm.get_save_state())) { + if (!LadderSettings.profile_equals(last_value, vm.get_save_state())) { settings_id = 0; } else { settings_subject.OnNext(last_value = profile.value); @@ -211,6 +209,7 @@ namespace bts.shell { _ => _, vm.get_save_state(), UserSettings.FileExtensions.LADDER, + LadderSettings.profile_equals, settings_id); dialog_vm.applied += apply; // dialog diff --git a/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs b/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs index d5d1c38da..174a14b69 100644 --- a/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs +++ b/src/client/spark/Modules/Trading/Ladder/VM/LadderVM.cs @@ -35,7 +35,14 @@ namespace mbts.spark { _show_cancel_sells, _show_cancel_all, _show_zoom; readonly PropertyAutoWrapper _bid_background, _bid_foreground, _ask_background, _ask_foreground; readonly HashSet _sticky_algos = new HashSet(); - double _position, _day_position, _raw_day_position; + double + _position, + _day_position, + _raw_day_position, + _left_panel_extent_height, + _left_panel_view_port_height, + _left_panel_scroll_position, + _left_panel_scroll_position_target; bool _show_account_position, _show_day_position, _show_raw_day_position; ulong _misc_time = 0; ulong _last_trade_time = 0; @@ -76,6 +83,7 @@ namespace mbts.spark { _volume_column_width = backing(nameof(volume_column_width), ws.volume_column_width); _left_panel_width = backing(nameof(left_panel_width), ws.order_entry_panel_width); _zoom_factor = backing(nameof(zoom_factor), ws.zoom_factor); + _left_panel_scroll_position_target = init.left_panel_scroll_position; // remember: account_positions needs to subscribe to selected_account; both the sub and account_positions need to be disposed _volume = backing(nameof(volume), 0ul); _auto_clear = backing(nameof(auto_clear), init.auto_clear); @@ -333,6 +341,33 @@ namespace mbts.spark { public bool show_cancel_sells => _show_cancel_sells.view; public bool show_cancel_all => _show_cancel_all.view; public bool show_zoom => _show_zoom.view; + // left panel scroll props + public double left_panel_view_port_height { + get => _left_panel_view_port_height; + set { + using (detect_property_changes(nameof(left_panel_scroll_position))) + _left_panel_view_port_height = value; + } + } + public double left_panel_scroll_position { + get { + if (!_left_panel_scroll_position_target.is_nan()) { + if (_left_panel_scroll_position_target < _max_left_panel_scroll_position) { + _left_panel_scroll_position = _left_panel_scroll_position_target; + _left_panel_scroll_position_target = double.NaN; + } + } + return Math.Min(_left_panel_scroll_position, _left_panel_extent_height); + } + set => Set(ref _left_panel_scroll_position, value); + } + public double left_panel_extent_height { + get => _left_panel_extent_height; + set { + using (detect_property_changes(nameof(left_panel_scroll_position))) + Set(ref _left_panel_extent_height, value); + } + } public double left_panel_width { get => _left_panel_width.Value; set => _left_panel_width.set(value); } public double zoom_factor { get => _zoom_factor.Value; set => _zoom_factor.set(value); } public string position_display_text { @@ -364,6 +399,10 @@ namespace mbts.spark { public bool show_warn_on_cross_from_settings => current_settings.show_warn_on_cross; internal LadderModel model => _model; internal IObservable settings { get; } + + double _max_left_panel_scroll_position => + Math.Max(0, _left_panel_extent_height - _left_panel_view_port_height); + internal OrderRecordImmutable get_root_at_price((OrderRecordImmutable order, uint? _, AlgoData? __, AlgoDefinitionMetadata? meta) op) { var order = op.order; double p = order.price(); @@ -394,6 +433,7 @@ namespace mbts.spark { zoom_factor, piq_column_width)); rv.auto_clear = auto_clear; + rv.left_panel_scroll_position = left_panel_scroll_position; if (order_properties_vm != null) { rv.default_time_in_force = order_properties_vm.selected_time_in_force; if (order_properties_vm.selected_account.HasValue) diff --git a/src/client/spark/Modules/Trading/Ladder/View/LadderView.xaml b/src/client/spark/Modules/Trading/Ladder/View/LadderView.xaml index b761e9b75..c0275583a 100644 --- a/src/client/spark/Modules/Trading/Ladder/View/LadderView.xaml +++ b/src/client/spark/Modules/Trading/Ladder/View/LadderView.xaml @@ -301,7 +301,14 @@ - + diff --git a/src/client/spark/Modules/Trading/Ladder/View/LadderView.xaml.cs b/src/client/spark/Modules/Trading/Ladder/View/LadderView.xaml.cs index d3696d053..21c233eac 100644 --- a/src/client/spark/Modules/Trading/Ladder/View/LadderView.xaml.cs +++ b/src/client/spark/Modules/Trading/Ladder/View/LadderView.xaml.cs @@ -6,10 +6,12 @@ using mbts.ui.converters; using mbts.ui.extensions; using mbts.utils; using System; +using System.Collections.Generic; using System.Linq; using System.Reactive.Linq; using System.Windows; using System.Windows.Controls; +using System.Windows.Controls.Primitives; using System.Windows.Data; using System.Windows.Input; @@ -85,6 +87,7 @@ namespace mbts.spark { _ladder.visible_column_types.Select(t => ColumnFactory.create(_ladder, t))); this.vm = vm; this.ConnectDataContext(lvm => lvm.bus.subscribe(SparkTags.SecuritiesTag).OnDispatcher().Subscribe(sec_map => Resources[ResourceKeys.Securities] = sec_map)); + vm.SubscribeDisposed(_connect_left_panel_scroll()); DataContext = vm; DataContextChanged += datacontext_changed; _ui_scaler.MouseDoubleClick += _ui_scaler_MouseDoubleClick; @@ -92,7 +95,39 @@ namespace mbts.spark { this.PreviewMouseDown += LadderView_PreviewMouseDown; } - + IDisposable _connect_left_panel_scroll() { + // extent height + bool busy = false; + var extent_height_hook = _left_panel_scroll.ObserveProperty(ScrollViewer.ExtentHeightProperty, (s, e) => { + if (!busy) { + double scroll_pos = vm.left_panel_scroll_position; + busy = true; + Dispatcher.InvokeAsync(() => { + vm.left_panel_extent_height = _left_panel_scroll.ExtentHeight; + if (_left_panel_scroll.VerticalOffset != scroll_pos) + _left_panel_scroll.TryScrollToVerticalOffset(scroll_pos); + busy = false; + }, System.Windows.Threading.DispatcherPriority.ApplicationIdle); + } + }); + // view port height + _left_panel_scroll.Loaded += on_loaded; + var dispose = Disposable.CreateDisposeOnce(dispose_impl); + return Disposable.Create(dispose, vm.SubscribeDisposed(dispose)); + // local methods + void on_loaded(object sender, RoutedEventArgs e) { + if (_left_panel_scroll.descendants_of_type().TryGetFirst(sb => sb.Orientation == Orientation.Vertical, out var vscroll)) { + vscroll.SetBinding(ScrollBar.ViewportSizeProperty, new Binding(nameof(LadderVM.left_panel_view_port_height)) { + Converter = ValueConverter.create(d => new Size(0, d), sz => sz.Height), + Mode = BindingMode.OneWayToSource + }); + } + } + void dispose_impl() { + Disposable.dispose(ref extent_height_hook); + _left_panel_scroll.Loaded -= on_loaded; + } + } // (Left|Right) CTRL + Wheel to zoom // This is neat b/c the user doesn't even need to have the slider visible to zoom diff --git a/src/client/spark/Modules/Trading/OrderBook/OrderBookRowVM.cs b/src/client/spark/Modules/Trading/OrderBook/OrderBookRowVM.cs index 44fee4c18..8644745b1 100644 --- a/src/client/spark/Modules/Trading/OrderBook/OrderBookRowVM.cs +++ b/src/client/spark/Modules/Trading/OrderBook/OrderBookRowVM.cs @@ -108,7 +108,7 @@ namespace mbts.spark { public CustomOrderDefinition.CustomOneofCase root_algo_order_type => order_tuple.root.algo.value.CustomCase; public OrderMetadata root_algo_order_metadata => _owner.get_metadata(root_algo_order_type); public Brush root_algo_badge_fill => _root_algo_badge_fill ?? (_root_algo_badge_fill = new SolidColorBrush(_root_algo_badge_color)); - public string root_algo_display_name => order_tuple.root.algo.name; + public string root_algo_display_name => order_tuple.root.display_name(); // Tree public bool is_parent { get => _is_parent; set => Set(ref _is_parent, value); } diff --git a/src/client/spark/Orders/FillTuple.cs b/src/client/spark/Orders/FillTuple.cs index 87d4bb38c..a639fe575 100644 --- a/src/client/spark/Orders/FillTuple.cs +++ b/src/client/spark/Orders/FillTuple.cs @@ -36,6 +36,8 @@ namespace mbts.spark { public AlgoDefinitionMetadata? root_algo_meta => _order_tuple.HasValue ? _order_tuple.Value.root.meta : null; + public OrderSecurityAlgo? root_order_security => _order_tuple?.root; + public string account { get { var account_string = string.Empty; @@ -85,4 +87,4 @@ namespace mbts.spark { public static string user(this FillTuple fill_tuple) => fill_tuple.order.HasValue ? fill_tuple.order.Value.user() : string.Empty; } -} +} \ No newline at end of file diff --git a/src/client/spark/Orders/OrderUtils.cs b/src/client/spark/Orders/OrderUtils.cs index 2b4773a67..3c78d22b7 100644 --- a/src/client/spark/Orders/OrderUtils.cs +++ b/src/client/spark/Orders/OrderUtils.cs @@ -158,7 +158,9 @@ namespace mbts.spark { public static string display_name(this OrderSecurity order_tuple) => display_name(order_tuple.order, order_tuple.algo); - public static string display_name(OrderRecordImmutable order, AlgoData? algo) { + public static string display_name(OrderRecordImmutable order, AlgoData? algo, SecurityImmutable? security = null) { + if (order.order_type() == CustomOrderDefinition.CustomOneofCase.Spreader && security.HasValue) + return security.Value.ToString(); if (algo.HasValue) { return algo.Value.name; } else if (order.HasDef && order.Def.HasCustomDef) { @@ -250,7 +252,7 @@ namespace mbts.spark { order_type.ToString().ToUpper(); public static string display_name(this OrderSecurityAlgo order_sec_algo) => - display_name(order_sec_algo.order, order_sec_algo.algo); + display_name(order_sec_algo.order, order_sec_algo.algo, order_sec_algo.security); public static string display_name(this CustomOrderDefinitionImmutable algo) => algo.CustomCase == CustomOrderDefinition.CustomOneofCase.Dynamic ? algo.Dynamic.DynamicOrderType : algo.CustomCase.display_name(); diff --git a/src/client/spark/Orders/OrdersModel.cs b/src/client/spark/Orders/OrdersModel.cs index ffeceeb34..ccc189f82 100644 --- a/src/client/spark/Orders/OrdersModel.cs +++ b/src/client/spark/Orders/OrdersModel.cs @@ -210,6 +210,7 @@ namespace mbts.spark { // manual fills on_manual_fills_securities = _position_service.subscribei_manual_fills() .Naggle(interval, scheduler) + .Filter(f => f.FillType == ManualFill.Types.FillType.Local) .join(sstore, mf => mf.SecurityKey) .Table().Cache(); var manual_fill_tuples_account_join = on_manual_fills_securities.LeftJoin( diff --git a/src/client/spark/Predicates/Data/Events/OrderSentEventPredicate.cs b/src/client/spark/Predicates/Data/Events/OrderSentEventPredicate.cs new file mode 100644 index 000000000..f16dc8ed8 --- /dev/null +++ b/src/client/spark/Predicates/Data/Events/OrderSentEventPredicate.cs @@ -0,0 +1,80 @@ +using bts.api; +using bts.api.orderman; +using bts.shell; +using bts.utils; +using mbts.spark; +using mbts.ui.settings; +using ProtoBuf; +using System; +using System.Collections.Generic; +using System.ComponentModel; + +namespace mbts { + static class OrderSentEventPredicateVMFactory { + public static Dictionary> get_oneofs(IBus bus) => + new Dictionary> { + { OrderSentEventPredicate.PredicateTypeOneofCase.AnyOrder, PredicateVMWrapper.create(p => p.security = null) }, + { OrderSentEventPredicate.PredicateTypeOneofCase.SecurityOrder, SecurityCriteriaVMFactory.create(bus, o => o.security?.is_value ?? new SecurityCriteria(), + (p, s) => { + if (p.security == null) { + p.security = new SecurityPredicate(); + } + p.security.is_value = s; + }) + } + }; + } + + [ProtoContract] + class OrderSentEventPredicate : IEquatable { + static readonly int _type_hash = typeof(OrderSentEventPredicate).GetHashCode(); + // arbitrary short time period (can override in config) + static readonly TimeSpan _stale_order_threshold = TimeSpan.FromSeconds(config.Configuration.get().stale_order_threshold_seconds); + + public enum PredicateTypeOneofCase { + [Description("(any order)")] + AnyOrder, + [Description("choose securities")] + SecurityOrder + } + + [ProtoMember(1)] + public SecurityPredicate security { get; set; } + + public PredicateTypeOneofCase predicate_type_case { + get { + if (security != null) + return PredicateTypeOneofCase.SecurityOrder; + return PredicateTypeOneofCase.AnyOrder; + } + } + + public IPredicate create(object obj) => + create_predicate((INotificationServiceDataCache)obj); + + public IPredicate create_predicate(INotificationServiceDataCache data_cache) { + var sec_pred = security?.create(); + return PredicateBuilder.create(os => + // verify security + (sec_pred == null || (os.security.HasValue && sec_pred.trigger(os.security.Value))) && + // verify not stale + ((DateTime.Now - os.order.created()) < _stale_order_threshold) && + // verify order hasn't been added yet + // Note: the notification service should offer a way to connect predicates so that they only receive items in TableUpdate.added, + // however, the notification service predated TableUpdate.Changes, so for now, just check that the history.Count == 1) + (data_cache.order_history.TryGetValue(os.order.Key, out var hist) && hist.Count == 1)); + } + + public INotificationPredicate create_toast(INotificationServiceDataCache data_cache) => + throw new NotImplementedException(); + + public bool Equals(OrderSentEventPredicate other) => + other != null && other.security.safe_equals(other.security); + + public override bool Equals(object obj) => + Equals(obj as OrderSentEventPredicate); + + public override int GetHashCode() => + EqualityComparer.auto_phase(_type_hash, security?.GetHashCode() ?? 0); + } +} \ No newline at end of file diff --git a/src/client/spark/Predicates/Data/OrderRecordTuplePredicate.cs b/src/client/spark/Predicates/Data/OrderRecordTuplePredicate.cs index c137f7d0b..be4a346fb 100644 --- a/src/client/spark/Predicates/Data/OrderRecordTuplePredicate.cs +++ b/src/client/spark/Predicates/Data/OrderRecordTuplePredicate.cs @@ -5,14 +5,9 @@ using bts.utils; using mbts.spark; using mbts.ui; using mbts.ui.settings; -using mbts.ui.utility; -using mbts.utils; using ProtoBuf; using System; using System.Collections.Generic; -using System.Linq; -using System.Reactive.Linq; -using OrderType = bts.api.orderman.CustomOrderDefinition.CustomOneofCase; using PTOC = mbts.OrderRecordTuplePredicate.PredicateTypeOneofCase; namespace mbts { @@ -20,6 +15,7 @@ namespace mbts { // TODO: uncomment the remaining cases when ready public static Dictionary> get_oneofs(IBus bus, OrdersModel orders_model) { return new Dictionary> { + { PTOC.SentEvent, wrap(rp => rp.sent_event, (rp, p) => rp.sent_event = p, p => p.predicate_type_case, OrderSentEventPredicateVMFactory.get_oneofs(bus)) }, { PTOC.FilledEvent, wrap(rp => rp.filled_event, (rp, p) => rp.filled_event = p, p => p.predicate_type_case, OrderFilledEventPredicateVMFactory.get_oneofs(bus)) }, { PTOC.CompletedEvent, wrap(rp => rp.completed_event, (rp, p) => rp.completed_event = p, p => p.predicate_type_case, OrderCompletedEventPredicateVMFactory.get_oneofs(bus)) }, { PTOC.CanceledEvent, wrap(rp => rp.canceled_event, (rp, p) => rp.canceled_event = p, p => p.predicate_type_case, OrderCanceledEventPredicateVMFactory.get_oneofs(bus)) }, @@ -77,6 +73,7 @@ namespace mbts { OrderFilledEventPredicate _filled_event; OrderCompletedEventPredicate _completed_event; OrderCanceledEventPredicate _canceled_event; + OrderSentEventPredicate _sent_event; public enum PredicateTypeOneofCase { None, @@ -120,6 +117,8 @@ namespace mbts { OrderKey, [PredicateCase(is_toastable:false)] ParentKey, + [PredicateCase("When order is sent", PredicateCategory.Event)] + SentEvent, [PredicateCase("When order gets a fill", PredicateCategory.Event)] FilledEvent, [PredicateCase("When order is completed", PredicateCategory.Event)] @@ -176,6 +175,8 @@ namespace mbts { public OrderCompletedEventPredicate completed_event { get => _completed_event; set => _set(ref _completed_event, value); } [ProtoMember(23)] public OrderCanceledEventPredicate canceled_event { get => _canceled_event; set => _set(ref _canceled_event, value); } + [ProtoMember(26)] + public OrderSentEventPredicate sent_event { get => _sent_event; set => _set(ref _sent_event, value); } [ProtoMember(24)] public bool is_toast_enabled { get; set; } [ProtoMember(25)] @@ -206,6 +207,7 @@ namespace mbts { if (_filled_event != null) return PTOC.FilledEvent; if (_completed_event != null) return PTOC.CompletedEvent; if (_canceled_event != null) return PTOC.CanceledEvent; + if (_sent_event != null) return PTOC.SentEvent; if (_attached_target_order_key != null) return PTOC.AttachedTargetOrderKey; return PTOC.None; } @@ -236,6 +238,7 @@ namespace mbts { case PTOC.FilledEvent: return _filled_event.create_predicate(data_cache); case PTOC.CompletedEvent: return _completed_event.create_predicate(data_cache); case PTOC.CanceledEvent: return _canceled_event.create(data_cache); + case PTOC.SentEvent: return _sent_event.create(data_cache); case PTOC.AttachedTargetOrderKey: return wrap(_attached_target_order_key.create(), r => r.order.attached_target_order_key()); default: return null; } @@ -285,6 +288,7 @@ namespace mbts { case PTOC.FilledEvent: return _filled_event.Equals(other._filled_event); case PTOC.CompletedEvent: return _completed_event.Equals(other._completed_event); case PTOC.CanceledEvent: return _canceled_event.Equals(other._canceled_event); + case PTOC.SentEvent: return _sent_event.Equals(other._sent_event); case PTOC.AttachedTargetOrderKey: return _attached_target_order_key.Equals(other._attached_target_order_key); case PTOC.None: return true; default: throw ExceptionHelper.unexpected_oneof_case(ptoc); @@ -320,6 +324,7 @@ namespace mbts { case PTOC.FilledEvent: raw_hash = _filled_event.GetHashCode(); break; case PTOC.CompletedEvent: raw_hash = _completed_event.GetHashCode(); break; case PTOC.CanceledEvent: raw_hash = _canceled_event.GetHashCode(); break; + case PTOC.SentEvent: raw_hash = _sent_event.GetHashCode(); break; case PTOC.AttachedTargetOrderKey: raw_hash = _attached_target_order_key.GetHashCode(); break; case PTOC.None: raw_hash = 0; break; default: throw ExceptionHelper.unexpected_oneof_case(ptoc); @@ -355,6 +360,7 @@ namespace mbts { _filled_event = null; _completed_event = null; _canceled_event = null; + _sent_event = null; _attached_target_order_key = null; } field = value; diff --git a/src/client/spark/core/GlobalExtensions/DoubleHelper.cs b/src/client/spark/core/GlobalExtensions/DoubleHelper.cs index 747747963..4b9292936 100644 --- a/src/client/spark/core/GlobalExtensions/DoubleHelper.cs +++ b/src/client/spark/core/GlobalExtensions/DoubleHelper.cs @@ -1,7 +1,36 @@ -using System.Linq; +using System; +using System.Linq; namespace mbts { public static class DoubleHelper { + public static bool any_nan_or_infinity(params double[] values) { + for (int i = 0; i < values.Length; i++) { + if (double.IsNaN(values[i]) || double.IsInfinity(values[i])) + return true; + } + return false; + } + + public static bool are_close(double v1, double v2, double threshold) => + !any_nan_or_infinity(v1, v2, threshold) && Math.Abs(threshold) > Math.Abs(v1 - v2); + + // bc double.IsNaN gets annoying write, and a lazy programmer is a happy programmer ;) + public static bool is_nan(this double value) => + double.IsNaN(value); + + /// + /// If the specified value is a , , or , returns the equivalent ; otherwise, returns . + /// + /// The value to convert to a . + /// The equivalent value if the cast succeeds, otherwise . + public static double nan_cast(object value) { + // devs: add numeric type checks as needed + if (value is double d) return d; + if (value is int i) return i; + if (value is uint u) return u; + return double.NaN; + } + public static bool IsNaNOrInfinity(double d) => double.IsNaN(d) || double.IsInfinity(d); public static bool IsNaNOrInfinityOr(double d, params double[] values) => IsNaNOrInfinity(d) || values.Contains(d); public static bool IsOneOf(double d, params double[] values) => values.Contains(d); diff --git a/src/client/spark/view/Controls/DIYGrid/DoubleUtil.cs b/src/client/spark/view/Controls/DIYGrid/DoubleUtil.cs index aa2019135..cce6cb9bc 100644 --- a/src/client/spark/view/Controls/DIYGrid/DoubleUtil.cs +++ b/src/client/spark/view/Controls/DIYGrid/DoubleUtil.cs @@ -4,6 +4,8 @@ using System.Linq; namespace mbts.ui.controls { static class DoubleUtil { public const int API_DECIMAL_PRECISION = 9; + // arbitrary small number that can be used to determine whether or not scroll changes are significant + public const double MIN_SCROLL_DELTA = 0.000015; /* smallest such that 1.0+DBL_EPSILON != 1.0 */ private const double EPSILON = 2.2204460492503131e-016; private const double BIG_EPSILON = EPSILON * 10; diff --git a/src/client/spark/view/Converters/AnonymousValueConverter.cs b/src/client/spark/view/Converters/AnonymousValueConverter.cs index 93ce4aa32..2e1df9262 100644 --- a/src/client/spark/view/Converters/AnonymousValueConverter.cs +++ b/src/client/spark/view/Converters/AnonymousValueConverter.cs @@ -11,6 +11,9 @@ namespace mbts.ui.converters { public static IValueConverter create(Func convert) => new AnonymousValueConverter(convert); + public static IValueConverter create(Func convert, Func convert_back) => + new AnonymousValueConverter(convert, convert_back); + public static IMultiValueConverter create(Func convert) => new AnonymousMultiValueConverter(convert); diff --git a/src/client/spark/view/Extensions/FrameworkElementExtensions.cs b/src/client/spark/view/Extensions/FrameworkElementExtensions.cs index 5e1fca80f..56bc99d47 100644 --- a/src/client/spark/view/Extensions/FrameworkElementExtensions.cs +++ b/src/client/spark/view/Extensions/FrameworkElementExtensions.cs @@ -9,6 +9,29 @@ using CompositeDisposable = System.Reactive.Disposables.CompositeDisposable; namespace mbts.ui.extensions { static class FrameworkElementHelper { + /// + /// Invokes the specified action immediately if the element is already loaded, otherwise hooks up to the event, + /// and [conditionally]invokes the specified action if returns true. + /// + /// The element that must be loaded before the specified action is invoked. + /// The action to invoke when the element is loaded. + /// If the element is not already loaded, this delegate determines whether or not to invoke the action in the Loaded event callback. + /// + public static void InvokeOnLoaded(this FrameworkElement element, Action action, Func should_still_execute) { + if (action == null) + throw new ArgumentNullException(nameof(action)); + if (element.IsLoaded) { + action(); + } else { + element.Loaded += on_loaded; + void on_loaded(object sender, RoutedEventArgs e) { + element.Loaded -= on_loaded; + if (should_still_execute()) + action(); + } + } + } + public static Point GetCenter(this FrameworkElement element) => new Point(element.ActualWidth * 0.5, element.ActualHeight * 0.5); diff --git a/src/client/spark/view/Extensions/ScrollViewerBehavior.cs b/src/client/spark/view/Extensions/ScrollViewerBehavior.cs new file mode 100644 index 000000000..e9db14fd4 --- /dev/null +++ b/src/client/spark/view/Extensions/ScrollViewerBehavior.cs @@ -0,0 +1,61 @@ +using mbts.ui.controls; +using mbts.ui.extensions; +using System.Windows; +using System.Windows.Controls; + +namespace mbts.ui { + static class ScrollViewerBehavior { + public static readonly DependencyProperty VerticalOffsetProperty = + DependencyProperty.RegisterAttached("VerticalOffset", typeof(double), typeof(ScrollViewerBehavior), new PropertyMetadata(double.NaN, OnVerticalOffsetChanged)); + + static void OnVerticalOffsetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { + if (d is ScrollViewer scroll) { + double voff = DoubleHelper.nan_cast(e.NewValue); + // Ignore small deltas to prevent strange layout rounding issues/loops. + // Be mindful that small deltas are not accumulated into a single larger delta. + if (!double.IsNaN(voff) && !DoubleHelper.are_close(DoubleHelper.nan_cast(e.OldValue), voff, DoubleUtil.MIN_SCROLL_DELTA)) { + scroll.InvokeOnLoaded(() => scroll.ScrollToVerticalOffset(voff), + () => scroll.GetValue(VerticalOffsetProperty) is double curr_voff && curr_voff == voff); + } + } + } + + public static double GetVerticalOffset(DependencyObject d) => (double)d.GetValue(VerticalOffsetProperty); + public static void SetVerticalOffset(DependencyObject d, double value) => d.SetValue(VerticalOffsetProperty, value); + + public static readonly DependencyProperty EnableTwoWayVerticalOffsetBindingProperty = + DependencyProperty.RegisterAttached("EnableTwoWayVerticalOffsetBinding", typeof(bool), typeof(ScrollViewerBehavior), new PropertyMetadata(false, OnEnableTwoWayVerticalOffsetBindingChanged)); + + static void OnEnableTwoWayVerticalOffsetBindingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { + if (d is ScrollViewer scroll) { + if ((bool)e.NewValue) { + scroll.ScrollChanged += EnableTwoWayVerticalOffsetBindingUtils.on_scroll_changed; + } else { + scroll.ScrollChanged -= EnableTwoWayVerticalOffsetBindingUtils.on_scroll_changed; + } + } + } + + public static bool GetEnableTwoWayVerticalOffsetBinding(DependencyObject d) => (bool)d.GetValue(EnableTwoWayVerticalOffsetBindingProperty); + public static void SetEnableTwoWayVerticalOffsetBinding(DependencyObject d, bool value) => d.SetValue(EnableTwoWayVerticalOffsetBindingProperty, value); + + public static readonly DependencyProperty VerticalOffsetMirrorBusyProperty = + DependencyProperty.RegisterAttached("VerticalOffsetMirrorBusy", typeof(bool), typeof(ScrollViewerBehavior), new PropertyMetadata(false)); + + static class EnableTwoWayVerticalOffsetBindingUtils { + public static void on_scroll_changed(object sender, ScrollChangedEventArgs e) { + if (e.VerticalChange != 0 && sender is ScrollViewer scroll) { + if (!(bool)scroll.GetValue(VerticalOffsetMirrorBusyProperty)) { + scroll.SetValue(VerticalOffsetMirrorBusyProperty, true); + // scroll changes could get noisy while layouts are being processed; + // let everything settle down before updating the VerticalOffset binding sources/targets. + scroll.Dispatcher.InvokeAsync(() => { + scroll.SetCurrentValue(VerticalOffsetProperty, scroll.VerticalOffset); + scroll.SetValue(VerticalOffsetMirrorBusyProperty, false); + }, System.Windows.Threading.DispatcherPriority.ApplicationIdle); + } + } + } + } + } +} \ No newline at end of file diff --git a/src/client/spark/view/Extensions/UIElementExtensions.cs b/src/client/spark/view/Extensions/UIElementExtensions.cs index 0e5924fd2..3b48769a0 100644 --- a/src/client/spark/view/Extensions/UIElementExtensions.cs +++ b/src/client/spark/view/Extensions/UIElementExtensions.cs @@ -236,6 +236,14 @@ namespace mbts.ui.extensions { target.ScrollChanged += callback; return Disposable.Create(() => target.ScrollChanged -= callback); } + + public static bool TryScrollToVerticalOffset(this ScrollViewer scroll_viewer, double vertical_offset) { + if (vertical_offset >= 0 && scroll_viewer.IsLoaded && vertical_offset < scroll_viewer.ExtentHeight - scroll_viewer.ViewportHeight) { + scroll_viewer.ScrollToVerticalOffset(vertical_offset); + return true; + } + return false; + } } public static class TextBoxExtensions { diff --git a/src/client/spark/view/Shell/Settings/ShellSettingsDialogVM.cs b/src/client/spark/view/Shell/Settings/ShellSettingsDialogVM.cs index b51a4989a..6cc76049e 100644 --- a/src/client/spark/view/Shell/Settings/ShellSettingsDialogVM.cs +++ b/src/client/spark/view/Shell/Settings/ShellSettingsDialogVM.cs @@ -130,8 +130,10 @@ namespace mbts.spark { DialogSkirtItem _apply_item, _ok_item, _cancel_item; MenuItemVM _import_item, _export_item, _load_factory_item; - public ProfiledShellSettingsDialogVM(ISettingsProfileService profile_service, Func get_fallback, Func vm_factory, Func normalize, T init, string file_ext, uint settings_id = 0) { + public ProfiledShellSettingsDialogVM(ISettingsProfileService profile_service, Func get_fallback, Func vm_factory, Func normalize, T init, string file_ext, Func profile_equals = null, uint settings_id = 0) { _vm_factory = vm_factory; + if (profile_equals == null) + profile_equals = EqualityComparer.Default.Equals; // profile collections var skip_local = profiles.WrapSkip(1); var skip_local_wrapper = skip_local.WrapSelector( @@ -185,12 +187,19 @@ namespace mbts.spark { continue; i = ~i; var temp = ns.with(value: normalize(ns.value)); - skip_local_wrapper.Insert(i, temp); if (settings_id == temp.id) { - if (temp.value.Equals(init)) - selected_profile = skip_local[i]; settings_id = 0; + if (profile_equals(temp.value, init)) { + if (!temp.value.Equals(init)) { + // they aren't exactly equal (don't overwrite any props in 'init' - use it to create the vm) + temp = temp.with(value: init); + } + skip_local_wrapper.Insert(i, temp); + selected_profile = skip_local[i]; + continue; + } } + skip_local_wrapper.Insert(i, temp); } })); diff --git a/src/lib/config/defaults/cme_reference_data.conf b/src/lib/config/defaults/cme_reference_data.conf index b0e734abe..ae2a5d4d7 100644 --- a/src/lib/config/defaults/cme_reference_data.conf +++ b/src/lib/config/defaults/cme_reference_data.conf @@ -3,11 +3,10 @@ # source: tools/cpp_helper/generate-cpps.ps1 # -CppConfig -{ - value +CppConfig +{ + value { - cpp_entry { key: "098" value: 2000 } cpp_entry { key: "0A" value: 100 } cpp_entry { key: "0B" value: 100 } cpp_entry { key: "0C" value: 100 } @@ -459,9 +458,9 @@ CppConfig cpp_entry { key: "DDE" value: 1000 } cpp_entry { key: "DDI" value: 1000 } cpp_entry { key: "DDO" value: 1000 } - cpp_entry { key: "DEB" value: 720 } + cpp_entry { key: "DEB" value: 745 } cpp_entry { key: "DEN" value: 250 } - cpp_entry { key: "DEP" value: 252 } + cpp_entry { key: "DEP" value: 276 } cpp_entry { key: "DFL" value: 100 } cpp_entry { key: "DFN" value: 100 } cpp_entry { key: "DG2" value: 100 } @@ -730,8 +729,8 @@ CppConfig cpp_entry { key: "IPO" value: 10 } cpp_entry { key: "IPT" value: 10 } cpp_entry { key: "IS" value: 50 } - cpp_entry { key: "ITB" value: 720 } - cpp_entry { key: "ITP" value: 252 } + cpp_entry { key: "ITB" value: 745 } + cpp_entry { key: "ITP" value: 276 } cpp_entry { key: "IW" value: 50 } cpp_entry { key: "J4L" value: 80 } cpp_entry { key: "J7" value: 6250000 } @@ -773,7 +772,6 @@ CppConfig cpp_entry { key: "K5" value: 20 } cpp_entry { key: "K5K" value: 20 } cpp_entry { key: "K5N" value: 20 } - cpp_entry { key: "KC" value: 375 } cpp_entry { key: "KE" value: 50 } cpp_entry { key: "KET" value: 50 } cpp_entry { key: "KQ" value: 20 } @@ -809,6 +807,7 @@ CppConfig cpp_entry { key: "LIY" value: 1000 } cpp_entry { key: "LL" value: 42000 } cpp_entry { key: "LLR" value: 1000 } + cpp_entry { key: "LNG" value: 10000 } cpp_entry { key: "LPE" value: 47000 } cpp_entry { key: "LPS" value: 1000 } cpp_entry { key: "LSF" value: 1 } @@ -1003,7 +1002,6 @@ CppConfig cpp_entry { key: "OAD" value: 1 } cpp_entry { key: "ODO" value: 1000 } cpp_entry { key: "OFF" value: 5 } - cpp_entry { key: "OJ" value: 150 } cpp_entry { key: "OML" value: 5 } cpp_entry { key: "OMM" value: 80 } cpp_entry { key: "OOD" value: 5 } @@ -1146,7 +1144,7 @@ CppConfig cpp_entry { key: "SBT" value: 50 } cpp_entry { key: "SD" value: 1000 } cpp_entry { key: "SDA" value: 250 } - cpp_entry { key: "SDD" value: 1600 } + cpp_entry { key: "SDD" value: 1840 } cpp_entry { key: "SDG" value: 250 } cpp_entry { key: "SDI" value: 1000 } cpp_entry { key: "SDM" value: 100 } @@ -1163,10 +1161,12 @@ CppConfig cpp_entry { key: "SFR" value: 250 } cpp_entry { key: "SG" value: 250 } cpp_entry { key: "SGB" value: 1000 } + cpp_entry { key: "SGC" value: 1000 } cpp_entry { key: "SGE" value: 42000 } cpp_entry { key: "SGF" value: 1000 } cpp_entry { key: "SGG" value: 1000 } cpp_entry { key: "SGT" value: 250 } + cpp_entry { key: "SGU" value: 32.15 } cpp_entry { key: "SI" value: 5000 } cpp_entry { key: "SIL" value: 1000 } cpp_entry { key: "SIR" value: 500 } @@ -1185,7 +1185,7 @@ CppConfig cpp_entry { key: "SR3" value: 2500 } cpp_entry { key: "SR5" value: 1000 } cpp_entry { key: "SRB" value: 1000 } - cpp_entry { key: "SRT" value: 1600 } + cpp_entry { key: "SRT" value: 1840 } cpp_entry { key: "SSI" value: 1000 } cpp_entry { key: "SSP" value: 5000 } cpp_entry { key: "SSW" value: 1000 } @@ -1197,31 +1197,31 @@ CppConfig cpp_entry { key: "SU" value: 250 } cpp_entry { key: "SUT" value: 250 } cpp_entry { key: "T01" value: 800 } - cpp_entry { key: "T02" value: 800 } - cpp_entry { key: "T03" value: 800 } cpp_entry { key: "T04" value: 800 } + cpp_entry { key: "T05" value: 800 } + cpp_entry { key: "T06" value: 800 } cpp_entry { key: "T07" value: 800 } cpp_entry { key: "T08" value: 800 } - cpp_entry { key: "T09" value: 800 } - cpp_entry { key: "T10" value: 800 } cpp_entry { key: "T11" value: 800 } cpp_entry { key: "T12" value: 800 } cpp_entry { key: "T13" value: 800 } + cpp_entry { key: "T15" value: 800 } cpp_entry { key: "T16" value: 800 } cpp_entry { key: "T17" value: 800 } cpp_entry { key: "T18" value: 800 } - cpp_entry { key: "T19" value: 800 } cpp_entry { key: "T1U" value: 1000 } - cpp_entry { key: "T20" value: 800 } + cpp_entry { key: "T21" value: 800 } + cpp_entry { key: "T22" value: 800 } cpp_entry { key: "T23" value: 800 } cpp_entry { key: "T24" value: 800 } cpp_entry { key: "T25" value: 800 } - cpp_entry { key: "T26" value: 800 } - cpp_entry { key: "T27" value: 800 } + cpp_entry { key: "T28" value: 800 } + cpp_entry { key: "T29" value: 800 } cpp_entry { key: "T2B" value: 1000 } cpp_entry { key: "T2D" value: 1000 } cpp_entry { key: "T2M" value: 100 } cpp_entry { key: "T30" value: 800 } + cpp_entry { key: "T31" value: 800 } cpp_entry { key: "T3B" value: 1000 } cpp_entry { key: "T3L" value: 80 } cpp_entry { key: "T4B" value: 1000 } @@ -1276,7 +1276,7 @@ CppConfig cpp_entry { key: "TT" value: 50000 } cpp_entry { key: "TTD" value: 24 } cpp_entry { key: "TTE" value: 10000 } - cpp_entry { key: "TTF" value: 720 } + cpp_entry { key: "TTF" value: 745 } cpp_entry { key: "TUB" value: 1000 } cpp_entry { key: "TUF" value: 1000 } cpp_entry { key: "TUL" value: 1000 } @@ -1299,7 +1299,7 @@ CppConfig cpp_entry { key: "UFU" value: 100 } cpp_entry { key: "UFV" value: 100 } cpp_entry { key: "UGG" value: 42000 } - cpp_entry { key: "UKG" value: 300 } + cpp_entry { key: "UKG" value: 310 } cpp_entry { key: "ULB" value: 42000 } cpp_entry { key: "UMB" value: 1000 } cpp_entry { key: "UMD" value: 1000 } @@ -1457,14 +1457,13 @@ CppConfig cpp_entry { key: "ZT" value: 2000 } cpp_entry { key: "ZW" value: 50 } cpp_entry { key: "ZWT" value: 50 } - } -} + } +} -CmeSymbolMics -{ - value +CmeSymbolMics +{ + value { - cme_mic { key: "098" value: CBT } cme_mic { key: "0A" value: NYMEX } cme_mic { key: "0B" value: NYMEX } cme_mic { key: "0C" value: NYMEX } @@ -2265,6 +2264,7 @@ CmeSymbolMics cme_mic { key: "LIY" value: CBT } cme_mic { key: "LL" value: NYMEX } cme_mic { key: "LLR" value: NYMEX } + cme_mic { key: "LNG" value: NYMEX } cme_mic { key: "LPE" value: NYMEX } cme_mic { key: "LPS" value: NYMEX } cme_mic { key: "LSF" value: COMEX } @@ -2618,10 +2618,12 @@ CmeSymbolMics cme_mic { key: "SFR" value: CME } cme_mic { key: "SG" value: CME } cme_mic { key: "SGB" value: NYMEX } + cme_mic { key: "SGC" value: COMEX } cme_mic { key: "SGE" value: NYMEX } cme_mic { key: "SGF" value: NYMEX } cme_mic { key: "SGG" value: NYMEX } cme_mic { key: "SGT" value: CME } + cme_mic { key: "SGU" value: COMEX } cme_mic { key: "SI" value: COMEX } cme_mic { key: "SIL" value: COMEX } cme_mic { key: "SIR" value: CME } @@ -2652,31 +2654,31 @@ CmeSymbolMics cme_mic { key: "SU" value: CME } cme_mic { key: "SUT" value: CME } cme_mic { key: "T01" value: NYMEX } - cme_mic { key: "T02" value: NYMEX } - cme_mic { key: "T03" value: NYMEX } cme_mic { key: "T04" value: NYMEX } + cme_mic { key: "T05" value: NYMEX } + cme_mic { key: "T06" value: NYMEX } cme_mic { key: "T07" value: NYMEX } cme_mic { key: "T08" value: NYMEX } - cme_mic { key: "T09" value: NYMEX } - cme_mic { key: "T10" value: NYMEX } cme_mic { key: "T11" value: NYMEX } cme_mic { key: "T12" value: NYMEX } cme_mic { key: "T13" value: NYMEX } + cme_mic { key: "T15" value: NYMEX } cme_mic { key: "T16" value: NYMEX } cme_mic { key: "T17" value: NYMEX } cme_mic { key: "T18" value: NYMEX } - cme_mic { key: "T19" value: NYMEX } cme_mic { key: "T1U" value: CBT } - cme_mic { key: "T20" value: NYMEX } + cme_mic { key: "T21" value: NYMEX } + cme_mic { key: "T22" value: NYMEX } cme_mic { key: "T23" value: NYMEX } cme_mic { key: "T24" value: NYMEX } cme_mic { key: "T25" value: NYMEX } - cme_mic { key: "T26" value: NYMEX } - cme_mic { key: "T27" value: NYMEX } + cme_mic { key: "T28" value: NYMEX } + cme_mic { key: "T29" value: NYMEX } cme_mic { key: "T2B" value: NYMEX } cme_mic { key: "T2D" value: NYMEX } cme_mic { key: "T2M" value: NYMEX } cme_mic { key: "T30" value: NYMEX } + cme_mic { key: "T31" value: NYMEX } cme_mic { key: "T3B" value: NYMEX } cme_mic { key: "T3L" value: NYMEX } cme_mic { key: "T4B" value: NYMEX } @@ -2912,5 +2914,5 @@ CmeSymbolMics cme_mic { key: "ZT" value: CBT } cme_mic { key: "ZW" value: CBT } cme_mic { key: "ZWT" value: CBT } - } + } } diff --git a/src/lib/config/protos/UI.proto b/src/lib/config/protos/UI.proto index e926428e4..0a557f5bb 100644 --- a/src/lib/config/protos/UI.proto +++ b/src/lib/config/protos/UI.proto @@ -78,6 +78,13 @@ message OrderBookOptions { optional double status_color_opacity_when_selected = 2 [default = 0.35]; } +message OrderAlerts { + // when the client sees an order for the first time, + // this time period is used to determine if the order is actually new, + // or [presumably]just arrived bc shell is still initializing, or the server restarted. + optional int32 stale_order_threshold_seconds = 1 [default = 60]; +} + message ShellPingOptions { optional bool shell_ping_is_enabled = 1 [default = true]; optional int32 workloop_milliseconds_interval = 2 [default = 5000]; diff --git a/src/lib/config/protos/toggles.proto b/src/lib/config/protos/toggles.proto index 5c3c87ee0..787cbf7e0 100644 --- a/src/lib/config/protos/toggles.proto +++ b/src/lib/config/protos/toggles.proto @@ -61,4 +61,10 @@ message EnsureOnScreenWithWorkAreaRect { message IgnoreNansInDayPnL { optional bool enabled = 1 [default = true]; +} + +message DynamicAlgos{ + optional bool enable_dorman = 1 [default = false]; + optional bool enable_pyramid = 2 [default = false]; + optional bool enable_tas = 3 [default = false]; } \ No newline at end of file diff --git a/src/lib/domain_model/Security.h b/src/lib/domain_model/Security.h index 80444d860..697678f5b 100644 --- a/src/lib/domain_model/Security.h +++ b/src/lib/domain_model/Security.h @@ -43,6 +43,8 @@ inline api::Side other_side(api::Side side) { inline double market_epislon() { return 1e-10; } +// better == p1 more aggressive than p1 ie for a buy order p1 is higher +// than p2, and for a sell order p1 is lower than p2 inline bool is_better(api::Side side, Price p1, Price p2) { switch (side) { case api::SIDE_BUY: @@ -54,6 +56,7 @@ inline bool is_better(api::Side side, Price p1, Price p2) { } } +// like the above function inline Price improve_price(api::Side side, Price p, Price offset) { switch (side) { case api::SIDE_BUY: @@ -169,13 +172,30 @@ inline Price tick_size(api::Security const &sec) { // Looking to round md::IntPrice? Look in IntPrice.h -// computes the difference between 2 prices in ticks. -// the result is an a signed int so the order of args -// matter, its second price - first price +// computes price_2 - price_1 in ticks inline int price_diff_to_ticks(double price_1, double price_2, double tick_size) { return static_cast(std::round((price_2 - price_1) / tick_size)); } +// returns the difference (in ticks) bw and order and a market. +// if the order has crossed the market, returns -ve ticks +// (ie the buy order price > market_price or +// sell_order_price < market_price) +inline int order_diff_market(double order_price, + double market_price, + api::Side side, + double tick_size){ + switch (side) { + case api::SIDE_BUY: + return price_diff_to_ticks(order_price,market_price,tick_size); + case api::SIDE_SELL: + return price_diff_to_ticks(market_price,order_price,tick_size); + default: + bts_assert(false); + break; + } + return 0; +} // because of prices not being completely rounded to the tick, // simple double equality can not be used to compare prices. // this function deems 2 prices to be equal if they are within diff --git a/src/lib/orderman/orders/algo/algo_orders/RegisterDorman.cpp b/src/lib/orderman/orders/algo/algo_orders/RegisterDorman.cpp index 29930db8b..70cecbb4b 100644 --- a/src/lib/orderman/orders/algo/algo_orders/RegisterDorman.cpp +++ b/src/lib/orderman/orders/algo/algo_orders/RegisterDorman.cpp @@ -3,6 +3,8 @@ #include "lib/api/services/OrderService.pb.h" #include "lib/logging/logging.h" #include "lib/orderman/orderman_utils/orderman_utils.h" +#include "lib/config/protos/toggles.pb.h" +#include "lib/config/config.h" #include "DormanAlgo.h" #include "PyramidAlgo.h" #include "TASAlgo.h" @@ -159,8 +161,13 @@ extern "C" void init_tas_plugin(bts::SparkServices& srv) { } extern "C" void init_spark_plugin(bts::SparkServices &srv) { - init_dorman_plugin(srv); - init_tas_plugin(srv); + auto dyn_algo_config = config::get(); + if(dyn_algo_config.enable_dorman()) + init_dorman_plugin(srv); + if(dyn_algo_config.enable_pyramid()) + init_pyramid_plugin(srv); + if(dyn_algo_config.enable_tas()) + init_tas_plugin(srv); } }}} \ No newline at end of file diff --git a/src/lib/orderman/orders/spreader_orders/SpreaderOrder.cpp b/src/lib/orderman/orders/spreader_orders/SpreaderOrder.cpp index 32d552e99..262f70c87 100644 --- a/src/lib/orderman/orders/spreader_orders/SpreaderOrder.cpp +++ b/src/lib/orderman/orders/spreader_orders/SpreaderOrder.cpp @@ -463,6 +463,7 @@ void SpreaderOrder::_comp_and_report_state (){ reported_state.set_quantity(bookkeeping_data.quantity().value()); reported_state.set_filled_quantity(filled_qty.value()); reported_state.set_avg_price(avg_filled_price.value()); + reported_state.set_last_price(avg_filled_price.value()); } // if order is cons'ed from disc, with inited_new==false, // we just publish what was given to us diff --git a/src/lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h b/src/lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h index 559fa2c96..683a75832 100644 --- a/src/lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h +++ b/src/lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h @@ -9,6 +9,7 @@ #include "lib/orderman/orders/spreader_orders/spreader/quoter/QuoteLegDriver.h" #include "lib/api/services/OrderService.pb.h" #include "lib/orderman/actors/order_manager/OrderBuilder.h" +#include "lib/os/os.h" #include namespace bts { @@ -284,35 +285,66 @@ public: //////////////////////////////////////////////////// // quoting params ////////////////////////////////// //////////////////////////////////////////////////// - // given the new price, applies the quoting parameters (mute etc) - // to see if quote needs to be repriced - static bool reprice_quote_mute_zone(double current_price, - double new_price, - api::Side quote_side, - double tick_size, - const bts::spark::QuoteMuteZone& quote_mute_zone){ - int price_change_ticks = bts::securities::price_diff_to_ticks (current_price, new_price, tick_size); - if (price_change_ticks != 0){ - bool price_increasing = price_change_ticks > 0; - uint32_t abs_price_change_ticks = static_cast(std::abs(price_change_ticks)); - LOG(OrderMan, Diag, "SpreaderUtils::reprice_quote_mute_zone current_price: {} new_price: {} price_change_ticks: {} abs_price_change_ticks: {} inside_limit_ticks: {} outside_limit_ticks: {}", - current_price, new_price, price_change_ticks, abs_price_change_ticks, quote_mute_zone.inside_ticks(), quote_mute_zone.outside_ticks()); - if (quote_side == api::SIDE_BUY){ - if (price_increasing) // moving toward inside market - return abs_price_change_ticks > quote_mute_zone.inside_ticks(); - else - return abs_price_change_ticks > quote_mute_zone.outside_ticks(); - } - else{ - if (!price_increasing) // moving toward inside market - return abs_price_change_ticks > quote_mute_zone.inside_ticks(); - else - return abs_price_change_ticks > quote_mute_zone.outside_ticks(); - } - } - else - return false; + static bool is_throttle_reject(double current_price, + double new_price, + const Book& qbook, + api::Side quote_side, + double tick_size, + const bts::spark::QuoteParams& quote_params){ + + bool reject = + (quote_params.has_quote_mute_zone() && + is_quote_mute_zone_reject(current_price, + new_price, + quote_side, + tick_size, + quote_params.quote_mute_zone())) || + (quote_params.has_quote_inside_market_distance_throttle() && + is_quote_inside_market_reject(current_price, + new_price, + qbook.side(quote_side)[0].price(), + quote_side, + tick_size, + quote_params.quote_inside_market_distance_throttle())); + return reject; } + + // returns true is quote mute zone rejects the price change + static bool is_quote_mute_zone_reject(double current_price, + double new_price, + api::Side quote_side, + double tick_size, + const bts::spark::QuoteMuteZone& quote_mute_zone){ + int ticks_moved = bts::securities::price_diff_to_ticks(current_price, new_price, tick_size); + bool toward_inside = quote_side==api::Side::SIDE_BUY ? ticks_moved >=0 : ticks_moved <= 0; + uint32_t throttle = toward_inside ? quote_mute_zone.inside_ticks() : + quote_mute_zone.outside_ticks(); + uint32_t abs_ticks_moved = static_cast(std::abs(ticks_moved)); + // has to move outside of the zone + return abs_ticks_moved <= throttle; + } + // returns false if the param surpresses the quote + static bool is_quote_inside_market_reject( + double current_price, + double new_price, + double inside_market, + api::Side quote_side, + double tick_size, + const bts::spark::QuoteInsideMarketDistanceThrottle& imd){ + bool toward = bts::securities::is_equal_or_better(quote_side, + Price(new_price), + Price(current_price)); + if(toward && !os::is_nan(inside_market)){ + int new_order_diff_market = bts::securities::order_diff_market( + new_price, + inside_market, + quote_side, + tick_size); + return new_order_diff_market > static_cast(imd.on_toward_distance()); + } + return false; + } + static bool conditional_quoting(Price quoting_price, Quantity quoting_qty, size_t leg_idx, diff --git a/src/lib/orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWorkingStateWorker.cpp b/src/lib/orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWorkingStateWorker.cpp index 14c5d30f4..12ace9abf 100644 --- a/src/lib/orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWorkingStateWorker.cpp +++ b/src/lib/orderman/orders/spreader_orders/spreader/quoter/quoter_states/QuoterWorkingStateWorker.cpp @@ -73,19 +73,31 @@ void QuoterWorkingStateWorker::_longpath_analyze_and_act () } else{ // to adjust for what has already been filled - Quantity order_quantity = Quantity (computed_quantity.value() + _quoter->_price_quantity_state.aggregated_filled_quantity().value()); - if (order_quantity.value() != _quoter->_price_quantity_state.out_quantity().value()) + Quantity order_quantity = Quantity ( + computed_quantity.value() + + _quoter->_price_quantity_state.aggregated_filled_quantity().value() + ); + if (order_quantity != _quoter->_price_quantity_state.out_quantity()) // this is a size change, size changes always go through regardless of the // quoting parameters _modify_order (computed_price, order_quantity); else{ - bool reprice = true; - if (_quoter->_this_leg_data.leg_params().quote_params().has_quote_mute_zone()) - reprice = SpreaderUtils::reprice_quote_mute_zone(_quoter->_price_quantity_state.out_price().value(), computed_price.value(), _quoter->_this_leg_data.trading_side(), - _quoter->_this_leg_data.tick_size(), _quoter->_this_leg_data.leg_params().quote_params().quote_mute_zone()); - reprice=reprice && !(_quoter->_spreader.in_cache_warming_cycle()); - if (reprice) - _modify_order (computed_price, order_quantity); + Price curr_price = _quoter->_price_quantity_state.out_price(); + if(!bts::securities::is_same(curr_price,computed_price)){ + const Book& book = + _quoter->_spreader.get_book(_quoter->_this_leg_data.leg_index()); + bool throttle_reject = SpreaderUtils::is_throttle_reject( + curr_price.value(), + computed_price.value(), + book, + _quoter->_this_leg_data.trading_side(), + _quoter->_this_leg_data.tick_size(), + _quoter->_this_leg_data.leg_params().quote_params()); + bool reprice = !throttle_reject; + reprice = reprice && !(_quoter->_spreader.in_cache_warming_cycle()); + if (reprice) + _modify_order (computed_price, order_quantity); + } } } } diff --git a/src/lib/sparkproto/SparkProtos.proto b/src/lib/sparkproto/SparkProtos.proto index d0f4c7675..e1b14e4fa 100644 --- a/src/lib/sparkproto/SparkProtos.proto +++ b/src/lib/sparkproto/SparkProtos.proto @@ -68,6 +68,7 @@ message QuoteParams QuoteMaxOrderMove quote_max_order_move = 1040; QuoteHidden quote_hidden = 1050; ConditionalQuoting conditional_quoting=1060; + QuoteInsideMarketDistanceThrottle quote_inside_market_distance_throttle = 1070; // default value 0, 1 means we will have one trailing // order behind the top level // (once we have ChildOrder's here, we can reture this @@ -129,6 +130,11 @@ message ConditionalQuoting{ PriceType price_type=10; } +message QuoteInsideMarketDistanceThrottle +{ + uint32 on_toward_distance = 10; +} + /*************************************Quote RepriceThrottled (unused)******************************* (Stellar's sensitivity) This parameter defines regions (wrt their distance from the inside market) @@ -174,7 +180,8 @@ THEN message QuoteInsideMarketDistance { RulePriority priority = 1; - uint32 ticks_from_inside = 10; + uint32 on_toward_distance = 10; + uint32 on_away_distance = 20; } /******************************Quote InsideMarketDistanceWithTravel****************************** diff --git a/testing/manual/admin/user_account_deletion.txt b/testing/manual/admin/user_account_deletion.txt new file mode 100644 index 000000000..21aa67b82 --- /dev/null +++ b/testing/manual/admin/user_account_deletion.txt @@ -0,0 +1,13 @@ +This test verifies that users can only see accounts that are not marked as deleted + +1. Start a client and the admin gui, choose a user other than bts + +2. In the admin gui, create an account whose name is Prada + +3. For the designated user, add permission to see the Prada account + +4. Verify the you can see the account in the client + +5. In the admin gui, delete the account + +6. Verify the gui no longer shows the Prada (or DELETED_Prada, etc) account diff --git a/testing/manual/forms/fills.txt b/testing/manual/forms/fills.txt index ce130ffa7..9ecc6ab14 100644 --- a/testing/manual/forms/fills.txt +++ b/testing/manual/forms/fills.txt @@ -8,3 +8,7 @@ Make sure the following columns have filters when the window starts: Cross an order, get a fill and make sure it shows up Test sorting and filtering + +Root algo: +Enter an iceberg order and force fills. Make sure the Root Algo column shows the Iceberg as the root algo. +Now enter a speader order and force fills. Make sure the Root Algo column shows the name of the spreader. diff --git a/testing/manual/forms2/manual_fills.txt b/testing/manual/forms2/manual_fills.txt new file mode 100644 index 000000000..8c831096d --- /dev/null +++ b/testing/manual/forms2/manual_fills.txt @@ -0,0 +1,16 @@ +Manual Fills Test* + +Manual fills should now show Admin fills +- Open the Trading -> Manual fills form + - Verify the form is completely empty as there should be no manual fills yet + +- In the Admin UI, click on Accounts -> Position Management + - Add a fill for the bts user with a qty of 100 + - Click Save + +- Back in the Manual fills form, verify the form is still empty +- Open up Trading -> PnL + - Verify the PnL shows a row for the trade you entered + + +* = We need to flesh out this test as it currently only tests 1 narrow piece of functionality \ No newline at end of file diff --git a/testing/manual/orders/order_book.txt b/testing/manual/orders/order_book.txt index c1e7ec741..edf2a0ce3 100644 --- a/testing/manual/orders/order_book.txt +++ b/testing/manual/orders/order_book.txt @@ -64,6 +64,12 @@ Filter/Collapse interaction - Now filter for order type = limit, you should only see the hedges and the currently working limit - Now filter for order type = IB and you should see nothing +Parent/Child +------------ +- Enter an algo fo your choice. Verify that the parent child algos show correctly. +- Enter a spreader. The spreader algo should show the name of the spreader as well. Verify +that the filter works for this (the filter only shows the spreader badge). + diff --git a/testing/manual/settings/SoundAndNotificationsTest.txt b/testing/manual/settings/SoundAndNotificationsTest.txt index 5690657f3..d3b6d1377 100644 --- a/testing/manual/settings/SoundAndNotificationsTest.txt +++ b/testing/manual/settings/SoundAndNotificationsTest.txt @@ -82,8 +82,15 @@ Prepare: open a ladder for a security that has steady market data activity (in t - enter a limit order ACROSS the market to trigger an immediate fill. - this time, the "When order is filled" sound should play; the "When order is canceled" sound should not be heard. +7) "Any Order" sent sounds: + Description: + You will be verifying that the order sent sound trigger works + + - in the settings dialog, change "When order is filled" to "When order is sent", then click apply + - in the ladder, enter a limit order away from the market, so it is NOT liable to get filled. + - you should hear the sound you selected for "When order is sent" -7) Saved with workspace: +8) Saved with workspace: ----Note---------------------------------------------------------------------------------------------------------------------- - you have completed the sound-functionality testing, don't be alarmed by the 4 sound triggers you are about to add. - this step just requires comparing 2 images of the settings dialog to confirm that they were retained with the workspace. @@ -99,7 +106,7 @@ Prepare: open a ladder for a security that has steady market data activity (in t - close the shell, then restart it with the "Where I left off on" workspace. - open the OWSD to verify that the sound triggers were saved with the workspace. -8) Test shell does not crash when no sound card present +9) Test shell does not crash when no sound card present - use a machine that does not have a sound card, such as eh-2 (check with Eric first) - update config to turn off sounds diff --git a/testing/manual/settings/UserSettingsTest.txt b/testing/manual/settings/UserSettingsTest.txt index 5201d95b6..0586fac73 100644 --- a/testing/manual/settings/UserSettingsTest.txt +++ b/testing/manual/settings/UserSettingsTest.txt @@ -86,6 +86,16 @@ NOTES: 2005) Open a new ladder for any symbol and verify you can cross your own orders without being pestered by a confirmation dialog +------------------------------------------------------------------------------- +Left Panel Scroll test +------------------------------------------------------------------------------- +The scroll position of the left-panel area is now remembered as part of the ladder settings + +Resize your ladder window to make it vertically small so that the left panel displays a scrollviewer. +Scroll the left panel down so that the qty box is the top-most visible control in the panel +Exit and relaunch Spark, loading your last saved workspace +Verify that the restored ladder window's left panel has been vertically scrolled so the the qty box is one again the top-most visble control + DONE!!! diff --git a/testing/manual/spreader_misc/algo_of_spreader.txt b/testing/manual/spreader_misc/algo_of_spreader.txt new file mode 100644 index 000000000..7dd7d5fba --- /dev/null +++ b/testing/manual/spreader_misc/algo_of_spreader.txt @@ -0,0 +1,12 @@ +This test makes sure the basic spreader works as child orders of different algos + +Iceberg +------- + +0. Follow the instructions from docs/spreader_common_setup_2.txt + +1. In the spreader ladder enter a 5 lot sell IB with a show qty of 2 at -0.275. + +2. Verify that it completely fills. + +3. Verify that the Filled Qty and Avg Filled in the OB is correct \ No newline at end of file diff --git a/testing/manual/spreader_misc/fractional_hedging.txt b/testing/manual/spreader_misc/fractional_hedging.txt index fce9925bb..4d9b9fbfd 100644 --- a/testing/manual/spreader_misc/fractional_hedging.txt +++ b/testing/manual/spreader_misc/fractional_hedging.txt @@ -26,21 +26,22 @@ or more orders to get the unhedged delta < 1. Force quoting fills based on the left most column (by lifting the quoting offer) and verify that hedge orders of size "hedge_order_sent" (3rd column) are sent as a result. -The "unhedged_delta" column shows the unhedged delta immediately after the quoting fill +Compare the cumulative qty (cum) to the quote and hedge badges for easy visual inspection. + +(The "unhedged_delta" column shows the unhedged delta immediately after the quoting fill and the "remaining_unhedged_delta" column is the unhedged delta after the hedge order -has been sent. -You can check the hedge orders being sent easily by looking at the order reduction -happening on the order sent in step 2 (or look at the hedges in the orderbook). +has been sent) + ------------------------------------------------------------------------------ -quoting fill unhedged_delta hedge_order_sent remaining_unhedged_delta +quoting fill(cum) unhedged_delta hedge_order_sent (cum) remaining_unhedged_delta ------------------------------------------------------------------------------ -1 2/3 0 2/3 -1 4/3 1 1/3 -1 1 1 0 -4 8/3 2 2/3 -5 4 4 0 -2 4/3 1 1/3 -1 1 1 0 +1(1/15) 2/3 0(0/10) 2/3 +1(2/15) 4/3 1(1/10) 1/3 +1(3/15) 1 1(2/10) 0 +4(7/17) 8/3 2(4/10) 2/3 +5(12/15) 4 4(8/10) 0 +2(14/15) 4/3 1(9/10) 1/3 +1(15/15) 1 1(10/10) 0 6. At the end of this, the whole order should be filled. Check the order book to make sure the fill price is -9.900, there are 10 total fills in SIF1 and diff --git a/testing/manual/spreader_misc/inside_market_distance.txt b/testing/manual/spreader_misc/inside_market_distance.txt new file mode 100644 index 000000000..885365413 --- /dev/null +++ b/testing/manual/spreader_misc/inside_market_distance.txt @@ -0,0 +1,12 @@ +This test makes sure the basic spreader functionality works for 2 legged synthetic spreads with one quoting leg + +Iceberg +------- + +0. Follow the instructions from docs/spreader_common_setup_2.txt + +1. In the spreader ladder enter a 5 lot sell IB with a show qty of 2 at -0.275. + +2. Verify that it completely fills. + +3. Verify that the Filled Qty and Avg Filled in the OB is correct \ No newline at end of file diff --git a/tools/cpp_helper/ics_spreads.csv b/tools/cpp_helper/ics_spreads.csv index 266475fd4..26265d4fb 100644 --- a/tools/cpp_helper/ics_spreads.csv +++ b/tools/cpp_helper/ics_spreads.csv @@ -29,5 +29,3 @@ Sym,Mult,Exch "BUB",1000,CBT "FNU",1000,CBT "SOM",500,CBT -"OJ",150,IFU -"KC",375,IFU