Fix bug closing trades while recalculating

closes #9186
This commit is contained in:
Matthias
2023-09-16 14:43:23 +02:00
parent 6d2d5f93d0
commit 3d858f6599
2 changed files with 4 additions and 3 deletions

View File

@@ -1888,7 +1888,7 @@ class FreqtradeBot(LoggingMixin):
self.handle_order_fee(trade, order_obj, order)
trade.update_trade(order_obj)
trade.update_trade(order_obj, not send_msg)
trade = self._update_trade_after_fill(trade, order_obj)
Trade.commit()

View File

@@ -728,7 +728,7 @@ class LocalTrade:
f"Trailing stoploss saved us: "
f"{float(self.stop_loss) - float(self.initial_stop_loss or 0.0):.8f}.")
def update_trade(self, order: Order) -> None:
def update_trade(self, order: Order, recalculating: bool = False) -> None:
"""
Updates this entity with amount and actual open/close rates.
:param order: order retrieved by exchange.fetch_order()
@@ -770,8 +770,9 @@ class LocalTrade:
self.precision_mode, self.contract_size)
if (
isclose(order.safe_amount_after_fee, amount_tr, abs_tol=MATH_CLOSE_PREC)
or order.safe_amount_after_fee > amount_tr
or (not recalculating and order.safe_amount_after_fee > amount_tr)
):
# When recalculating a trade, only comming out to 0 can force a close
self.close(order.safe_price)
else:
self.recalc_trade_from_orders()