From 70b9bd9c0e7d2b37a4386f0809af7237a9dada6a Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 23 Jan 2020 20:36:48 +0100 Subject: [PATCH] Verify if trade is closed before acting on Stoploss_on_exchange --- freqtrade/freqtradebot.py | 3 ++- tests/test_freqtradebot.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index c150d1aa9..9f06cbb67 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -689,9 +689,10 @@ class FreqtradeBot: self._notify_sell(trade, "stoploss") return True - if trade.open_order_id: + if trade.open_order_id or not trade.is_open: # Trade has an open Buy or Sell order, Stoploss-handling can't happen in this case # as the Amount on the exchange is tied up in another trade. + # The trade can be closed already (sell-order fill confirmation came in this iteration) return False # If buy order is fulfilled but there is no stoploss, we add a stoploss on exchange diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index a80bb7452..65b5adda5 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -1127,6 +1127,7 @@ def test_handle_stoploss_on_exchange(mocker, default_conf, fee, caplog, 'freqtrade.exchange.Exchange.stoploss_limit', side_effect=DependencyException() ) + trade.is_open = True freqtrade.handle_stoploss_on_exchange(trade) assert log_has('Unable to place a stoploss order on exchange.', caplog) assert trade.stoploss_order_id is None