From 99583bbd0ca9525aca9968740b4eda5f9e3da9a8 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 9 Mar 2021 20:21:08 +0100 Subject: [PATCH] Fix problem with FTX where cancelled orders are "cancelled", not "canceled" --- freqtrade/exchange/exchange.py | 3 ++- freqtrade/freqtradebot.py | 4 ++-- freqtrade/persistence/models.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 617cd6c26..e457b78de 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -1053,7 +1053,8 @@ class Exchange: :param order: Order dict as returned from fetch_order() :return: True if order has been cancelled without being filled, False otherwise. """ - return order.get('status') in ('closed', 'canceled') and order.get('filled') == 0.0 + return (order.get('status') in ('closed', 'canceled', 'cancelled') + and order.get('filled') == 0.0) @retrier def cancel_order(self, order_id: str, pair: str) -> Dict: diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index f605d61c4..27c8bd48a 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -1023,13 +1023,13 @@ class FreqtradeBot(LoggingMixin): was_trade_fully_canceled = False # Cancelled orders may have the status of 'canceled' or 'closed' - if order['status'] not in ('canceled', 'closed'): + if order['status'] not in ('cancelled', 'canceled', 'closed'): corder = self.exchange.cancel_order_with_result(trade.open_order_id, trade.pair, trade.amount) # Avoid race condition where the order could not be cancelled coz its already filled. # Simply bailing here is the only safe way - as this order will then be # handled in the next iteration. - if corder.get('status') not in ('canceled', 'closed'): + if corder.get('status') not in ('cancelled', 'canceled', 'closed'): logger.warning(f"Order {trade.open_order_id} for {trade.pair} not cancelled.") return False else: diff --git a/freqtrade/persistence/models.py b/freqtrade/persistence/models.py index 3c9a10fb7..a4702fdf5 100644 --- a/freqtrade/persistence/models.py +++ b/freqtrade/persistence/models.py @@ -425,7 +425,7 @@ class Trade(_DECL_BASE): self.close_rate_requested = self.stop_loss if self.is_open: logger.info(f'{order_type.upper()} is hit for {self}.') - self.close(order['average']) + self.close(safe_value_fallback(order, 'average', 'price')) else: raise ValueError(f'Unknown order type: {order_type}') cleanup_db()