Add safe_close_rate

This commit is contained in:
Matthias 2023-02-16 09:02:57 +00:00
parent e59eaf33e0
commit 608a7c2d38
2 changed files with 6 additions and 2 deletions

View File

@ -1639,7 +1639,7 @@ class FreqtradeBot(LoggingMixin):
profit = trade.calc_profit(rate=order_rate, amount=amount, open_rate=trade.open_rate) profit = trade.calc_profit(rate=order_rate, amount=amount, open_rate=trade.open_rate)
profit_ratio = trade.calc_profit_ratio(order_rate, amount, trade.open_rate) profit_ratio = trade.calc_profit_ratio(order_rate, amount, trade.open_rate)
else: else:
order_rate = trade.close_rate if trade.close_rate else trade.close_rate_requested order_rate = trade.safe_close_rate
profit = trade.calc_profit(rate=order_rate) + (0.0 if fill else trade.realized_profit) profit = trade.calc_profit(rate=order_rate) + (0.0 if fill else trade.realized_profit)
profit_ratio = trade.calc_profit_ratio(order_rate) profit_ratio = trade.calc_profit_ratio(order_rate)
amount = trade.amount amount = trade.amount
@ -1694,7 +1694,7 @@ class FreqtradeBot(LoggingMixin):
raise DependencyException( raise DependencyException(
f"Order_obj not found for {order_id}. This should not have happened.") f"Order_obj not found for {order_id}. This should not have happened.")
profit_rate: float = trade.close_rate if trade.close_rate else trade.close_rate_requested profit_rate: float = trade.safe_close_rate
profit_trade = trade.calc_profit(rate=profit_rate) profit_trade = trade.calc_profit(rate=profit_rate)
current_rate = self.exchange.get_rate( current_rate = self.exchange.get_rate(
trade.pair, side='exit', is_short=trade.is_short, refresh=False) trade.pair, side='exit', is_short=trade.is_short, refresh=False)

View File

@ -1065,6 +1065,10 @@ class LocalTrade():
""" DEPRECATED! Please use exit_reason instead.""" """ DEPRECATED! Please use exit_reason instead."""
return self.exit_reason return self.exit_reason
@property
def safe_close_rate(self) -> float:
return self.close_rate or self.close_rate_requested or 0.0
@staticmethod @staticmethod
def get_trades_proxy(*, pair: Optional[str] = None, is_open: Optional[bool] = None, def get_trades_proxy(*, pair: Optional[str] = None, is_open: Optional[bool] = None,
open_date: Optional[datetime] = None, open_date: Optional[datetime] = None,