From 80faa5feb14913ad6c17307b893aead1272b9040 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 10 May 2020 16:24:00 +0200 Subject: [PATCH 1/2] Add test to cancel sell order --- tests/test_freqtradebot.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index c502e264c..01e74c7a2 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -2405,6 +2405,21 @@ def test_handle_timedout_limit_sell(mocker, default_conf) -> None: assert cancel_order_mock.call_count == 1 +def test_handle_timedout_limit_sell_cancel_exception(mocker, default_conf) -> None: + patch_RPCManager(mocker) + patch_exchange(mocker) + mocker.patch( + 'freqtrade.exchange.Exchange.cancel_order', side_effect=InvalidOrderException()) + + freqtrade = FreqtradeBot(default_conf) + + trade = MagicMock() + order = {'remaining': 1, + 'amount': 1, + 'status': "open"} + assert freqtrade.handle_timedout_limit_sell(trade, order) == 'error cancelling order' + + def test_execute_sell_up(default_conf, ticker, fee, ticker_sell_up, mocker) -> None: rpc_mock = patch_RPCManager(mocker) patch_exchange(mocker) From 73a1496318d1b9e594a098f5e8bc25d62137fc3b Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 10 May 2020 17:44:45 +0200 Subject: [PATCH 2/2] Catch exception on cancel_order --- freqtrade/freqtradebot.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 930baff1f..4f4b3e3bb 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -949,8 +949,12 @@ class FreqtradeBot: if order['remaining'] == order['amount'] or order.get('filled') == 0.0: if not self.exchange.check_order_canceled_empty(order): reason = "cancelled due to timeout" - # if trade is not partially completed, just delete the trade - self.exchange.cancel_order(trade.open_order_id, trade.pair) + try: + # if trade is not partially completed, just delete the trade + self.exchange.cancel_order(trade.open_order_id, trade.pair) + except InvalidOrderException: + logger.exception(f"Could not cancel sell order {trade.open_order_id}") + return 'error cancelling order' logger.info('Sell order %s for %s.', reason, trade) else: reason = "cancelled on exchange"