From 9951f510795c241f516d6046b12699be885e84b6 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 18 Aug 2021 20:20:11 +0200 Subject: [PATCH] Update test to ensure direction of movement is correct --- freqtrade/freqtradebot.py | 12 ++++-------- tests/test_freqtradebot.py | 4 ++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index caf201451..e7a2a3784 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -1411,11 +1411,7 @@ class FreqtradeBot(LoggingMixin): min_custom_price_allowed = proposed_price - (proposed_price * cust_p_max_dist_r) max_custom_price_allowed = proposed_price + (proposed_price * cust_p_max_dist_r) - if valid_custom_price > max_custom_price_allowed: - valid_price = max_custom_price_allowed - elif valid_custom_price < min_custom_price_allowed: - valid_price = min_custom_price_allowed - else: - valid_price = valid_custom_price - - return valid_price + # Bracket between min_custom_price_allowed and max_custom_price_allowed + return max( + min(valid_custom_price, max_custom_price_allowed), + min_custom_price_allowed) diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index 21bad5c64..a2bb01a4b 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -4624,8 +4624,8 @@ def test_get_valid_price(mocker, default_conf) -> None: assert valid_price_from_int == custom_price_int assert valid_price_from_float == custom_price_float - assert valid_price_at_max_alwd != custom_price_over_max_alwd + assert valid_price_at_max_alwd < custom_price_over_max_alwd assert valid_price_at_max_alwd > proposed_price - assert valid_price_at_min_alwd != custom_price_under_min_alwd + assert valid_price_at_min_alwd > custom_price_under_min_alwd assert valid_price_at_min_alwd < proposed_price