From 8ccc66cd977d4a9a7048e3b3bff8d290199ae21e Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 21 Sep 2023 20:58:07 +0200 Subject: [PATCH] Add tests for cancel order retries --- tests/test_freqtradebot.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index 0886c9fca..6055ac69b 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -3334,7 +3334,7 @@ def test_manage_open_orders_exception(default_conf_usdt, ticker_usdt, open_trade def test_handle_cancel_enter(mocker, caplog, default_conf_usdt, limit_order, is_short, fee) -> None: patch_RPCManager(mocker) patch_exchange(mocker) - l_order = limit_order[entry_side(is_short)] + l_order = deepcopy(limit_order[entry_side(is_short)]) cancel_buy_order = deepcopy(limit_order[entry_side(is_short)]) cancel_buy_order['status'] = 'canceled' del cancel_buy_order['filled'] @@ -3381,6 +3381,21 @@ def test_handle_cancel_enter(mocker, caplog, default_conf_usdt, limit_order, is_ trade, limit_order[entry_side(is_short)], trade.open_orders_ids[0], reason ) + # Retry ... + cbo = limit_order[entry_side(is_short)] + + mocker.patch('freqtrade.freqtradebot.sleep') + cbo['status'] = 'open' + co_mock = mocker.patch(f'{EXMS}.cancel_order_with_result', return_value=cbo) + fo_mock = mocker.patch(f'{EXMS}.fetch_order', return_value=cbo) + assert not freqtrade.handle_cancel_enter( + trade, cbo, cbo['id'], reason, replacing=True + ) + assert co_mock.call_count == 1 + assert fo_mock.call_count == 3 + + + @pytest.mark.parametrize("is_short", [False, True]) @pytest.mark.parametrize("limit_buy_order_canceled_empty", ['binance', 'kraken', 'bittrex'],