From efcb4f471c245b63d5d91bf99bab0fac62afa6ea Mon Sep 17 00:00:00 2001 From: John Colvin Date: Wed, 14 Aug 2019 15:40:23 -0500 Subject: [PATCH] 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; }