diff --git a/tests/exchange/test_okx.py b/tests/exchange/test_okx.py index 97f8a3a4c..8d505da7f 100644 --- a/tests/exchange/test_okx.py +++ b/tests/exchange/test_okx.py @@ -6,6 +6,7 @@ import pytest from freqtrade.enums import CandleType, MarginMode, TradingMode from freqtrade.exceptions import RetryableOrderError, TemporaryError +from freqtrade.exchange.common import API_FETCH_ORDER_RETRY_COUNT from freqtrade.exchange.exchange import timeframe_to_minutes from tests.conftest import EXMS, get_patched_exchange, log_has from tests.exchange.test_exchange import ccxt_exceptionhandlers @@ -610,6 +611,39 @@ def test_fetch_stoploss_order_okx(default_conf, mocker): assert dro_mock.call_count == 1 +def test_fetch_stoploss_order_okx_exceptions(default_conf_usdt, mocker): + default_conf_usdt["dry_run"] = False + api_mock = MagicMock() + ccxt_exceptionhandlers( + mocker, + default_conf_usdt, + api_mock, + "okx", + "fetch_stoploss_order", + "fetch_order", + retries=API_FETCH_ORDER_RETRY_COUNT + 1, + order_id="12345", + pair="ETH/USDT", + ) + + # Test 2nd part of the function + api_mock.fetch_order = MagicMock(side_effect=ccxt.OrderNotFound()) + api_mock.fetch_closed_orders = MagicMock(return_value=[]) + api_mock.fetch_canceled_orders = MagicMock(return_value=[]) + + ccxt_exceptionhandlers( + mocker, + default_conf_usdt, + api_mock, + "okx", + "fetch_stoploss_order", + "fetch_open_orders", + retries=API_FETCH_ORDER_RETRY_COUNT + 1, + order_id="12345", + pair="ETH/USDT", + ) + + @pytest.mark.parametrize( "sl1,sl2,sl3,side", [(1501, 1499, 1501, "sell"), (1499, 1501, 1499, "buy")] )