From 5844756ba15714e4d1a0bdfed064a85d54220d42 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 11 Jun 2023 17:20:35 +0200 Subject: [PATCH] Add test and fix for stop-price == limit price closes #8758 --- freqtrade/exchange/exchange.py | 4 ++-- tests/exchange/test_exchange.py | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 88022e19c..ef3bea537 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -1148,8 +1148,8 @@ class Exchange: else: limit_rate = stop_price * (2 - limit_price_pct) - bad_stop_price = ((stop_price <= limit_rate) if side == - "sell" else (stop_price >= limit_rate)) + bad_stop_price = ((stop_price < limit_rate) if side == + "sell" else (stop_price > limit_rate)) # Ensure rate is less than stop price if bad_stop_price: # This can for example happen if the stop / liquidation price is set to 0 diff --git a/tests/exchange/test_exchange.py b/tests/exchange/test_exchange.py index bbf86744b..5fa2755d2 100644 --- a/tests/exchange/test_exchange.py +++ b/tests/exchange/test_exchange.py @@ -3492,14 +3492,22 @@ def test_stoploss_order_unsupported_exchange(default_conf, mocker): @pytest.mark.parametrize('side,ratio,expected', [ ('sell', 0.99, 99.0), # Default ('sell', 0.999, 99.9), + ('sell', 1, 100), + ('sell', 1.1, InvalidOrderException), ('buy', 0.99, 101.0), # Default ('buy', 0.999, 100.1), + ('buy', 1, 100), + ('buy', 1.1, InvalidOrderException), ]) def test__get_stop_limit_rate(default_conf_usdt, mocker, side, ratio, expected): exchange = get_patched_exchange(mocker, default_conf_usdt, id='binance') order_types = {'stoploss_on_exchange_limit_ratio': ratio} - assert exchange._get_stop_limit_rate(100, order_types, side) == expected + if isinstance(expected, type) and issubclass(expected, Exception): + with pytest.raises(expected): + exchange._get_stop_limit_rate(100, order_types, side) + else: + assert exchange._get_stop_limit_rate(100, order_types, side) == expected def test_merge_ft_has_dict(default_conf, mocker):