Skip to content

Commit

Permalink
Verify if trade is closed before acting on Stoploss_on_exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
xmatthias committed Jan 23, 2020
1 parent ea5ac1e commit 70b9bd9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion freqtrade/freqtradebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,9 +689,10 @@ def handle_stoploss_on_exchange(self, trade: Trade) -> bool:
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
Expand Down
1 change: 1 addition & 0 deletions tests/test_freqtradebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 70b9bd9

Please sign in to comment.