From badc30baae79a5edbe4e4b10dcc4d2860a926412 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 10 Mar 2023 15:37:44 -0500 Subject: [PATCH] Add an inverse of `float_digits()`: `digits_to_dec() --- piker/data/_source.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/piker/data/_source.py b/piker/data/_source.py index d358cd96..e503105e 100644 --- a/piker/data/_source.py +++ b/piker/data/_source.py @@ -90,6 +90,21 @@ def float_digits( return int(-Decimal(str(value)).as_tuple().exponent) +def digits_to_dec( + ndigits: int, +) -> Decimal: + ''' + Return the minimum float value for an input integer value. + + eg. 3 -> 0.001 + + ''' + if ndigits == 0: + return Decimal('0') + + return Decimal('0.' + '0'*(ndigits-1) + '1') + + def ohlc_zeros(length: int) -> np.ndarray: """Construct an OHLC field formatted structarray. @@ -213,10 +228,13 @@ class Symbol(Struct): return Symbol( key=symbol, + tick_size=tick_size, lot_tick_size=lot_size, + tick_size_digits=float_digits(tick_size), lot_size_digits=float_digits(lot_size), + suffix=suffix, broker_info={broker: info}, )