From 981976681a88423117ef9bd6fe18e56f96df4476 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 5 May 2020 07:08:24 +0200 Subject: [PATCH] Use filled, it's the safer choice when determining the filled amount. --- freqtrade/freqtradebot.py | 7 +++---- tests/test_freqtradebot.py | 1 - 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 30eebb962..9db7e4467 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -898,7 +898,7 @@ class FreqtradeBot: Buy timeout - cancel order :return: True if order was fully cancelled """ - if order['status'] != 'canceled': + if order['status'] not in ('canceled', 'closed'): reason = "cancelled due to timeout" corder = self.exchange.cancel_order_with_result(trade.open_order_id, trade.pair, trade.amount) @@ -909,7 +909,7 @@ class FreqtradeBot: logger.info('Buy order %s for %s.', reason, trade) - if safe_value_fallback(corder, order, 'remaining', 'remaining') == order['amount']: + if safe_value_fallback(corder, order, 'filled', 'filled') == 0.0: logger.info('Buy order fully cancelled. Removing %s from database.', trade) # if trade is not partially completed, just delete the trade Trade.session.delete(trade) @@ -921,8 +921,7 @@ class FreqtradeBot: # cancel_order may not contain the full order dict, so we need to fallback # to the order dict aquired before cancelling. # we need to fall back to the values from order if corder does not contain these keys. - trade.amount = order['amount'] - safe_value_fallback(corder, order, - 'remaining', 'remaining') + trade.amount = safe_value_fallback(corder, order, 'filled', 'filled') trade.stake_amount = trade.amount * trade.open_rate self.update_trade_state(trade, corder, trade.amount) diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index 2b5127cc0..f2b2f6b5c 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -2346,7 +2346,6 @@ def test_handle_timedout_limit_buy_exchanges(mocker, caplog, default_conf, assert log_has_re(r'Buy order fully cancelled. Removing .* from database\.', caplog) - @pytest.mark.parametrize('cancelorder', [ {}, {'remaining': None},