From cfeba74900e740e820472598fe975a5b3fe26863 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 6 Nov 2018 13:06:27 -0600 Subject: [PATCH 1/3] SPARK-1715 Handle fractional numerator tick sizes --- src/client/spark/view/Spark/Core/TickUtils.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/client/spark/view/Spark/Core/TickUtils.cs b/src/client/spark/view/Spark/Core/TickUtils.cs index 8144dd74a..8febc5d33 100644 --- a/src/client/spark/view/Spark/Core/TickUtils.cs +++ b/src/client/spark/view/Spark/Core/TickUtils.cs @@ -249,7 +249,18 @@ namespace mbts.spark { var tf = _try_create_tf(tick_size, tick_base); if (tf != null && display_digits_override > 0) { int display_digit_diff = (int)display_digits_override - tf.display_digits(); - if (display_digit_diff != 0) + // we can always add display_digits (i.e. dislpay_digit_diff > 0), of course the ticks can be expressed precisely with extra 0s. + // but if we are going to remove display_digits (i.e display_digit_diff < 0), we must make sure the tick_unit is large enough to be expressed precisely with that many fewer digits + // - "-display_digit_diff <= Math.Ceiling(Math.Log10(tf.tick_unit))" will tell us if the digits can be removed without compromising precision + // - unfortunately, we cannot rely on the exchange's ContractSpec for this, there is 1 known case where the data they give us is incorrect + // SOM spreads ContractSpec (from the exchange): + // LowTick: 0.0025 (aka 1/400, or 2/800) + // MainFraction: 8 + // SubFraction: 0 + // PriceDisplayFormat: 1 + // - as you can see, this cannot possibly be formatted with 1 display digit, it ticks in increments of 1/400 + // - in practice, to maintain the '8' base, we format this in increments of 2/800 (e.g. 1-000, 1-002, 1-004, and so on up to 1-778, 2-000) + if (display_digit_diff > 0 || (display_digit_diff < 0 && -display_digit_diff <= Math.Ceiling(Math.Log10(tf.tick_unit)))) tf = _inflate_to_base(tf, tf.tick_base * Math.Pow(10, display_digit_diff)); } return tf; From d2f2e03e645ca541a162d851555164644c20f244 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Wed, 14 Aug 2019 15:31:30 -0500 Subject: [PATCH 2/3] [SPARK-1715] config toggle for som ticks fix --- src/client/spark/view/Spark/Core/TickUtils.cs | 3 ++- src/lib/config/protos/toggles.proto | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/client/spark/view/Spark/Core/TickUtils.cs b/src/client/spark/view/Spark/Core/TickUtils.cs index 8febc5d33..7eecde910 100644 --- a/src/client/spark/view/Spark/Core/TickUtils.cs +++ b/src/client/spark/view/Spark/Core/TickUtils.cs @@ -197,6 +197,7 @@ namespace mbts.spark { static class TickStore { public static readonly RegionalTickFactors default_rtf = new RegionalTickFactors(new TickFactors(1000, 1), new TickFactors(1000, 1), double.MaxValue); static readonly ConcurrentDictionary _exchange_ticks = new ConcurrentDictionary(); + static readonly bool _som_ticks_fix_enabled = config.Configuration.get().enabled; public static RegionalTickFactors get(ContractSpecification spec) => _exchange_ticks.GetOrAdd(new SpecKey(spec), _create_rtf); @@ -247,7 +248,7 @@ namespace mbts.spark { /// Well-defined TickFactors static TickFactors _try_create_tf(double tick_size, double tick_base, uint display_digits_override) { var tf = _try_create_tf(tick_size, tick_base); - if (tf != null && display_digits_override > 0) { + if (_som_ticks_fix_enabled && tf != null && display_digits_override > 0) { int display_digit_diff = (int)display_digits_override - tf.display_digits(); // we can always add display_digits (i.e. dislpay_digit_diff > 0), of course the ticks can be expressed precisely with extra 0s. // but if we are going to remove display_digits (i.e display_digit_diff < 0), we must make sure the tick_unit is large enough to be expressed precisely with that many fewer digits diff --git a/src/lib/config/protos/toggles.proto b/src/lib/config/protos/toggles.proto index af0232f0b..f1733290f 100644 --- a/src/lib/config/protos/toggles.proto +++ b/src/lib/config/protos/toggles.proto @@ -48,6 +48,10 @@ message RejectStopAndStopLimitOrders { optional bool enabled = 1 [default = true]; } +message SOMTicksFix { + optional bool enabled = 1 [default = true]; +} + message EnsureOnScreenWithWorkAreaRect { // Defaulting to false bc this is near the end of the cycle (04/27/2019), // and the new ensure_onscreen code has only been tested with a single monitor arrangement. From efcb4f471c245b63d5d91bf99bab0fac62afa6ea Mon Sep 17 00:00:00 2001 From: John Colvin Date: Wed, 14 Aug 2019 15:40:23 -0500 Subject: [PATCH 3/3] fix config toggle for som ticks --- src/client/spark/view/Spark/Core/TickUtils.cs | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/client/spark/view/Spark/Core/TickUtils.cs b/src/client/spark/view/Spark/Core/TickUtils.cs index 7eecde910..4cf1dcd37 100644 --- a/src/client/spark/view/Spark/Core/TickUtils.cs +++ b/src/client/spark/view/Spark/Core/TickUtils.cs @@ -248,21 +248,25 @@ namespace mbts.spark { /// Well-defined TickFactors static TickFactors _try_create_tf(double tick_size, double tick_base, uint display_digits_override) { var tf = _try_create_tf(tick_size, tick_base); - if (_som_ticks_fix_enabled && tf != null && display_digits_override > 0) { + if (tf != null && display_digits_override > 0) { int display_digit_diff = (int)display_digits_override - tf.display_digits(); - // we can always add display_digits (i.e. dislpay_digit_diff > 0), of course the ticks can be expressed precisely with extra 0s. - // but if we are going to remove display_digits (i.e display_digit_diff < 0), we must make sure the tick_unit is large enough to be expressed precisely with that many fewer digits - // - "-display_digit_diff <= Math.Ceiling(Math.Log10(tf.tick_unit))" will tell us if the digits can be removed without compromising precision - // - unfortunately, we cannot rely on the exchange's ContractSpec for this, there is 1 known case where the data they give us is incorrect - // SOM spreads ContractSpec (from the exchange): - // LowTick: 0.0025 (aka 1/400, or 2/800) - // MainFraction: 8 - // SubFraction: 0 - // PriceDisplayFormat: 1 - // - as you can see, this cannot possibly be formatted with 1 display digit, it ticks in increments of 1/400 - // - in practice, to maintain the '8' base, we format this in increments of 2/800 (e.g. 1-000, 1-002, 1-004, and so on up to 1-778, 2-000) - if (display_digit_diff > 0 || (display_digit_diff < 0 && -display_digit_diff <= Math.Ceiling(Math.Log10(tf.tick_unit)))) + if (_som_ticks_fix_enabled) { + // we can always add display_digits (i.e. dislpay_digit_diff > 0), of course the ticks can be expressed precisely with extra 0s. + // but if we are going to remove display_digits (i.e display_digit_diff < 0), we must make sure the tick_unit is large enough to be expressed precisely with that many fewer digits + // - "-display_digit_diff <= Math.Ceiling(Math.Log10(tf.tick_unit))" will tell us if the digits can be removed without compromising precision + // - unfortunately, we cannot rely on the exchange's ContractSpec for this, there is 1 known case where the data they give us is incorrect + // SOM spreads ContractSpec (from the exchange): + // LowTick: 0.0025 (aka 1/400, or 2/800) + // MainFraction: 8 + // SubFraction: 0 + // PriceDisplayFormat: 1 + // - as you can see, this cannot possibly be formatted with 1 display digit, it ticks in increments of 1/400 + // - in practice, to maintain the '8' base, we format this in increments of 2/800 (e.g. 1-000, 1-002, 1-004, and so on up to 1-778, 2-000) + if (display_digit_diff > 0 || (display_digit_diff < 0 && -display_digit_diff <= Math.Ceiling(Math.Log10(tf.tick_unit)))) + tf = _inflate_to_base(tf, tf.tick_base * Math.Pow(10, display_digit_diff)); + } else if (display_digit_diff != 0) { tf = _inflate_to_base(tf, tf.tick_base * Math.Pow(10, display_digit_diff)); + } } return tf; }