Small cleanups

This commit is contained in:
Matthias 2022-05-28 10:07:23 +02:00
parent 05ca4fed06
commit a8218feea8
4 changed files with 7 additions and 6 deletions

View File

@ -1540,6 +1540,7 @@ class FreqtradeBot(LoggingMixin):
profit_rate = order.safe_price
if not fill:
# TODO: this call is wrong here.
trade.process_exit_sub_trade(order, is_closed=False)
profit_ratio = trade.close_profit

View File

@ -632,6 +632,9 @@ class LocalTrade():
Trade.commit()
def process_exit_sub_trade(self, order: Order, is_closed: bool = True) -> None:
"""
Recalculate trade amount and realized profit after partial exit
"""
exit_amount = order.safe_amount_after_fee
exit_rate = order.safe_price
exit_stake_amount = exit_rate * exit_amount * (1 - self.fee_close)
@ -642,10 +645,7 @@ class LocalTrade():
self.amount -= exit_amount
self.stake_amount = self.open_rate * self.amount
self.realized_profit += profit
logger.info(
'Processed exit sub trade for %s',
self
)
# logger.info(f"Processed exit sub trade for {self}")
self.close_profit_abs = profit
if self.is_short:
self.close_profit = (exit_stake_amount - profit) / exit_stake_amount - 1

View File

@ -243,7 +243,7 @@ def check_exit_timeout(self, pair: str, trade: 'Trade', order: 'Order',
"""
return False
def adjust_trade_position(self, trade: Trade, current_time: datetime,
def adjust_trade_position(self, trade: 'Trade', current_time: datetime,
current_rate: float, current_profit: float,
min_stake: Optional[float], max_stake: float,
current_entry_rate: float, current_exit_rate: float,

View File

@ -5860,4 +5860,4 @@ def test_check_and_call_adjust_trade_position(mocker, default_conf_usdt, fee, ca
freqtrade.strategy.adjust_trade_position = MagicMock(return_value=-10)
freqtrade.process_open_trade_positions()
assert log_has_re(r"Processed exit sub trade for .*", caplog)
# assert log_has_re(r"Processed exit sub trade for .*", caplog)