diff --git a/freqtrade/exchange/exchange_utils.py b/freqtrade/exchange/exchange_utils.py index 41322a550..7eca242f7 100644 --- a/freqtrade/exchange/exchange_utils.py +++ b/freqtrade/exchange/exchange_utils.py @@ -279,15 +279,15 @@ def price_to_precision( )) if precisionMode == TICK_SIZE: - if rounding_mode == ROUND: - ticks = price / price_precision - rounded_ticks = round(ticks) - return rounded_ticks * price_precision precision = FtPrecise(price_precision) price_str = FtPrecise(price) missing = price_str % precision if not missing == FtPrecise("0"): - return round(float(str(price_str - missing + precision)), 14) + if rounding_mode == ROUND_UP: + res = price_str - missing + precision + elif rounding_mode == ROUND_DOWN: + res = price_str - missing + return round(float(str(res)), 14) return price elif precisionMode in (SIGNIFICANT_DIGITS, DECIMAL_PLACES): diff --git a/tests/exchange/test_exchange_utils.py b/tests/exchange/test_exchange_utils.py index 3ddb0c26f..445920bae 100644 --- a/tests/exchange/test_exchange_utils.py +++ b/tests/exchange/test_exchange_utils.py @@ -247,11 +247,14 @@ def test_amount_to_precision(amount, precision_mode, precision, expected,): (2.34559, TICK_SIZE, 0.001, 2.346, ROUND_UP), (2.9999, TICK_SIZE, 0.001, 3.000, ROUND_UP), (2.9909, TICK_SIZE, 0.001, 2.991, ROUND_UP), + (2.9909, TICK_SIZE, 0.001, 2.990, ROUND_DOWN), (2.9909, TICK_SIZE, 0.005, 2.995, ROUND_UP), (2.9973, TICK_SIZE, 0.005, 3.0, ROUND_UP), (2.9977, TICK_SIZE, 0.005, 3.0, ROUND_UP), (234.43, TICK_SIZE, 0.5, 234.5, ROUND_UP), + (234.43, TICK_SIZE, 0.5, 234.0, ROUND_DOWN), (234.53, TICK_SIZE, 0.5, 235.0, ROUND_UP), + (234.53, TICK_SIZE, 0.5, 234.5, ROUND_DOWN), (0.891534, TICK_SIZE, 0.0001, 0.8916, ROUND_UP), (64968.89, TICK_SIZE, 0.01, 64968.89, ROUND_UP), (0.000000003483, TICK_SIZE, 1e-12, 0.000000003483, ROUND_UP),