Add test and fix for stop-price == limit price

closes #8758
This commit is contained in:
Matthias 2023-06-11 17:20:35 +02:00
parent 4a800fe467
commit 5844756ba1
2 changed files with 11 additions and 3 deletions

View File

@ -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

View File

@ -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):