Improve final exit message

This commit is contained in:
Matthias 2023-12-29 18:15:37 +01:00
parent e5e3002d45
commit b62661d8cd
3 changed files with 18 additions and 6 deletions

View File

@ -1824,6 +1824,8 @@ class FreqtradeBot(LoggingMixin):
'fiat_currency': self.config.get('fiat_display_currency'),
'sub_trade': sub_trade,
'cumulative_profit': trade.realized_profit,
'final_profit_ratio': trade.close_profit if not trade.is_open else None,
'is_final_exit': trade.is_open is False,
}
# Send the message

View File

@ -86,6 +86,8 @@ class RPCExitMsg(__RPCEntryExitMsgBase):
close_date: datetime
# current_rate: Optional[float]
order_rate: Optional[float]
final_profit_ratio: Optional[float]
is_final_exit: bool
class RPCExitCancelMsg(__RPCEntryExitMsgBase):

View File

@ -373,21 +373,29 @@ class Telegram(RPCHandler):
f"{msg['profit_extra']})")
is_fill = msg['type'] == RPCMessageType.EXIT_FILL
is_final_exit = msg.get('is_final_exit', False)
is_sub_trade = msg.get('sub_trade')
is_sub_profit = msg['profit_amount'] != msg.get('cumulative_profit')
profit_prefix = ('Sub ' if is_sub_profit else 'Cumulative ') if is_sub_trade else ''
cp_extra = ''
exit_wording = 'Exited' if is_fill else 'Exiting'
if is_sub_profit and is_sub_trade:
if (is_sub_profit and is_sub_trade) or is_final_exit:
if self._rpc._fiat_converter:
cp_fiat = self._rpc._fiat_converter.convert_amount(
msg['cumulative_profit'], msg['stake_currency'], msg['fiat_currency'])
cp_extra = f" / {cp_fiat:.3f} {msg['fiat_currency']}"
exit_wording = f"Partially {exit_wording.lower()}"
cp_extra = (
f"*Cumulative Profit:* (`{msg['cumulative_profit']:.8f} "
f"{msg['stake_currency']}{cp_extra}`)\n"
)
if is_final_exit:
profit_prefix = 'Sub '
cp_extra = (
f"*Final Profit:* `{msg['final_profit_ratio']:.2%} "
f"({msg['cumulative_profit']:.8f} {msg['stake_currency']}{cp_extra})`\n"
)
else:
exit_wording = f"Partially {exit_wording.lower()}"
cp_extra = (
f"*Cumulative Profit:* `({msg['cumulative_profit']:.8f} "
f"{msg['stake_currency']}{cp_extra})`\n"
)
message = (
f"{msg['emoji']} *{self._exchange_from_msg(msg)}:* "