From 74aca81322bb48326a85a9c8bc14711afcdfdb22 Mon Sep 17 00:00:00 2001 From: Michael Harding Date: Thu, 22 Mar 2018 16:02:54 -0400 Subject: [PATCH 01/13] Update Ladder test --- testing/manual/misc/ladder.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/testing/manual/misc/ladder.txt b/testing/manual/misc/ladder.txt index ff94b7bb7..abc4164ee 100644 --- a/testing/manual/misc/ladder.txt +++ b/testing/manual/misc/ladder.txt @@ -17,6 +17,7 @@ Check that what you mouse into or type into the keypad is reflected in the order Cancels: Work some orders, cancel them individually, and via Cancel Bids, Cancel Asks, Cancel all Order Types +**Market, Stop, and Stop Limit orders require Cert** Test a market order, do a buy and a sell and make sure they fill at market price and qty Test Stop and Stop limit orders. Put a Stop Buy above the market and a Stop Sell below @@ -25,6 +26,4 @@ Select ICEBerg and then specify limit as subtype via the left arrow. Set show q Now select a size greater than 1 in the main ladder, place buys and sells in the ladder.' Test TimeBox -Ask Taha? - - +Enter any time in the future and a reasonable end time. Enter two orders. Cross one of the orders during the specified time window with a limit order and verify it was filled correctly. Verify the other order cancels after the end time. From 2fb0e9c478bd9aaac63cee23e725e664b9875c73 Mon Sep 17 00:00:00 2001 From: Michael Harding Date: Thu, 22 Mar 2018 17:16:30 -0400 Subject: [PATCH 02/13] SPARK-943: Add Clone Synthetic Icon --- src/client/spark/Images/Icons.cs | 1 + src/client/spark/Images/Vector/Icons.xaml | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/client/spark/Images/Icons.cs b/src/client/spark/Images/Icons.cs index c1ccd0ce7..1e394d2bf 100644 --- a/src/client/spark/Images/Icons.cs +++ b/src/client/spark/Images/Icons.cs @@ -92,6 +92,7 @@ namespace mbts.ui public static ImageSource AddSynthetic { get { return (DrawingImage)_resources["AddSynthetic"]; } } public static ImageSource RemoveSynthetic { get { return (DrawingImage)_resources["RemoveSynthetic"]; } } public static ImageSource ModifySynthetic { get { return (DrawingImage)_resources["ModifySynthetic"]; } } + public static ImageSource CloneSynthetic { get { return (DrawingImage)_resources["CloneSynthetic"]; } } public static ImageSource ModifyOrder { get { return (DrawingImage)_resources["ModifyOrder"]; } } public static ImageSource Clock { get { return (DrawingImage)_resources["Clock"]; } } diff --git a/src/client/spark/Images/Vector/Icons.xaml b/src/client/spark/Images/Vector/Icons.xaml index 3bb5591cf..f51f84272 100644 --- a/src/client/spark/Images/Vector/Icons.xaml +++ b/src/client/spark/Images/Vector/Icons.xaml @@ -718,6 +718,17 @@ M0,0L63.999001,0 63.999001,48.792999 0,48.792999z"> + + + + + + + + + - + From bbdccf62b1e588306e3085a0acb90f1a3630f39e Mon Sep 17 00:00:00 2001 From: John Colvin Date: Thu, 22 Mar 2018 18:29:40 -0400 Subject: [PATCH 04/13] SPARK-909 Time and sales does not sort by anything --- .../Market/MarketView/MarketViewRow.cs | 12 +- .../Market/TimeAndSales/TimeAndSalesModel.cs | 76 +++++++++--- .../Market/TimeAndSales/TimeAndSalesVM.cs | 6 +- .../VM/SyntheticManagementDialogVM.cs | 12 +- .../GenericCollectionExtensions.cs | 108 +++++++++++++++--- .../spark/view/Spark/Grid/ISecurityRow.cs | 16 +-- 6 files changed, 182 insertions(+), 48 deletions(-) diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs b/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs index e5583491c..8ed233925 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewRow.cs @@ -15,7 +15,7 @@ using System.Windows.Input; namespace mbts.spark { partial class MarketViewVM { - public class Row : SecurityMDRow, IDisposable { + public class Row : SecurityMDRow, IDisposable, IEquatable { readonly IBus _bus; readonly OrdersModel _orders_model; readonly AnimationManager _animation = new AnimationManager(); @@ -116,6 +116,16 @@ namespace mbts.spark { _day_change.set(last_price - session_high); } + public bool Equals(Row other) => + other != null && + other.security_key == security_key; + + public override bool Equals(object obj) => + Equals(obj as Row); + + public override int GetHashCode() => + security_key.GetHashCode(); + #region Show Windows void _show_ladder() => _bus.post(SparkTags.ShowLadderTag, md); diff --git a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesModel.cs b/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesModel.cs index a3c54339a..c827507e3 100644 --- a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesModel.cs +++ b/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesModel.cs @@ -21,12 +21,12 @@ namespace mbts.spark { class TimeAndSalesModel { static readonly TimeSpan _poll_interval = TimeSpan.FromSeconds(0.4); - public TimeAndSalesModel(IBus bus, MDConsumer consumer, SecurityCriteria security_criteria) => + public TimeAndSalesModel(IBus bus, MDConsumer consumer, SecurityCriteria security_criteria) { trades = security_criteria.subscribe_md_map(bus) - .Scan(new Dictionary(), + .Scan(new Dictionary(), (cache, md_map) => { - var copy = new Dictionary(cache); - copy.sync_with(md_map, (id, smd) => new SecurityTradeConsumer(smd.security, consumer.get_channel(smd.security.Symbol, smd.security.security_type(), smd.security.Exchange))); + var copy = new Dictionary(cache); + copy.sync_with_demux(md_map, get_channel_key, get_channel_consumer, update_channel_consumer); return copy; } ).Select(cache => @@ -34,20 +34,66 @@ namespace mbts.spark { .Select(_ => new List(cache.Values.SelectMany(c => c.read_trades()))) ).SelectMany(_ => _); - public IObservable> trades { get; } + ChannelKey get_channel_key(KeyValuePair md_kv) => + new ChannelKey(md_kv.Value.security.Symbol, md_kv.Value.security.security_type(), md_kv.Value.security.Exchange); - private class SecurityTradeConsumer { - readonly SecurityImmutable _security; - readonly MDConsumerChannel _channel; - long _cursor = 0; - - public SecurityTradeConsumer(SecurityImmutable security, MDConsumerChannel channel) { - _security = security; - _channel = channel; + ChannelConsumer get_channel_consumer(IGrouping> channel_sec_group) { + var key = channel_sec_group.Key; + var rv = new ChannelConsumer(consumer.get_channel(key.symbol, key.type, key.exchange)); + rv.set_securities(channel_sec_group); + return rv; } - public IEnumerable read_trades() => - _channel.read_trades(ref _cursor).Select(tm => new TradeInfo(_security, tm)); + void update_channel_consumer(KeyValuePair channel_kv, IEnumerable> security_kvs) => + channel_kv.Value.set_securities(security_kvs); + } + + public IObservable> trades { get; } + + private class ChannelKey : IEquatable { + public readonly string symbol; + public readonly SecurityType type; + public readonly Venue exchange; + + public ChannelKey(string symbol, SecurityType type, Venue exchange) { + this.symbol = symbol; + this.type = type; + this.exchange = exchange; + } + + public bool Equals(ChannelKey other) => + other != null && + other.symbol == symbol && + other.type == type && + other.exchange == exchange; + + public override bool Equals(object obj) => + Equals(obj as ChannelKey); + + public override int GetHashCode() => + symbol.GetHashCode() ^ + type.GetHashCode() ^ + exchange.GetHashCode(); + } + + private class ChannelConsumer { + readonly MDConsumerChannel _channel; + Dictionary _securities; + long _cursor = 0; + + public ChannelConsumer(MDConsumerChannel channel) => + _channel = channel; + + public void set_securities(IEnumerable> securities) => + _securities = securities.ToDictionary(kv => kv.Key, kv => kv.Value.security); + + public IEnumerable read_trades() { + var copy = new Dictionary(_securities); + foreach (var tm in _channel.read_trades(ref _cursor)) { + if (copy.TryGetValue(tm.Key, out SecurityImmutable sec)) + yield return new TradeInfo(sec, tm); + } + } } } } \ No newline at end of file diff --git a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesVM.cs b/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesVM.cs index 6a746b379..3467e69f6 100644 --- a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesVM.cs +++ b/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesVM.cs @@ -67,7 +67,7 @@ namespace mbts.spark { if (smd_lookup.success) _bus.post(SparkTags.ShowLadderTag, smd_lookup.result); } - public class Row : SecurityRow, IEquatable { + public class Row : SecurityRow { readonly uint _trade_key; public Row(TimeAndSalesVM parent, SecurityImmutable security, TradeMessageImmutable trade) : base(security) { @@ -83,10 +83,6 @@ namespace mbts.spark { public double price { get; } public uint size { get; } public ICommand show_ladder { get; } - - public bool Equals(Row other) => other != null && other._trade_key == _trade_key; - public override bool Equals(object obj) => Equals(obj as Row); - public override int GetHashCode() => _trade_key.GetHashCode(); } } } \ No newline at end of file diff --git a/src/client/spark/Modules/Spreader/VM/SyntheticManagementDialogVM.cs b/src/client/spark/Modules/Spreader/VM/SyntheticManagementDialogVM.cs index beaa6559d..5c2d6e372 100644 --- a/src/client/spark/Modules/Spreader/VM/SyntheticManagementDialogVM.cs +++ b/src/client/spark/Modules/Spreader/VM/SyntheticManagementDialogVM.cs @@ -53,7 +53,7 @@ namespace mbts.spark { }; #endregion - public class Row : SecurityMDRow { + public class Row : SecurityMDRow, IEquatable { readonly IBus _bus; readonly ExecutionStrategyImmutable? _strategy; readonly Property _n_working_orders; @@ -83,6 +83,16 @@ namespace mbts.spark { public ICommand show_ladder { get; } public ICommand show_order_book { get; } + public bool Equals(Row other) => + other != null && + other.security_key == security_key; + + public override bool Equals(object obj) => + Equals(obj as Row); + + public override int GetHashCode() => + security_key.GetHashCode(); + void _show_ladder() => _bus.post(SparkTags.ShowLadderTag, md); diff --git a/src/client/spark/core/GlobalExtensions/GenericCollectionExtensions.cs b/src/client/spark/core/GlobalExtensions/GenericCollectionExtensions.cs index a86250ed0..2ec9c95f6 100644 --- a/src/client/spark/core/GlobalExtensions/GenericCollectionExtensions.cs +++ b/src/client/spark/core/GlobalExtensions/GenericCollectionExtensions.cs @@ -606,17 +606,58 @@ namespace mbts.collections.extensions { else dictionary.Add(key, create_new()); } - // this overload prevents 'ambiguous calls' compilation errors due to Dictionary implementing IDictionary, and IReadOnlyDictionary. - public static void sync_with(this IDictionary dictionary, Dictionary source, Func selector) => - _sync_with(dictionary, source, selector); + public static void sync_with( + this IDictionary dictionary, + Dictionary source, + Func selector + ) => _sync_with(dictionary, source, selector); - public static void sync_with(this IDictionary dictionary, IDictionary source, Func selector) => - _sync_with(dictionary, source, selector); + public static void sync_with( + this IDictionary dictionary, + IDictionary source, + Func selector + ) => _sync_with(dictionary, source, selector); - public static void sync_with(this IDictionary dictionary, IReadOnlyDictionary source, Func selector) => - _sync_with_ro(dictionary, source, selector); + public static void sync_with( + this IDictionary dictionary, + IReadOnlyDictionary source, + Func selector + ) => _sync_with_ro(dictionary, source, selector); - static void _sync_with(this IDictionary dictionary, IDictionary source, Func selector) { + public static void sync_with_demux( + this IDictionary dictionary, + Dictionary source, + Func, TKey> key_selector, + Func>, TValue> value_selector, + Action, IEnumerable>> update + ) => _sync_with_demux(dictionary, source, key_selector, value_selector, update); + + public static void sync_with_demux( + this IDictionary dictionary, + IDictionary source, + Func, TKey> key_selector, + Func>, TValue> value_selector, + Action, IEnumerable>> update + ) => _sync_with_demux(dictionary, source, key_selector, value_selector, update); + + public static void sync_with_demux( + this IDictionary dictionary, + IReadOnlyDictionary source, + Func, TKey> key_selector, + Func>, TValue> value_selector, + Action, IEnumerable>> update + ) => _sync_with_demux_ro(dictionary, source, key_selector, value_selector, update); + + static void _sync_with(IDictionary dictionary, IDictionary source, Func selector) { + var removes = dictionary.Keys.Except(source.Keys).ToList(); + foreach (var k in removes) + dictionary.Remove(k); + var adds = source.Except(dictionary.Keys, kv => kv.Key).ToList(); + foreach (var kv in adds) + dictionary.Add(kv.Key, selector(kv.Key, kv.Value)); + } + + static void _sync_with_ro(IDictionary dictionary, IReadOnlyDictionary source, Func selector) { var removes = dictionary.Keys.Except(source.Keys).ToList(); foreach (var k in removes) dictionary.Remove(k); @@ -625,13 +666,54 @@ namespace mbts.collections.extensions { dictionary.Add(kv.Key, selector(kv.Key, kv.Value)); } - static void _sync_with_ro(this IDictionary dictionary, IReadOnlyDictionary source, Func selector) { - var removes = dictionary.Keys.Except(source.Keys).ToList(); + static void _sync_with_demux( + IDictionary dictionary, + IDictionary source, + Func, TKey> key_selector, + Func>, TValue> value_selector, + Action, IEnumerable>> update + ) { + var source_lookup = source.ToLookup(key_selector); + HashSet changes = new HashSet(), removes = new HashSet(); + foreach (var kv in dictionary) { + if (source_lookup.TryGetValue(kv.Key, out IEnumerable> result)) { + update(kv, result); + changes.Add(kv.Key); + } else { + removes.Add(kv.Key); + } + } foreach (var k in removes) dictionary.Remove(k); - var adds = source.Except(dictionary.Keys, kv => kv.Key).ToList(); - foreach (var kv in adds) - dictionary.Add(kv.Key, selector(kv.Key, kv.Value)); + foreach (var g in source_lookup) { + if (!changes.Contains(g.Key)) + dictionary.Add(g.Key, value_selector(g)); + } + } + + static void _sync_with_demux_ro( + IDictionary dictionary, + IReadOnlyDictionary source, + Func, TKey> key_selector, + Func>, TValue> value_selector, + Action, IEnumerable>> update + ) { + var source_lookup = source.ToLookup(key_selector); + HashSet changes = new HashSet(), removes = new HashSet(); + foreach (var kv in dictionary) { + if (source_lookup.TryGetValue(kv.Key, out IEnumerable> result)) { + update(kv, result); + changes.Add(kv.Key); + } else { + removes.Add(kv.Key); + } + } + foreach (var k in removes) + dictionary.Remove(k); + foreach (var g in source_lookup) { + if (!changes.Contains(g.Key)) + dictionary.Add(g.Key, value_selector(g)); + } } } } \ No newline at end of file diff --git a/src/client/spark/view/Spark/Grid/ISecurityRow.cs b/src/client/spark/view/Spark/Grid/ISecurityRow.cs index 1e393a332..6ed0dacd7 100644 --- a/src/client/spark/view/Spark/Grid/ISecurityRow.cs +++ b/src/client/spark/view/Spark/Grid/ISecurityRow.cs @@ -1,24 +1,14 @@ using bts.api; using mbts.ui.shell; -using System; -namespace mbts.spark -{ - interface ISecurityRow - { +namespace mbts.spark { + interface ISecurityRow { SecurityImmutable security { get; } } - abstract class SecurityRow : DisposableViewModelBase, ISecurityRow, IEquatable, IEquatable - { + abstract class SecurityRow : DisposableViewModelBase, ISecurityRow { protected SecurityRow(SecurityImmutable security) => this.security = security; public SecurityImmutable security { get; } public uint security_key => security.Id; - - bool _equals(ISecurityRow other) => other != null && other.security.Id == security.Id; - public bool Equals(SecurityRow other) => _equals(other); - bool IEquatable.Equals(ISecurityRow other) => _equals(other); - public override bool Equals(object obj) => _equals(obj as ISecurityRow); - public override int GetHashCode() => security.Id.GetHashCode(); } } \ No newline at end of file From d5a3e5c5f15abc270e70e7d61a4a2f531099d57c Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Thu, 22 Mar 2018 18:20:46 -0500 Subject: [PATCH 05/13] PnL - have to hide NaN now that the Tickconverter is no lnoger used --- src/client/spark/view/Spark/PAndL/PAndLView.xaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/client/spark/view/Spark/PAndL/PAndLView.xaml b/src/client/spark/view/Spark/PAndL/PAndLView.xaml index 4318e22ef..9d8c765ae 100644 --- a/src/client/spark/view/Spark/PAndL/PAndLView.xaml +++ b/src/client/spark/view/Spark/PAndL/PAndLView.xaml @@ -18,6 +18,7 @@ + @@ -109,7 +110,7 @@ - --> - Date: Thu, 22 Mar 2018 20:13:02 -0400 Subject: [PATCH 06/13] SPARK-929 Need better defaults on synth creation --- .../Modules/Spreader/SyntheticDataHelper.cs | 16 ++++++------- ...ostHedgePriceBasedCrossMarketTicksModel.cs | 22 ++++++++++------- .../PostHedgePriceBasedCrossTicksModel.cs | 22 ++++++++++------- ...PostHedgeTimeBasedCrossMarketTicksModel.cs | 22 ++++++++++------- .../PostHedgeTimeBasedCrossTimeModel.cs | 22 ++++++++++------- .../PreHedge/PreHedgePaylessThresholdModel.cs | 21 +++++++++------- .../PreHedge/PreHedgePaylessTicksModel.cs | 22 ++++++++++------- .../PreHedge/PreHedgePayupThresholdModel.cs | 21 +++++++++------- .../PreHedge/PreHedgePayupTicksModel.cs | 22 ++++++++++------- .../Quote/QuoteInsideMarketThrottleMinMove.cs | 22 ++++++++++------- .../QuoteInsideMarketThrottleTicksModel.cs | 21 +++++++++------- .../Quote/QuoteThrottleInsideTicksModel.cs | 24 ++++++++++++------- .../Quote/QuoteThrottleOutsideTicksModel.cs | 24 ++++++++++++------- .../Spreader/VM/ParameterRows/RowModel.cs | 3 ++- 14 files changed, 177 insertions(+), 107 deletions(-) diff --git a/src/client/spark/Modules/Spreader/SyntheticDataHelper.cs b/src/client/spark/Modules/Spreader/SyntheticDataHelper.cs index c49565b67..9ecaa2d06 100644 --- a/src/client/spark/Modules/Spreader/SyntheticDataHelper.cs +++ b/src/client/spark/Modules/Spreader/SyntheticDataHelper.cs @@ -99,8 +99,8 @@ namespace bts.shell { } } public static QuoteMuteZone QuoteMuteZone => new QuoteMuteZone { - InsideTicks = 1, - OutsideTicks = 1, + InsideTicks = 2, + OutsideTicks = 3, Priority = RulePriority }; public static QuoteInsideMarketDistanceWithTravel QuoteInsideMarketDistanceWithTravel => new QuoteInsideMarketDistanceWithTravel { Priority = RulePriority }; @@ -110,8 +110,8 @@ namespace bts.shell { #region PreHedge public static PreHedgeParams PreHedgeParams => new PreHedgeParams { MaxPriceFromInsideMarket = PreHedgeMaxPriceFromInsideMarket, - QuantityBasedPaylessTicks = PreHedgeQuantityBasedPayLessTicks, - QuantityBasedPayupTicks = PreHedgeQuantityBasedPayUpTicks, + QuantityBasedPaylessTicks = null, + QuantityBasedPayupTicks = null, SendHedgeAsMarketOrder = PreHedgeSendHedgeAsMarketOrder }; public static PreHedgeSendHedgeAsMarketOrder PreHedgeSendHedgeAsMarketOrder => new PreHedgeSendHedgeAsMarketOrder(); @@ -122,8 +122,8 @@ namespace bts.shell { #region PostHedge public static PostHedgeParams PostHedgeParams => new PostHedgeParams { - PriceBasedCross = PostHedgePriceBasedForcedCross, - TimeBasedForcedCross = PostHedgeTimeBasedForcedCross, + PriceBasedCross = null, + TimeBasedForcedCross = null, }; public static PostHedgePriceBasedForcedCross PostHedgePriceBasedForcedCross => new PostHedgePriceBasedForcedCross(); public static PostHedgeTimeBasedForcedCross PostHedgeTimeBasedForcedCross => new PostHedgeTimeBasedForcedCross(); @@ -140,8 +140,8 @@ namespace bts.shell { public static ExecutionStrategy ExecutionStrategy(SecurityImmutable security) { switch (security.ContractCase) { - case bts.api.Security.ContractOneofCase.Spread: return ExecutionStrategy(security.Spread.Legs.Select(l => l.Security)); - case bts.api.Security.ContractOneofCase.Synthetic: return ExecutionStrategy(security.Synthetic.Legs.Select(l => l.Security)); + case Security.ContractOneofCase.Spread: return ExecutionStrategy(security.Spread.Legs.Select(l => l.Security)); + case Security.ContractOneofCase.Synthetic: return ExecutionStrategy(security.Synthetic.Legs.Select(l => l.Security)); default: throw new ArgumentException("Must be a Spread, or Synthetic", nameof(security)); } } diff --git a/src/client/spark/Modules/Spreader/VM/ParameterRows/PostHedge/PostHedgePriceBasedCrossMarketTicksModel.cs b/src/client/spark/Modules/Spreader/VM/ParameterRows/PostHedge/PostHedgePriceBasedCrossMarketTicksModel.cs index 30921c187..549c6f395 100644 --- a/src/client/spark/Modules/Spreader/VM/ParameterRows/PostHedge/PostHedgePriceBasedCrossMarketTicksModel.cs +++ b/src/client/spark/Modules/Spreader/VM/ParameterRows/PostHedge/PostHedgePriceBasedCrossMarketTicksModel.cs @@ -1,4 +1,5 @@ using bts.shell; +using bts.spark; using mbts.collections.extensions; using mbts.ui.spark; using System.Collections.Generic; @@ -12,22 +13,27 @@ namespace mbts.spark { public override ParameterSection[] section_path { get; } = new[] { Sections.PostHedge, Subsections.TicksAwayCross }; public void apply_value(LegSpreaderParamsTuple leg_tup) => - leg_tup.leg_params.PostHedgeParams.PriceBasedCross.MarketCrossTicks = _value_from_store(leg_tup); + _get_price_based_cross(leg_tup).MarketCrossTicks = _value_from_store(leg_tup); - public override uint get_value(LegSpreaderParamsTuple leg_tup) { - var price_based_cross = leg_tup.leg_params.PostHedgeParams.PriceBasedCross; - return price_based_cross != null ? price_based_cross.MarketCrossTicks : _value_from_store(leg_tup); - } + public override uint get_value(LegSpreaderParamsTuple leg_tup) => + _get_price_based_cross(leg_tup) is PostHedgePriceBasedForcedCross price_based_cross ? + price_based_cross.MarketCrossTicks : + _value_from_store(leg_tup); public override void set_value(LegSpreaderParamsTuple leg_tup, uint value) { _value_store[leg_tup.SecurityKey] = value; - var price_based_cross = leg_tup.leg_params.PostHedgeParams.PriceBasedCross; - if (price_based_cross != null) + if (_get_price_based_cross(leg_tup) is PostHedgePriceBasedForcedCross price_based_cross) price_based_cross.MarketCrossTicks = value; } + protected override bool _get_enabled(LegSpreaderParamsTuple leg_tup) => + _get_price_based_cross(leg_tup) != null; + + PostHedgePriceBasedForcedCross _get_price_based_cross(LegSpreaderParamsTuple leg_tup) => + leg_tup.leg_params.PostHedgeParams.PriceBasedCross; + uint _value_from_store(LegSpreaderParamsTuple leg_tup) => - _value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.PostHedgeParams.PriceBasedCross.MarketCrossTicks); + _value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.PostHedgePriceBasedForcedCross.MarketCrossTicks); } } } \ No newline at end of file diff --git a/src/client/spark/Modules/Spreader/VM/ParameterRows/PostHedge/PostHedgePriceBasedCrossTicksModel.cs b/src/client/spark/Modules/Spreader/VM/ParameterRows/PostHedge/PostHedgePriceBasedCrossTicksModel.cs index 853527a12..1d18c26c8 100644 --- a/src/client/spark/Modules/Spreader/VM/ParameterRows/PostHedge/PostHedgePriceBasedCrossTicksModel.cs +++ b/src/client/spark/Modules/Spreader/VM/ParameterRows/PostHedge/PostHedgePriceBasedCrossTicksModel.cs @@ -1,4 +1,5 @@ using bts.shell; +using bts.spark; using mbts.collections.extensions; using mbts.ui.spark; using System.Collections.Generic; @@ -12,22 +13,27 @@ namespace mbts.spark { public override ParameterSection[] section_path { get; } = new[] { Sections.PostHedge, Subsections.TicksAwayCross }; public void apply_value(LegSpreaderParamsTuple leg_tup) => - leg_tup.leg_params.PostHedgeParams.PriceBasedCross.TicksThreshold = _value_from_store(leg_tup); + _get_price_based_cross(leg_tup).TicksThreshold = _value_from_store(leg_tup); - public override uint get_value(LegSpreaderParamsTuple leg_tup) { - var price_based_cross = leg_tup.leg_params.PostHedgeParams.PriceBasedCross; - return price_based_cross != null ? price_based_cross.TicksThreshold : _value_from_store(leg_tup); - } + public override uint get_value(LegSpreaderParamsTuple leg_tup) => + _get_price_based_cross(leg_tup) is PostHedgePriceBasedForcedCross price_based_cross ? + price_based_cross.TicksThreshold : + _value_from_store(leg_tup); public override void set_value(LegSpreaderParamsTuple leg_tup, uint value) { _value_store[leg_tup.SecurityKey] = value; - var price_based_cross = leg_tup.leg_params.PostHedgeParams.PriceBasedCross; - if (price_based_cross != null) + if (_get_price_based_cross(leg_tup) is PostHedgePriceBasedForcedCross price_based_cross) price_based_cross.TicksThreshold = value; } + protected override bool _get_enabled(LegSpreaderParamsTuple leg_tup) => + _get_price_based_cross(leg_tup) != null; + + PostHedgePriceBasedForcedCross _get_price_based_cross(LegSpreaderParamsTuple leg_tup) => + leg_tup.leg_params.PostHedgeParams.PriceBasedCross; + uint _value_from_store(LegSpreaderParamsTuple leg_tup) => - _value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.PostHedgeParams.PriceBasedCross.TicksThreshold); + _value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.PostHedgePriceBasedForcedCross.TicksThreshold); } } } \ No newline at end of file diff --git a/src/client/spark/Modules/Spreader/VM/ParameterRows/PostHedge/PostHedgeTimeBasedCrossMarketTicksModel.cs b/src/client/spark/Modules/Spreader/VM/ParameterRows/PostHedge/PostHedgeTimeBasedCrossMarketTicksModel.cs index b58dcc7a8..0edfab885 100644 --- a/src/client/spark/Modules/Spreader/VM/ParameterRows/PostHedge/PostHedgeTimeBasedCrossMarketTicksModel.cs +++ b/src/client/spark/Modules/Spreader/VM/ParameterRows/PostHedge/PostHedgeTimeBasedCrossMarketTicksModel.cs @@ -1,4 +1,5 @@ using bts.shell; +using bts.spark; using mbts.collections.extensions; using mbts.ui.spark; using System.Collections.Generic; @@ -12,22 +13,27 @@ namespace mbts.spark { public override ParameterSection[] section_path { get; } = new[] { Sections.PostHedge, Subsections.TimeBasedCross }; public void apply_value(LegSpreaderParamsTuple leg_tup) => - leg_tup.leg_params.PostHedgeParams.TimeBasedForcedCross.MarketCrossTicks = _value_from_store(leg_tup); + _get_time_based_cross(leg_tup).MarketCrossTicks = _value_from_store(leg_tup); - public override uint get_value(LegSpreaderParamsTuple leg_tup) { - var time_based_cross = leg_tup.leg_params.PostHedgeParams.TimeBasedForcedCross; - return time_based_cross != null ? time_based_cross.MarketCrossTicks : _value_from_store(leg_tup); - } + public override uint get_value(LegSpreaderParamsTuple leg_tup) => + _get_time_based_cross(leg_tup) is PostHedgeTimeBasedForcedCross time_based_cross ? + time_based_cross.MarketCrossTicks : + _value_from_store(leg_tup); public override void set_value(LegSpreaderParamsTuple leg_tup, uint value) { _value_store[leg_tup.SecurityKey] = value; - var time_based_cross = leg_tup.leg_params.PostHedgeParams.TimeBasedForcedCross; - if (time_based_cross != null) + if (_get_time_based_cross(leg_tup) is PostHedgeTimeBasedForcedCross time_based_cross) time_based_cross.MarketCrossTicks = value; } + protected override bool _get_enabled(LegSpreaderParamsTuple leg_tup) => + _get_time_based_cross(leg_tup) != null; + + PostHedgeTimeBasedForcedCross _get_time_based_cross(LegSpreaderParamsTuple leg_tup) => + leg_tup.leg_params.PostHedgeParams.TimeBasedForcedCross; + uint _value_from_store(LegSpreaderParamsTuple leg_tup) => - _value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.PostHedgeParams.TimeBasedForcedCross.MarketCrossTicks); + _value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.PostHedgeTimeBasedForcedCross.MarketCrossTicks); } } } \ No newline at end of file diff --git a/src/client/spark/Modules/Spreader/VM/ParameterRows/PostHedge/PostHedgeTimeBasedCrossTimeModel.cs b/src/client/spark/Modules/Spreader/VM/ParameterRows/PostHedge/PostHedgeTimeBasedCrossTimeModel.cs index e80594e11..520996519 100644 --- a/src/client/spark/Modules/Spreader/VM/ParameterRows/PostHedge/PostHedgeTimeBasedCrossTimeModel.cs +++ b/src/client/spark/Modules/Spreader/VM/ParameterRows/PostHedge/PostHedgeTimeBasedCrossTimeModel.cs @@ -1,4 +1,5 @@ using bts.shell; +using bts.spark; using mbts.collections.extensions; using mbts.ui.spark; using System.Collections.Generic; @@ -12,22 +13,27 @@ namespace mbts.spark { public override ParameterSection[] section_path { get; } = new[] { Sections.PostHedge, Subsections.TimeBasedCross }; public void apply_value(LegSpreaderParamsTuple leg_tup) => - leg_tup.leg_params.PostHedgeParams.TimeBasedForcedCross.TimeInMsThreshold = _value_from_store(leg_tup); + _get_time_based_cross(leg_tup).TimeInMsThreshold = _value_from_store(leg_tup); - public override uint get_value(LegSpreaderParamsTuple leg_tup) { - var time_based_cross = leg_tup.leg_params.PostHedgeParams.TimeBasedForcedCross; - return time_based_cross != null ? time_based_cross.TimeInMsThreshold : _value_from_store(leg_tup); - } + public override uint get_value(LegSpreaderParamsTuple leg_tup) => + _get_time_based_cross(leg_tup) is PostHedgeTimeBasedForcedCross time_based_cross ? + time_based_cross.TimeInMsThreshold : + _value_from_store(leg_tup); public override void set_value(LegSpreaderParamsTuple leg_tup, uint value) { _value_store[leg_tup.SecurityKey] = value; - var time_based_cross = leg_tup.leg_params.PostHedgeParams.TimeBasedForcedCross; - if (time_based_cross != null) + if (_get_time_based_cross(leg_tup) is PostHedgeTimeBasedForcedCross time_based_cross) time_based_cross.TimeInMsThreshold = value; } + protected override bool _get_enabled(LegSpreaderParamsTuple leg_tup) => + _get_time_based_cross(leg_tup) != null; + + PostHedgeTimeBasedForcedCross _get_time_based_cross(LegSpreaderParamsTuple leg_tup) => + leg_tup.leg_params.PostHedgeParams.TimeBasedForcedCross; + uint _value_from_store(LegSpreaderParamsTuple leg_tup) => - _value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.PostHedgeParams.TimeBasedForcedCross.TimeInMsThreshold); + _value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.PostHedgeTimeBasedForcedCross.TimeInMsThreshold); } } } \ No newline at end of file diff --git a/src/client/spark/Modules/Spreader/VM/ParameterRows/PreHedge/PreHedgePaylessThresholdModel.cs b/src/client/spark/Modules/Spreader/VM/ParameterRows/PreHedge/PreHedgePaylessThresholdModel.cs index 65f6915c6..8fa5a2c46 100644 --- a/src/client/spark/Modules/Spreader/VM/ParameterRows/PreHedge/PreHedgePaylessThresholdModel.cs +++ b/src/client/spark/Modules/Spreader/VM/ParameterRows/PreHedge/PreHedgePaylessThresholdModel.cs @@ -13,24 +13,29 @@ namespace mbts.spark { public override ParameterSection[] section_path { get; } = new[] { Sections.PreHedge, Subsections.Payless }; public void apply_value(LegSpreaderParamsTuple leg_tup) => - leg_tup.leg_params.PreHedgeParams.QuantityBasedPaylessTicks.QuantityThreshold = _value_from_store(leg_tup); + _get_payless_ticks(leg_tup).QuantityThreshold = _value_from_store(leg_tup); - public override QuantityMeasure get_value(LegSpreaderParamsTuple leg_tup) { - var payless_ticks = leg_tup.leg_params.PreHedgeParams.QuantityBasedPaylessTicks; - return payless_ticks != null ? payless_ticks.QuantityThreshold : _value_from_store(leg_tup); - } + public override QuantityMeasure get_value(LegSpreaderParamsTuple leg_tup) => + _get_payless_ticks(leg_tup) is PreHedgeQuantityBasedPayLessTicks payless_ticks ? + payless_ticks.QuantityThreshold : + _value_from_store(leg_tup); public override void set_value(LegSpreaderParamsTuple leg_tup, QuantityMeasure value) { _value_store[leg_tup.SecurityKey] = value; - var payless_ticks = leg_tup.leg_params.PreHedgeParams.QuantityBasedPaylessTicks; - if (payless_ticks != null) + if (_get_payless_ticks(leg_tup) is PreHedgeQuantityBasedPayLessTicks payless_ticks) payless_ticks.QuantityThreshold = value; } public override ICell create_cell(LegSpreaderParamsTuple leg_tup) => new QuantityMeasureCell(this, leg_tup); + protected override bool _get_enabled(LegSpreaderParamsTuple leg_tup) => + _get_payless_ticks(leg_tup) != null; + + PreHedgeQuantityBasedPayLessTicks _get_payless_ticks(LegSpreaderParamsTuple leg_tup) => + leg_tup.leg_params.PreHedgeParams.QuantityBasedPaylessTicks; + QuantityMeasure _value_from_store(LegSpreaderParamsTuple leg_tup) => - _value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.PreHedgeParams.QuantityBasedPaylessTicks.QuantityThreshold); + _value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.PreHedgeQuantityBasedPayLessTicks.QuantityThreshold); } } } \ No newline at end of file diff --git a/src/client/spark/Modules/Spreader/VM/ParameterRows/PreHedge/PreHedgePaylessTicksModel.cs b/src/client/spark/Modules/Spreader/VM/ParameterRows/PreHedge/PreHedgePaylessTicksModel.cs index f2464246a..6d9df6dd7 100644 --- a/src/client/spark/Modules/Spreader/VM/ParameterRows/PreHedge/PreHedgePaylessTicksModel.cs +++ b/src/client/spark/Modules/Spreader/VM/ParameterRows/PreHedge/PreHedgePaylessTicksModel.cs @@ -1,4 +1,5 @@ using bts.shell; +using bts.spark; using mbts.collections.extensions; using mbts.ui.spark; using System.Collections.Generic; @@ -12,22 +13,27 @@ namespace mbts.spark { public override ParameterSection[] section_path { get; } = new[] { Sections.PreHedge, Subsections.Payless }; public void apply_value(LegSpreaderParamsTuple leg_tup) => - leg_tup.leg_params.PreHedgeParams.QuantityBasedPaylessTicks.PaylessTicks = _value_from_store(leg_tup); + _get_payless_ticks(leg_tup).PaylessTicks = _value_from_store(leg_tup); - public override uint get_value(LegSpreaderParamsTuple leg_tup) { - var payless_ticks = leg_tup.leg_params.PreHedgeParams.QuantityBasedPaylessTicks; - return payless_ticks != null ? payless_ticks.PaylessTicks : _value_from_store(leg_tup); - } + public override uint get_value(LegSpreaderParamsTuple leg_tup) => + _get_payless_ticks(leg_tup) is PreHedgeQuantityBasedPayLessTicks payless_ticks ? + payless_ticks.PaylessTicks : + _value_from_store(leg_tup); public override void set_value(LegSpreaderParamsTuple leg_tup, uint value) { _value_store[leg_tup.SecurityKey] = value; - var payless_ticks = leg_tup.leg_params.PreHedgeParams.QuantityBasedPaylessTicks; - if (payless_ticks != null) + if (_get_payless_ticks(leg_tup) is PreHedgeQuantityBasedPayLessTicks payless_ticks) payless_ticks.PaylessTicks = value; } + protected override bool _get_enabled(LegSpreaderParamsTuple leg_tup) => + _get_payless_ticks(leg_tup) != null; + + PreHedgeQuantityBasedPayLessTicks _get_payless_ticks(LegSpreaderParamsTuple leg_tup) => + leg_tup.leg_params.PreHedgeParams.QuantityBasedPaylessTicks; + uint _value_from_store(LegSpreaderParamsTuple leg_tup) => - _value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.PreHedgeParams.QuantityBasedPaylessTicks.PaylessTicks); + _value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.PreHedgeQuantityBasedPayLessTicks.PaylessTicks); } } } \ No newline at end of file diff --git a/src/client/spark/Modules/Spreader/VM/ParameterRows/PreHedge/PreHedgePayupThresholdModel.cs b/src/client/spark/Modules/Spreader/VM/ParameterRows/PreHedge/PreHedgePayupThresholdModel.cs index c71b5c247..b3baca8f2 100644 --- a/src/client/spark/Modules/Spreader/VM/ParameterRows/PreHedge/PreHedgePayupThresholdModel.cs +++ b/src/client/spark/Modules/Spreader/VM/ParameterRows/PreHedge/PreHedgePayupThresholdModel.cs @@ -13,24 +13,29 @@ namespace mbts.spark { public override ParameterSection[] section_path { get; } = new[] { Sections.PreHedge, Subsections.Payup }; public void apply_value(LegSpreaderParamsTuple leg_tup) => - leg_tup.leg_params.PreHedgeParams.QuantityBasedPayupTicks.QuantityThreshold = _value_from_store(leg_tup); + _get_payup_ticks(leg_tup).QuantityThreshold = _value_from_store(leg_tup); - public override QuantityMeasure get_value(LegSpreaderParamsTuple leg_tup) { - var payup_ticks = leg_tup.leg_params.PreHedgeParams.QuantityBasedPayupTicks; - return payup_ticks != null ? payup_ticks.QuantityThreshold : _value_from_store(leg_tup); - } + public override QuantityMeasure get_value(LegSpreaderParamsTuple leg_tup) => + _get_payup_ticks(leg_tup) is PreHedgeQuantityBasedPayupTicks payup_ticks ? + payup_ticks.QuantityThreshold : + _value_from_store(leg_tup); public override void set_value(LegSpreaderParamsTuple leg_tup, QuantityMeasure value) { _value_store[leg_tup.SecurityKey] = value; - var payup_ticks = leg_tup.leg_params.PreHedgeParams.QuantityBasedPayupTicks; - if (payup_ticks != null) + if (_get_payup_ticks(leg_tup) is PreHedgeQuantityBasedPayupTicks payup_ticks) payup_ticks.QuantityThreshold = value; } public override ICell create_cell(LegSpreaderParamsTuple leg_tup) => new QuantityMeasureCell(this, leg_tup); + protected override bool _get_enabled(LegSpreaderParamsTuple leg_tup) => + _get_payup_ticks(leg_tup) != null; + + PreHedgeQuantityBasedPayupTicks _get_payup_ticks(LegSpreaderParamsTuple leg_tup) => + leg_tup.leg_params.PreHedgeParams.QuantityBasedPayupTicks; + QuantityMeasure _value_from_store(LegSpreaderParamsTuple leg_tup) => - _value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.PreHedgeParams.QuantityBasedPayupTicks.QuantityThreshold); + _value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.PreHedgeQuantityBasedPayUpTicks.QuantityThreshold); } } } \ No newline at end of file diff --git a/src/client/spark/Modules/Spreader/VM/ParameterRows/PreHedge/PreHedgePayupTicksModel.cs b/src/client/spark/Modules/Spreader/VM/ParameterRows/PreHedge/PreHedgePayupTicksModel.cs index 406d2f897..0fd270d0f 100644 --- a/src/client/spark/Modules/Spreader/VM/ParameterRows/PreHedge/PreHedgePayupTicksModel.cs +++ b/src/client/spark/Modules/Spreader/VM/ParameterRows/PreHedge/PreHedgePayupTicksModel.cs @@ -1,4 +1,5 @@ using bts.shell; +using bts.spark; using mbts.collections.extensions; using mbts.ui.spark; using System.Collections.Generic; @@ -12,22 +13,27 @@ namespace mbts.spark { public override ParameterSection[] section_path { get; } = new[] { Sections.PreHedge, Subsections.Payup }; public void apply_value(LegSpreaderParamsTuple leg_tup) => - leg_tup.leg_params.PreHedgeParams.QuantityBasedPayupTicks.PayupTicks = _value_from_store(leg_tup); + _get_payup_ticks(leg_tup).PayupTicks = _value_from_store(leg_tup); - public override uint get_value(LegSpreaderParamsTuple leg_tup) { - var payup_ticks = leg_tup.leg_params.PreHedgeParams.QuantityBasedPayupTicks; - return payup_ticks != null ? payup_ticks.PayupTicks : _value_from_store(leg_tup); - } + public override uint get_value(LegSpreaderParamsTuple leg_tup) => + _get_payup_ticks(leg_tup) is PreHedgeQuantityBasedPayupTicks payup_ticks ? + payup_ticks.PayupTicks : + _value_from_store(leg_tup); public override void set_value(LegSpreaderParamsTuple leg_tup, uint value) { _value_store[leg_tup.SecurityKey] = value; - var payup_ticks = leg_tup.leg_params.PreHedgeParams.QuantityBasedPayupTicks; - if (payup_ticks != null) + if (_get_payup_ticks(leg_tup) is PreHedgeQuantityBasedPayupTicks payup_ticks) payup_ticks.PayupTicks = value; } + protected override bool _get_enabled(LegSpreaderParamsTuple leg_tup) => + _get_payup_ticks(leg_tup) != null; + + PreHedgeQuantityBasedPayupTicks _get_payup_ticks(LegSpreaderParamsTuple leg_tup) => + leg_tup.leg_params.PreHedgeParams.QuantityBasedPayupTicks; + uint _value_from_store(LegSpreaderParamsTuple leg_tup) => - _value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.PreHedgeParams.QuantityBasedPayupTicks.PayupTicks); + _value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.PreHedgeQuantityBasedPayUpTicks.PayupTicks); } } } \ No newline at end of file diff --git a/src/client/spark/Modules/Spreader/VM/ParameterRows/Quote/QuoteInsideMarketThrottleMinMove.cs b/src/client/spark/Modules/Spreader/VM/ParameterRows/Quote/QuoteInsideMarketThrottleMinMove.cs index b17c8fa13..a591107e3 100644 --- a/src/client/spark/Modules/Spreader/VM/ParameterRows/Quote/QuoteInsideMarketThrottleMinMove.cs +++ b/src/client/spark/Modules/Spreader/VM/ParameterRows/Quote/QuoteInsideMarketThrottleMinMove.cs @@ -1,4 +1,5 @@ using bts.shell; +using bts.spark; using mbts.collections.extensions; using mbts.ui.spark; using System.Collections.Generic; @@ -12,22 +13,27 @@ namespace mbts.spark { public override ParameterSection[] section_path { get; } = new[] { Sections.Quote, Subsections.InsideMarketThrottleThresholds }; public void apply_value(LegSpreaderParamsTuple leg_tup) => - leg_tup.leg_params.QuoteParams.QuoteInsideMarketDistanceWithTravel.Limit = _value_from_store(leg_tup); + _get_inside_market_throttle(leg_tup).Limit = _value_from_store(leg_tup); - public override uint get_value(LegSpreaderParamsTuple leg_tup) { - var inside_market_throttle = leg_tup.leg_params.QuoteParams.QuoteInsideMarketDistanceWithTravel; - return inside_market_throttle != null ? inside_market_throttle.Limit : _value_from_store(leg_tup); - } + public override uint get_value(LegSpreaderParamsTuple leg_tup) => + _get_inside_market_throttle(leg_tup) is QuoteInsideMarketDistanceWithTravel inside_market_throttle ? + inside_market_throttle.Limit : + _value_from_store(leg_tup); public override void set_value(LegSpreaderParamsTuple leg_tup, uint value) { _value_store[leg_tup.SecurityKey] = value; - var inside_market_throttle = leg_tup.leg_params.QuoteParams.QuoteInsideMarketDistanceWithTravel; - if (inside_market_throttle != null) + if (_get_inside_market_throttle(leg_tup) is QuoteInsideMarketDistanceWithTravel inside_market_throttle) inside_market_throttle.Limit = value; } + protected override bool _get_enabled(LegSpreaderParamsTuple leg_tup) => + _get_inside_market_throttle(leg_tup) != null; + + QuoteInsideMarketDistanceWithTravel _get_inside_market_throttle(LegSpreaderParamsTuple leg_tup) => + leg_tup.leg_params.QuoteParams.QuoteInsideMarketDistanceWithTravel; + uint _value_from_store(LegSpreaderParamsTuple leg_tup) => - _value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.QuoteParams.QuoteInsideMarketDistanceWithTravel.Limit); + _value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.QuoteInsideMarketDistanceWithTravel.Limit); } } } \ No newline at end of file diff --git a/src/client/spark/Modules/Spreader/VM/ParameterRows/Quote/QuoteInsideMarketThrottleTicksModel.cs b/src/client/spark/Modules/Spreader/VM/ParameterRows/Quote/QuoteInsideMarketThrottleTicksModel.cs index 5b252d307..8a361c547 100644 --- a/src/client/spark/Modules/Spreader/VM/ParameterRows/Quote/QuoteInsideMarketThrottleTicksModel.cs +++ b/src/client/spark/Modules/Spreader/VM/ParameterRows/Quote/QuoteInsideMarketThrottleTicksModel.cs @@ -13,22 +13,27 @@ namespace mbts.spark { public override ParameterSection[] section_path { get; } = new[] { Sections.Quote, Subsections.InsideMarketThrottleThresholds }; public void apply_value(LegSpreaderParamsTuple leg_tup) => - leg_tup.leg_params.QuoteParams.QuoteInsideMarketDistanceWithTravel.TicksFromInside = _value_from_store(leg_tup); + _get_inside_market_throttle(leg_tup).TicksFromInside = _value_from_store(leg_tup); - public override uint get_value(LegSpreaderParamsTuple leg_tup) { - var inside_market_throttle = leg_tup.leg_params.QuoteParams.QuoteInsideMarketDistanceWithTravel; - return inside_market_throttle != null ? inside_market_throttle.TicksFromInside : _value_from_store(leg_tup); - } + public override uint get_value(LegSpreaderParamsTuple leg_tup) => + _get_inside_market_throttle(leg_tup) is QuoteInsideMarketDistanceWithTravel inside_market_throttle ? + inside_market_throttle.TicksFromInside : + _value_from_store(leg_tup); public override void set_value(LegSpreaderParamsTuple leg_tup, uint value) { _value_store[leg_tup.SecurityKey] = value; - var inside_market_throttle = leg_tup.leg_params.QuoteParams.QuoteInsideMarketDistanceWithTravel; - if (inside_market_throttle != null) + if (_get_inside_market_throttle(leg_tup) is QuoteInsideMarketDistanceWithTravel inside_market_throttle) inside_market_throttle.TicksFromInside = value; } + protected override bool _get_enabled(LegSpreaderParamsTuple leg_tup) => + _get_inside_market_throttle(leg_tup) != null; + + QuoteInsideMarketDistanceWithTravel _get_inside_market_throttle(LegSpreaderParamsTuple leg_tup) => + leg_tup.leg_params.QuoteParams.QuoteInsideMarketDistanceWithTravel; + uint _value_from_store(LegSpreaderParamsTuple leg_tup) => - _value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.QuoteParams.QuoteInsideMarketDistanceWithTravel.TicksFromInside); + _value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.QuoteInsideMarketDistanceWithTravel.TicksFromInside); } } } \ No newline at end of file diff --git a/src/client/spark/Modules/Spreader/VM/ParameterRows/Quote/QuoteThrottleInsideTicksModel.cs b/src/client/spark/Modules/Spreader/VM/ParameterRows/Quote/QuoteThrottleInsideTicksModel.cs index 0f5b0ec02..2e5058297 100644 --- a/src/client/spark/Modules/Spreader/VM/ParameterRows/Quote/QuoteThrottleInsideTicksModel.cs +++ b/src/client/spark/Modules/Spreader/VM/ParameterRows/Quote/QuoteThrottleInsideTicksModel.cs @@ -1,4 +1,5 @@ using bts.shell; +using bts.spark; using mbts.collections.extensions; using mbts.ui.spark; using System.Collections.Generic; @@ -12,22 +13,27 @@ namespace mbts.spark { public override ParameterSection[] section_path { get; } = new[] { Sections.Quote, Subsections.Throttle }; public void apply_value(LegSpreaderParamsTuple leg_tup) => - leg_tup.leg_params.QuoteParams.QuoteMuteZone.InsideTicks = _value_from_store(leg_tup); + _get_throttle(leg_tup).InsideTicks = _value_from_store(leg_tup); - public override uint get_value(LegSpreaderParamsTuple leg_tup) { - var quote_throttle = leg_tup.leg_params.QuoteParams.QuoteMuteZone; - return quote_throttle != null ? quote_throttle.InsideTicks : _value_from_store(leg_tup); - } + public override uint get_value(LegSpreaderParamsTuple leg_tup) => + _get_throttle(leg_tup) is QuoteMuteZone throttle ? + throttle.InsideTicks : + _value_from_store(leg_tup); public override void set_value(LegSpreaderParamsTuple leg_tup, uint value) { _value_store[leg_tup.SecurityKey] = value; - var quote_throttle = leg_tup.leg_params.QuoteParams.QuoteMuteZone; - if (quote_throttle != null) - quote_throttle.InsideTicks = value; + if (_get_throttle(leg_tup) is QuoteMuteZone throttle) + throttle.InsideTicks = value; } + protected override bool _get_enabled(LegSpreaderParamsTuple leg_tup) => + _get_throttle(leg_tup) != null; + + QuoteMuteZone _get_throttle(LegSpreaderParamsTuple leg_tup) => + leg_tup.leg_params.QuoteParams.QuoteMuteZone; + uint _value_from_store(LegSpreaderParamsTuple leg_tup) => - _value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.QuoteParams.QuoteMuteZone.InsideTicks); + _value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.QuoteMuteZone.InsideTicks); } } } \ No newline at end of file diff --git a/src/client/spark/Modules/Spreader/VM/ParameterRows/Quote/QuoteThrottleOutsideTicksModel.cs b/src/client/spark/Modules/Spreader/VM/ParameterRows/Quote/QuoteThrottleOutsideTicksModel.cs index 0155fd5c3..cb0a27eb1 100644 --- a/src/client/spark/Modules/Spreader/VM/ParameterRows/Quote/QuoteThrottleOutsideTicksModel.cs +++ b/src/client/spark/Modules/Spreader/VM/ParameterRows/Quote/QuoteThrottleOutsideTicksModel.cs @@ -1,4 +1,5 @@ using bts.shell; +using bts.spark; using mbts.collections.extensions; using mbts.ui.spark; using System.Collections.Generic; @@ -12,22 +13,27 @@ namespace mbts.spark { public override ParameterSection[] section_path { get; } = new[] { Sections.Quote, Subsections.Throttle }; public void apply_value(LegSpreaderParamsTuple leg_tup) => - leg_tup.leg_params.QuoteParams.QuoteMuteZone.OutsideTicks = _value_from_store(leg_tup); + _get_throttle(leg_tup).OutsideTicks = _value_from_store(leg_tup); - public override uint get_value(LegSpreaderParamsTuple leg_tup) { - var quote_throttle = leg_tup.leg_params.QuoteParams.QuoteMuteZone; - return quote_throttle != null ? quote_throttle.OutsideTicks : _value_from_store(leg_tup); - } + public override uint get_value(LegSpreaderParamsTuple leg_tup) => + _get_throttle(leg_tup) is QuoteMuteZone throttle ? + throttle.OutsideTicks : + _value_from_store(leg_tup); public override void set_value(LegSpreaderParamsTuple leg_tup, uint value) { _value_store[leg_tup.SecurityKey] = value; - var quote_throttle = leg_tup.leg_params.QuoteParams.QuoteMuteZone; - if (quote_throttle != null) - quote_throttle.OutsideTicks = value; + if (_get_throttle(leg_tup) is QuoteMuteZone throttle) + throttle.OutsideTicks = value; } + protected override bool _get_enabled(LegSpreaderParamsTuple leg_tup) => + _get_throttle(leg_tup) != null; + + QuoteMuteZone _get_throttle(LegSpreaderParamsTuple leg_tup) => + leg_tup.leg_params.QuoteParams.QuoteMuteZone; + uint _value_from_store(LegSpreaderParamsTuple leg_tup) => - _value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.QuoteParams.QuoteMuteZone.OutsideTicks); + _value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.QuoteMuteZone.OutsideTicks); } } } \ 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 c20454edb..a5e6aa5bf 100644 --- a/src/client/spark/Modules/Spreader/VM/ParameterRows/RowModel.cs +++ b/src/client/spark/Modules/Spreader/VM/ParameterRows/RowModel.cs @@ -60,13 +60,14 @@ namespace mbts.spark { public IObservable observe_enabled(LegSpreaderParamsTuple leg_tup) => _enabled_store.GetOrAdd(leg_tup.leg.Security.Id, sec => { var rs = new ReplaySubject(1); - rs.OnNext(true); + rs.OnNext(_get_enabled(leg_tup)); return rs; }); public IObservable observe_override_value(LegSpreaderParamsTuple leg_tup) => _override_value_store.GetOrAdd(leg_tup.leg.Security.Id, sec => new Subject()); + protected virtual bool _get_enabled(LegSpreaderParamsTuple leg_tup) => true; #region IRowModel (explicit) object IRowModel.get_value(LegSpreaderParamsTuple leg_tup) => get_value(leg_tup); void IRowModel.set_value(LegSpreaderParamsTuple leg_tup, object value) { From cd5801a9b245ba8d05c0ab32feb18cdf85b72cce Mon Sep 17 00:00:00 2001 From: Pedro Pinto Date: Thu, 22 Mar 2018 20:15:12 -0400 Subject: [PATCH 07/13] Added cert reservation for Michael. --- src/lib/config/defaults/jetfix.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/config/defaults/jetfix.conf b/src/lib/config/defaults/jetfix.conf index 5e761ce22..c719216f7 100644 --- a/src/lib/config/defaults/jetfix.conf +++ b/src/lib/config/defaults/jetfix.conf @@ -247,5 +247,5 @@ JetFIX { # pp cme_mbx # taha cme_mc1 # kevin cme_mc5 - +# michael cme_mc8 SparkConnection {value {connection_name: "sim"}} From 7e1fc8fe46858b8700dda3916ca13141bffa8768 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Fri, 23 Mar 2018 08:42:49 -0500 Subject: [PATCH 08/13] PnL - fleshing out a more comprehensive PnL test --- testing/manual/misc/P&L.txt | 64 ++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/testing/manual/misc/P&L.txt b/testing/manual/misc/P&L.txt index 3c6f08f0b..6558964e5 100644 --- a/testing/manual/misc/P&L.txt +++ b/testing/manual/misc/P&L.txt @@ -1,12 +1,68 @@ P&L UI Test -Open the P&L form (Trading->P&L) +Turn merge with md off since we want to control the md -Open a ladder and select an account that's not currently listed on the P&L form +ExchangeSim { + value {merge_with_md:false} +} -Make some trades by crossing yourself in that ladder. +clear your fills database: + rm ~/.bts/data/databases/fills/* -A new P&L row with your account should come up, P&L should read zero, buy qty and sell qty should be equal +and you may also want to clear your orders for a clean slate: + rm ~/.bts/data/databases/orders/* + +Bring up the pnl form (empty). +Bring up a ladder form. It should be completely empty since we're controlling the md. For this exercise we'll be using ES. +Bring up an order ticket for your corresponding ladder + place a buy order with price 2500 and qty 100 + your ladder should populate now +Sell a 1 lot at your bid + The Start of Day (SOD) position should be 0 + Buy qty and Sell qty should be 1 (we crossed our own bid) + Net Pos should be 0 (buy 1 - sell 1) + PnL should be 0 (since we have a 0 net position) + PnL Price should be the level of your bid. + AvgBuy and Avg Sell should both represent the level at which you entered the buy and sell order +Improve the bid + Under BTS2 account (this is important for the next step), enter a 100 lot at 2500.25 + Observe the PnL Price reflect the current bid + Switch back to BTS1 +Sell a 1 lot at the current bid + You should now have rows for both the BTS1 and BTS2 account + BTS1 + Sell Qty 2 + Net Pos -1 + PnL 0 + Avg Buy 2500.0 + Avg Sell 2500.13 +Improve the Bid + Enter a 100 lot at 2500.50 + The PnL Price should reflect the current Bid (2500.5) + The PnL for BTS1 account should show -12.5 + Fill 1: 25 = (2500.5 - 2500) * 1 * 50 + Fill 2: -25 = (2500 - 2500.5) * 1 * 50 + Fill 3: -12.5 = (2500.25 - 2500.5) * 1 * 50 + The PnL for BTS2 account should show 12.5 by a similar calculation as above (but there is only 1 fill) +Go to bed and wake up the next day + The SOD for BTS1 should show a -1 + The SOD for BTS2 should show a 1 + Buy Qty for all should show 0 + Sell Qty for all should show 0 + Net Pos should be the same as SOD at the moment +The simulator might not work for orders left up overnight + If your ladder shows no working orders, place a buy order with price 2500 and qty 100 +Sell a 1 lot as the current bid + The SOD should still show -1 + The Buy and Sell Qty should show 1 (we crossed ourself) + The net position will still say -1 + Now switch to BTS2 +Sell a 5 lot at the current bid + The SOD should still show -1 + BTS1 Buy qty should show 5 + BTS1 Sell Qty should show 1 + Net Pos should show 3 (-1 (SOD) + 5 (Buys) -1 (Sells)) + BTS1 PnL should show 12.5 Test sorting and filtering From 877e915969aed0821721d9ee1bc506d088a9c93a Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Fri, 23 Mar 2018 10:20:27 -0400 Subject: [PATCH 09/13] spark-938. Support request confirmation should not be topmost. --- .../spark/view/Controls/Dialogs/SupportRequestWindow.xaml.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/client/spark/view/Controls/Dialogs/SupportRequestWindow.xaml.cs b/src/client/spark/view/Controls/Dialogs/SupportRequestWindow.xaml.cs index b0c62e386..29ed4e68c 100644 --- a/src/client/spark/view/Controls/Dialogs/SupportRequestWindow.xaml.cs +++ b/src/client/spark/view/Controls/Dialogs/SupportRequestWindow.xaml.cs @@ -29,6 +29,7 @@ namespace bts.view.controls { private void on_loaded(object sender, RoutedEventArgs e) { MoveFocus(new TraversalRequest(FocusNavigationDirection.Next)); + this.move_to_mouse(); } private void any_button_click(object sender, RoutedEventArgs e) { Close(); @@ -65,10 +66,10 @@ namespace bts.view.controls { image: screenshot )); if (reply.success) { - BTSMessageBox.Show("Your message has been received.", "Thank You", BTSMessageBoxButtons.OK, MessageBoxImage.Information, top_most:true); + BTSMessageBox.Show("Your message has been received.", "Thank You", BTSMessageBoxButtons.OK, MessageBoxImage.Information); } else { - BTSMessageBox.Show($"There was an error submitting your message. '{reply.error_message}'", "Error", BTSMessageBoxButtons.OK, MessageBoxImage.Error, top_most:true); + BTSMessageBox.Show($"There was an error submitting your message. '{reply.error_message}'", "Error", BTSMessageBoxButtons.OK, MessageBoxImage.Error); } } From f50098ee9157bdfcfefb2d46f2ee0446017a16b4 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Fri, 23 Mar 2018 10:40:52 -0400 Subject: [PATCH 10/13] fix error in setup_builds.bat --- tools/setup_builds.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/setup_builds.bat b/tools/setup_builds.bat index 431b08f6a..864627cdc 100644 --- a/tools/setup_builds.bat +++ b/tools/setup_builds.bat @@ -12,4 +12,4 @@ if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Commo ) copy /y ..\tools\cpp.build.props Directory.Build.Props del spark.sln -nuget_restore.cmd +%~dp0\nuget_restore.cmd From e00975bf4a08cbbca72fd76c1e05c8e21fa686f8 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Fri, 23 Mar 2018 09:57:45 -0500 Subject: [PATCH 11/13] PnL - typo spotted by Eric in binding --- src/client/spark/view/Spark/PAndL/PAndLView.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/spark/view/Spark/PAndL/PAndLView.xaml b/src/client/spark/view/Spark/PAndL/PAndLView.xaml index 9d8c765ae..bd6c55618 100644 --- a/src/client/spark/view/Spark/PAndL/PAndLView.xaml +++ b/src/client/spark/view/Spark/PAndL/PAndLView.xaml @@ -53,7 +53,7 @@ Date: Fri, 23 Mar 2018 10:28:44 -0400 Subject: [PATCH 12/13] minor refactoring --- .../Market/MarketView/MarketViewWindow.cs | 22 +++---- .../Market/TimeAndSales/TimeAndSalesWindow.cs | 20 +++--- .../Spreader/SyntheticManagementWindow.cs | 22 +++---- .../Modules/Trading/Fills/FillsWindow.cs | 10 +-- .../spark/core/utils/SingleValuePump.cs | 64 +++++++++---------- 5 files changed, 68 insertions(+), 70 deletions(-) diff --git a/src/client/spark/Modules/Market/MarketView/MarketViewWindow.cs b/src/client/spark/Modules/Market/MarketView/MarketViewWindow.cs index 6bed5a5fa..36b39fff5 100644 --- a/src/client/spark/Modules/Market/MarketView/MarketViewWindow.cs +++ b/src/client/spark/Modules/Market/MarketView/MarketViewWindow.cs @@ -18,7 +18,7 @@ namespace mbts.spark readonly MarketViewWindowFactory _factory; readonly OrdersModel _orders_model; - SingleValuePump _vm = new SingleValuePump(destroy: vm => vm.Dispose()); + SingleValuePump _vm = new SingleValuePump(); MarketViewWindowFactory.StartupData _state; MarketViewView _view; PartialCommand _criteria_callback_command; @@ -31,20 +31,20 @@ namespace mbts.spark _criteria_callback_command = SparkCommand.create("Update Market View", SparkCommands.ShowMarketView.icon, _updated_security_criteria_tag); Commands = new SparkCommand[] { SparkCommand.create("Change Securities", Icons.Admin, SparkTags.ShowAndEditPickMultiple, () => (_criteria_callback_command, _state.security_criteria)), - SparkCommands.ShowLadder.complete(_vm.Observable.SelectMany(vm => vm.current_security_md), md => md.HasValue, ObjectHelper.ValueOrDefault), + SparkCommands.ShowLadder.complete(_vm.observable.SelectMany(vm => vm.current_security_md), md => md.HasValue, ObjectHelper.ValueOrDefault), // TODO: ShowLinkedLadder - SparkCommands.ShowOrderTicketFromSecurity.complete(_vm.Observable.SelectMany(vm => vm.current_security_md), md => md.HasValue, ObjectHelper.ValueOrDefault), + SparkCommands.ShowOrderTicketFromSecurity.complete(_vm.observable.SelectMany(vm => vm.current_security_md), md => md.HasValue, ObjectHelper.ValueOrDefault), // TODO: ShowLinkedOrderTicket - SparkCommands.ShowFills.complete(_vm.Observable.SelectMany(vm => vm.selected_securities_observable()), _ => true, + SparkCommands.ShowFills.complete(_vm.observable.SelectMany(vm => vm.selected_securities_observable()), _ => true, secs => new FillsWindowFactory.StartupData(new FillsWindowFactory.FilterStates { security = secs.Count > 0 ? new SecurityCriteria(secs) : _state.security_criteria }) ), - SparkCommands.ShowTimeAndSales.complete(_vm.Observable.SelectMany(vm => vm.selected_securities_observable()), _ => true, secs => secs.Count > 0 ? new SecurityCriteria(secs) : _state.security_criteria), + SparkCommands.ShowTimeAndSales.complete(_vm.observable.SelectMany(vm => vm.selected_securities_observable()), _ => true, secs => secs.Count > 0 ? new SecurityCriteria(secs) : _state.security_criteria), // SpreadMatrix ?? // SyntheticCreate SparkCommands.ShowSyntheticManagement, - SparkCommands.ShowSyntheticCreate.complete(_vm.Observable.SelectMany(vm => vm.selected_securities_observable()), secs => secs.Count > 0, secs => new SecurityCriteria(secs)) + SparkCommands.ShowSyntheticCreate.complete(_vm.observable.SelectMany(vm => vm.selected_securities_observable()), secs => secs.Count > 0, secs => new SecurityCriteria(secs)) // ModifyOrder - await orders // CancelOrdersRoot ? //SparkCommands.CancelBuyOrders, @@ -61,11 +61,11 @@ namespace mbts.spark } public void update_criteria(SecurityCriteria c) => - _initialize(new MarketViewWindowFactory.StartupData(c, _vm.Current.rows_view.GetSortingCriteria(), _vm.Current.get_filter_states())); + _initialize(new MarketViewWindowFactory.StartupData(c, _vm.value.rows_view.GetSortingCriteria(), _vm.value.get_filter_states())); public override UIElement Content => _view; public override IEnumerable Commands { get; } - public override MarketViewWindowFactory.StartupData SaveState => _state = new MarketViewWindowFactory.StartupData(_state.security_criteria, _vm.Current.rows_view.GetSortingCriteria(), _vm.Current.get_filter_states()); + public override MarketViewWindowFactory.StartupData SaveState => _state = new MarketViewWindowFactory.StartupData(_state.security_criteria, _vm.value.rows_view.GetSortingCriteria(), _vm.value.get_filter_states()); public override double MinWidth => 1035 + SPARK_MENU_COLLAPSED_WIDTH + LAUNCHER_BUTTON_BORDER_WIDTH; public override void Dispose() { @@ -77,11 +77,11 @@ namespace mbts.spark void _initialize(MarketViewWindowFactory.StartupData state) { Logger.notnull(state); _state = state; - _vm.Push(new MarketViewVM(_bus, _orders_model, state.security_criteria, state.sorting_criteria, state.filters)); + _vm.value = new MarketViewVM(_bus, _orders_model, state.security_criteria, state.sorting_criteria, state.filters); if (_view == null) { - _view = new MarketViewView { DataContext = _vm.Current }; + _view = new MarketViewView { DataContext = _vm.value }; } else { - _view.DataContext = _vm.Current; + _view.DataContext = _vm.value; } } } diff --git a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesWindow.cs b/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesWindow.cs index 57fe51dc0..84f592aad 100644 --- a/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesWindow.cs +++ b/src/client/spark/Modules/Market/TimeAndSales/TimeAndSalesWindow.cs @@ -17,7 +17,7 @@ namespace mbts.spark { readonly MDConsumer _consumer; readonly TimeAndSalesWindowFactory _factory; - SingleValuePump _vm = new SingleValuePump(destroy: vm => vm.Dispose()); + SingleValuePump _vm = new SingleValuePump(); TimeAndSalesWindowFactory.StartupData _state; TimeAndSalesView _view; PartialCommand _criteria_callback_command; @@ -30,14 +30,14 @@ namespace mbts.spark { _criteria_callback_command = SparkCommand.create("Update Time and Sales", SparkCommands.ShowTimeAndSales.icon, _updated_security_criteria_tag); Commands = new SparkCommand[] { SparkCommand.create("Change Securities", Icons.Admin, SparkTags.ShowAndEditPickMultiple, () => (_criteria_callback_command, _state.security_criteria)), - SparkCommands.ShowLadder.complete(_vm.Observable.SelectMany(vm => vm.current_security_md_observable(bus)), md => md.HasValue, ObjectHelper.ValueOrDefault), - SparkCommands.ShowOrderTicketFromSecurity.complete(_vm.Observable.SelectMany(vm => vm.current_security_md_observable(bus)), md => md.HasValue, ObjectHelper.ValueOrDefault), - SparkCommands.ShowFills.complete(_vm.Observable.SelectMany(vm => vm.selected_securities_observable()), _ => true, + SparkCommands.ShowLadder.complete(_vm.observable.SelectMany(vm => vm.current_security_md_observable(bus)), md => md.HasValue, ObjectHelper.ValueOrDefault), + SparkCommands.ShowOrderTicketFromSecurity.complete(_vm.observable.SelectMany(vm => vm.current_security_md_observable(bus)), md => md.HasValue, ObjectHelper.ValueOrDefault), + SparkCommands.ShowFills.complete(_vm.observable.SelectMany(vm => vm.selected_securities_observable()), _ => true, secs => new FillsWindowFactory.StartupData(new FillsWindowFactory.FilterStates { security = secs.Count > 0 ? new SecurityCriteria(secs) : _state.security_criteria }) ), - SparkCommands.ShowMarketView.complete(_vm.Observable.SelectMany(vm => vm.selected_securities_observable()), _ => true, secs => secs.Count > 0 ? new SecurityCriteria(secs) : _state.security_criteria), + SparkCommands.ShowMarketView.complete(_vm.observable.SelectMany(vm => vm.selected_securities_observable()), _ => true, secs => secs.Count > 0 ? new SecurityCriteria(secs) : _state.security_criteria), }; _subscriptions = _bus.subscribe(_updated_security_criteria_tag).ObserveOnDispatcher().Subscribe(update_criteria); } @@ -48,11 +48,11 @@ namespace mbts.spark { return window; } - public void update_criteria(SecurityCriteria c) => _initialize(new TimeAndSalesWindowFactory.StartupData(c, _vm.Current.rows_view.GetSortingCriteria(), _vm.Current.get_filter_states())); + public void update_criteria(SecurityCriteria c) => _initialize(new TimeAndSalesWindowFactory.StartupData(c, _vm.value.rows_view.GetSortingCriteria(), _vm.value.get_filter_states())); public override UIElement Content => _view; public override IEnumerable Commands { get; } - public override TimeAndSalesWindowFactory.StartupData SaveState => _state = new TimeAndSalesWindowFactory.StartupData(_state.security_criteria, _vm.Current.rows_view.GetSortingCriteria(), _vm.Current.get_filter_states()); + public override TimeAndSalesWindowFactory.StartupData SaveState => _state = new TimeAndSalesWindowFactory.StartupData(_state.security_criteria, _vm.value.rows_view.GetSortingCriteria(), _vm.value.get_filter_states()); public override double MinWidth => 444 + SPARK_MENU_COLLAPSED_WIDTH + LAUNCHER_BUTTON_BORDER_WIDTH; public override void Dispose() { @@ -65,11 +65,11 @@ namespace mbts.spark { Logger.notnull(state); _state = state; var model = new TimeAndSalesModel(_bus, _consumer, _state.security_criteria); - _vm.Push(new TimeAndSalesVM(_bus, model, state.sorting_criteria, state.filters)); + _vm.value = new TimeAndSalesVM(_bus, model, state.sorting_criteria, state.filters); if (_view == null) - _view = new TimeAndSalesView { DataContext = _vm.Current }; + _view = new TimeAndSalesView { DataContext = _vm.value }; else - _view.DataContext = _vm.Current; + _view.DataContext = _vm.value; } } } \ No newline at end of file diff --git a/src/client/spark/Modules/Spreader/SyntheticManagementWindow.cs b/src/client/spark/Modules/Spreader/SyntheticManagementWindow.cs index f81a15a17..c032388dc 100644 --- a/src/client/spark/Modules/Spreader/SyntheticManagementWindow.cs +++ b/src/client/spark/Modules/Spreader/SyntheticManagementWindow.cs @@ -13,7 +13,7 @@ using static bts.shell.SyntheticManagementWindowFactory; namespace mbts.spark { class SyntheticManagementWindow : SparkWindow { - SingleValuePump _vm = new SingleValuePump(destroy: vm => vm.Dispose()); + SingleValuePump _vm = new SingleValuePump(); StartupData _state; OrdersModel _orders_model; SyntheticManagementView _view; @@ -29,18 +29,18 @@ namespace mbts.spark { _orders_model = orders_model; Commands = new SparkCommand[] { SparkCommand.create("Add", Icons.AddSynthetic, SparkTags.ShowSyntheticCreateTag).complete( - () => new SecurityCriteria(_vm.Current.selected_securities), () => true + () => new SecurityCriteria(_vm.value.selected_securities), () => true ), SparkCommand.create("Remove", Icons.RemoveSynthetic, SparkTags.SyntheticDeleteTag).complete( - _vm.Observable.SelectMany(vm => vm.current_row_observable), + _vm.observable.SelectMany(vm => vm.current_row_observable), can_row_change, r => r == null ? 0 : r.security_key ), SparkCommand.create("Change", Icons.ModifySynthetic, SparkTags.ShowSyntheticStrategyTag).complete( - _vm.Observable.SelectMany(vm => vm.current_row_observable), + _vm.observable.SelectMany(vm => vm.current_row_observable), can_row_change, r => r == null ? SecurityDataHelper.Defaults.SecurityImmutable : r.security ), SparkCommands.ShowLadder.complete( - _vm.Observable.SelectMany(vm => vm.current_security_md), md => md.HasValue, ObjectHelper.ValueOrDefault + _vm.observable.SelectMany(vm => vm.current_security_md), md => md.HasValue, ObjectHelper.ValueOrDefault ), SparkCommands.ShowOrders.complete(() => new OrderBookWindowFactory.OrderBookStartupData { filters = new OrderBookWindowFactory.FilterStates { - security_criteria = new SecurityCriteria(_vm.Current.row_vms.Select(r => r.security)) + security_criteria = new SecurityCriteria(_vm.value.row_vms.Select(r => r.security)) } }) }; @@ -52,19 +52,19 @@ namespace mbts.spark { public void initialize(StartupData state) { Logger.notnull(state); _state = state; - _vm.Push(new SyntheticManagementDialogVM(_bus, _orders_model, state.sorting_criteria, state.filters ?? new FilterStates())); - if (_view == null) _view = new SyntheticManagementView { DataContext = _vm.Current }; - else _view.DataContext = _vm.Current; + _vm.value = new SyntheticManagementDialogVM(_bus, _orders_model, state.sorting_criteria, state.filters ?? new FilterStates()); + if (_view == null) _view = new SyntheticManagementView { DataContext = _vm.value }; + else _view.DataContext = _vm.value; } public override UIElement Content => _view; public override IEnumerable Commands { get; } - public override StartupData SaveState => _state = new StartupData(_vm.Current.rows_view.GetSortingCriteria(), _vm.Current.get_filter_states()); + public override StartupData SaveState => _state = new StartupData(_vm.value.rows_view.GetSortingCriteria(), _vm.value.get_filter_states()); public override double MinWidth => 700; public override void Dispose() { Disposable.dispose(ref _vm); - foreach (var c in Commands.OfType()) c.Dispose(); + Commands.OfType().DisposeAll(); } } } \ No newline at end of file diff --git a/src/client/spark/Modules/Trading/Fills/FillsWindow.cs b/src/client/spark/Modules/Trading/Fills/FillsWindow.cs index 8c7c8eea8..bbe9e9a3d 100644 --- a/src/client/spark/Modules/Trading/Fills/FillsWindow.cs +++ b/src/client/spark/Modules/Trading/Fills/FillsWindow.cs @@ -10,7 +10,7 @@ namespace mbts.spark { class FillsWindow : SparkWindow { readonly OrdersModel _orders_model; - SingleValuePump _vm = new SingleValuePump(destroy: vm => vm.Dispose()); + SingleValuePump _vm = new SingleValuePump(); FillsWindowFactory.StartupData _state; FillsView _view; @@ -26,13 +26,13 @@ namespace mbts.spark public void initialize(FillsWindowFactory.StartupData state) { Logger.notnull(state); _state = state; - _vm.Push(new FillsVM(_bus,_orders_model, state.orders, state.sorting_criteria, state.filters)); - if (_view == null) _view = new FillsView { DataContext = _vm.Current }; - else _view.DataContext = _vm.Current; + _vm.value = new FillsVM(_bus,_orders_model, state.orders, state.sorting_criteria, state.filters); + if (_view == null) _view = new FillsView { DataContext = _vm.value }; + else _view.DataContext = _vm.value; } public override UIElement Content => _view; - public override FillsWindowFactory.StartupData SaveState => _state = new FillsWindowFactory.StartupData(_vm.Current.orders, _vm.Current.rows_view.GetSortingCriteria(), _vm.Current.get_filters()); + public override FillsWindowFactory.StartupData SaveState => _state = new FillsWindowFactory.StartupData(_vm.value.orders, _vm.value.rows_view.GetSortingCriteria(), _vm.value.get_filters()); public override double MinWidth => 1050 + SPARK_MENU_COLLAPSED_WIDTH + LAUNCHER_BUTTON_BORDER_WIDTH; public override void Dispose() => Disposable.dispose(ref _vm); diff --git a/src/client/spark/core/utils/SingleValuePump.cs b/src/client/spark/core/utils/SingleValuePump.cs index 3380e9a32..9db863197 100644 --- a/src/client/spark/core/utils/SingleValuePump.cs +++ b/src/client/spark/core/utils/SingleValuePump.cs @@ -1,42 +1,40 @@ using System; -using System.Collections.Generic; using System.Reactive.Linq; -using System.Reactive.Subjects; -namespace mbts.utils -{ - class SingleValuePump : IDisposable - { - public SingleValuePump(Action init=null, Action destroy=null) { - // use publisher to ensure that, for each new value, init is called and Current is assigned before the subscribers are notified - bool value_set = false; - Func assign_and_select = init != null ? - new Func(v => { - init(v); - Current = v; - value_set = true; - return v; - }) : - new Func(v => { - Current = v; - value_set = true; - return v; - }); - var publisher = _pump.Select(assign_and_select).Publish(); - Observable = publisher.AsObservable(); - _disposables.Add(publisher.Connect()); - if (destroy != null) { - _disposables.Add(_pump.PairWithPrevious().Skip(1).Select(vals => vals.prev).Subscribe(destroy)); - _disposables.Add(Disposable.Create(() => { if (value_set) destroy(Current); })); +namespace mbts.utils { + class SingleValuePump : IDisposable { + readonly Action _init, _destroy; + T _value; + bool _value_present; + + public SingleValuePump() + : this(null, val => (val as IDisposable)?.Dispose()) { } + + public SingleValuePump(Action init, Action destroy) { + _init = init; + _destroy = destroy; + } + + public event Action value_changed; + + public T value { + get => _value; + set { + if (_value_present) + _destroy?.Invoke(_value); + _value_present = true; + _value = value; + _init?.Invoke(value); + value_changed?.Invoke(value); } } - readonly List _disposables = new List(3); - readonly Subject _pump = new Subject(); + public IObservable observable => + Observable.FromEvent, T>(cb => value_changed += cb, cb => value_changed -= cb); - public T Current { get; private set; } - public void Push(T value) => _pump.OnNext(value); - public IObservable Observable { get; } - public void Dispose() => Disposable.dispose(_disposables); + public void Dispose() { + if (_value_present) + _destroy?.Invoke(_value); + } } } \ No newline at end of file From 0e15784a4333b0601255d59f06006aadecce0dcd Mon Sep 17 00:00:00 2001 From: John Colvin Date: Fri, 23 Mar 2018 12:40:16 -0400 Subject: [PATCH 13/13] SPARK-932 When adding a new synthetic... --- .../Spreader/ShowSyntheticEditorHandler.cs | 24 ++++++++++++++++++- .../Spreader/SyntheticManagementWindow.cs | 5 +++- .../Modules/Spreader/VM/SyntheticEditorVM.cs | 18 ++++++++++---- .../VM/SyntheticManagementDialogVM.cs | 7 +++--- src/client/spark/core/Bus/SparkTags.cs | 1 + 5 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/client/spark/Modules/Spreader/ShowSyntheticEditorHandler.cs b/src/client/spark/Modules/Spreader/ShowSyntheticEditorHandler.cs index ba41f2962..dda21adc2 100644 --- a/src/client/spark/Modules/Spreader/ShowSyntheticEditorHandler.cs +++ b/src/client/spark/Modules/Spreader/ShowSyntheticEditorHandler.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.ComponentModel.Composition; using System.Linq; using System.Reactive.Linq; +using System.Text.RegularExpressions; using System.Threading.Tasks; namespace bts.shell { @@ -32,6 +33,16 @@ namespace bts.shell { v.Show(-250, -200, true); } + static string _get_clone_name(string name) { + if (string.IsNullOrEmpty(name)) + return string.Empty; + var regex = new Regex(@"(?<=\()\d+(?=\)$)"); + var match = regex.Match(name); + return match.Success && int.TryParse(match.Value, out int i) && i < int.MaxValue ? + regex.Replace(name, (i + 1).ToString()) : + name + "(1)"; + } + async void _show_synthetic_create(SecurityCriteria security_criteria) => _show_synthetic_create((await security_criteria.securities(_bus)).ToList()); @@ -61,6 +72,16 @@ namespace bts.shell { _show_synthetic_editor(new SyntheticEditorVM(_model.spreader, verified_synthetic, lookup.result, _model.security_has_working_orders(verified_synthetic.Id))); } + void _show_synthetic_clone((SecurityImmutable security, ExecutionStrategyImmutable strategy) args) { + if (args.security.ContractCase == Security.ContractOneofCase.Synthetic) { + var mutable_sec = args.security.CloneToMutable(); + mutable_sec.Id = 0; + mutable_sec.Synthetic.Name = _get_clone_name(mutable_sec.Synthetic.Name); + _show_synthetic_editor(new SyntheticEditorVM(_bus, _model.spreader, new SecurityImmutable(mutable_sec), args.strategy, true)); + } else + _show_synthetic_strategy(args.security); + } + void _show_synthetic_create(IEnumerable legs) { var syn = SyntheticDataHelper.Defaults.SyntheticContract("Synthetic", legs); var sec = new SecurityImmutable(new Security { @@ -78,7 +99,8 @@ namespace bts.shell { Disposable.dispose(ref _dispose); _dispose = Disposable.Create( _bus.subscribe(SparkTags.ShowSyntheticCreateTag).ObserveOnDispatcher().Subscribe(_show_synthetic_create), - _bus.subscribe(SparkTags.ShowSyntheticStrategyTag).ObserveOnDispatcher().Subscribe(_show_synthetic_strategy) + _bus.subscribe(SparkTags.ShowSyntheticStrategyTag).ObserveOnDispatcher().Subscribe(_show_synthetic_strategy), + _bus.subscribe(SparkTags.ShowSyntheticCloneTag).ObserveOnDispatcher().Subscribe(_show_synthetic_clone) ); } diff --git a/src/client/spark/Modules/Spreader/SyntheticManagementWindow.cs b/src/client/spark/Modules/Spreader/SyntheticManagementWindow.cs index c032388dc..bac5fb36d 100644 --- a/src/client/spark/Modules/Spreader/SyntheticManagementWindow.cs +++ b/src/client/spark/Modules/Spreader/SyntheticManagementWindow.cs @@ -29,13 +29,16 @@ namespace mbts.spark { _orders_model = orders_model; Commands = new SparkCommand[] { SparkCommand.create("Add", Icons.AddSynthetic, SparkTags.ShowSyntheticCreateTag).complete( - () => new SecurityCriteria(_vm.value.selected_securities), () => true + () => new SecurityCriteria(), () => true ), SparkCommand.create("Remove", Icons.RemoveSynthetic, SparkTags.SyntheticDeleteTag).complete( _vm.observable.SelectMany(vm => vm.current_row_observable), can_row_change, r => r == null ? 0 : r.security_key ), SparkCommand.create("Change", Icons.ModifySynthetic, SparkTags.ShowSyntheticStrategyTag).complete( _vm.observable.SelectMany(vm => vm.current_row_observable), can_row_change, r => r == null ? SecurityDataHelper.Defaults.SecurityImmutable : r.security + ), SparkCommand.create("Clone", Icons.CloneSynthetic, SparkTags.ShowSyntheticCloneTag).complete( + _vm.observable.SelectMany(vm => vm.current_row_observable), + r => r != null && r.strategy.HasValue, r => r == null ? default : (r.security, r.strategy.Value) ), SparkCommands.ShowLadder.complete( _vm.observable.SelectMany(vm => vm.current_security_md), md => md.HasValue, ObjectHelper.ValueOrDefault ), SparkCommands.ShowOrders.complete(() => new OrderBookWindowFactory.OrderBookStartupData { diff --git a/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs b/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs index 6495a3ab5..509096b46 100644 --- a/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs +++ b/src/client/spark/Modules/Spreader/VM/SyntheticEditorVM.cs @@ -62,7 +62,7 @@ namespace mbts.spark { /// The application bus /// The new synthetic security to create, or existing synthetic security who's strategy to modify, on commit /// The new strategy to create, or existing strategy to modify, on commit - public SyntheticEditorVM(IBus bus, SpreaderModel model, SecurityImmutable synthetic, ExecutionStrategyImmutable strategy) + public SyntheticEditorVM(IBus bus, SpreaderModel model, SecurityImmutable synthetic, ExecutionStrategyImmutable strategy, bool override_auto_set_behavior = false) : this (synthetic, strategy, true) { ExceptionAssert.InvalidOperation.That(synthetic.Id == 0, "This constructor may only be used for new synthetic securities (id must be zero)."); title = "Create Synthetic"; @@ -112,10 +112,18 @@ namespace mbts.spark { } } }, () => leg_count >= 2); - _deduce_name(); - _deduce_ticks(); - _deduce_quantities(); - _deduce_price_mults(); + if (override_auto_set_behavior) { + _set_name_automatically = false; + _set_ticks_automatically = false; + _set_quantities_automatically = false; + _set_price_mults_automatically = false; + _tick_factors = TickUtils.get_regional_ticks(_synthetic.ContractSpec).low_tick; + } else { + _deduce_name(); + _deduce_ticks(); + _deduce_quantities(); + _deduce_price_mults(); + } _validate_leg_count(); leg_tuples.CollectionChanged += (s, e) => { if (_set_name_automatically) _deduce_name(); diff --git a/src/client/spark/Modules/Spreader/VM/SyntheticManagementDialogVM.cs b/src/client/spark/Modules/Spreader/VM/SyntheticManagementDialogVM.cs index 5c2d6e372..3337794ba 100644 --- a/src/client/spark/Modules/Spreader/VM/SyntheticManagementDialogVM.cs +++ b/src/client/spark/Modules/Spreader/VM/SyntheticManagementDialogVM.cs @@ -54,13 +54,14 @@ namespace mbts.spark { #endregion public class Row : SecurityMDRow, IEquatable { + public readonly ExecutionStrategyImmutable? strategy; + readonly IBus _bus; - readonly ExecutionStrategyImmutable? _strategy; readonly Property _n_working_orders; public Row(IBus bus, SecurityMD security_md, ExecutionStrategyImmutable? strategy, OrdersModel orders_model) : base(security_md) { _bus = bus; - _strategy = strategy; + this.strategy = strategy; _n_working_orders = backing(nameof(n_working_orders), orders_model.on_security_orders(security_key) .Select(t => (uint)(t.state @@ -78,7 +79,7 @@ namespace mbts.spark { public string name { get; } public int n_legs { get; } public string description { get; } - public bool strategy_present => _strategy.HasValue; + public bool strategy_present => strategy.HasValue; public uint n_working_orders => _n_working_orders.Value; public ICommand show_ladder { get; } public ICommand show_order_book { get; } diff --git a/src/client/spark/core/Bus/SparkTags.cs b/src/client/spark/core/Bus/SparkTags.cs index 7290b77a2..f87d65f94 100644 --- a/src/client/spark/core/Bus/SparkTags.cs +++ b/src/client/spark/core/Bus/SparkTags.cs @@ -53,6 +53,7 @@ namespace mbts.spark public static ITag ShowMarketViewTag { get; } = new SparkTag("Show MarketView"); public static ITag ShowOrderBookTag { get; } = new SparkTag(nameof(ShowOrderBookTag)); public static ITag ShowPAndLTag { get; } = new SparkTag(nameof(ShowPAndLTag)); + public static ITag<(SecurityImmutable security, ExecutionStrategyImmutable strategy)> ShowSyntheticCloneTag { get; } = new SparkTag<(SecurityImmutable security, ExecutionStrategyImmutable strategy)>(nameof(ShowSyntheticCloneTag)); public static ITag ShowSyntheticCreateTag { get; } = new SparkTag(nameof(ShowSyntheticCreateTag)); public static ITag ShowSyntheticStrategyTag { get; } = new SparkTag(nameof(ShowSyntheticStrategyTag)); public static ITag ShowSyntheticManagementTag { get; } = new SparkTag(nameof(ShowSyntheticManagementTag));