From 8726d63923f1ef4cb98b5d76caaf5ecd7561c157 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 6 Jan 2024 10:33:18 +0100 Subject: [PATCH] Remove unnecessary calculations for exit msg --- freqtrade/rpc/telegram.py | 11 +++++------ tests/rpc/test_rpc_telegram.py | 14 +++++++------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 533dbafe5..e51842d0a 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -348,10 +348,9 @@ class Telegram(RPCHandler): def _format_exit_msg(self, msg: Dict[str, Any]) -> str: fiat_currency = msg['fiat_currency'] - msg['profit_percent'] = round(msg['profit_ratio'] * 100, 2) - msg['duration'] = msg['close_date'].replace( + duration = msg['close_date'].replace( microsecond=0) - msg['open_date'].replace(microsecond=0) - msg['duration_min'] = msg['duration'].total_seconds() / 60 + duration_min = duration.total_seconds() / 60 msg['emoji'] = self._get_sell_emoji(msg) msg['leverage_text'] = (f"*Leverage:* `{msg['leverage']:.1g}`\n" @@ -431,7 +430,7 @@ class Telegram(RPCHandler): message += ")`" else: - message += f"\n*Duration:* `{msg['duration']} ({msg['duration_min']:.1f} min)`" + message += f"\n*Duration:* `{duration} ({duration_min:.1f} min)`" return message def compose_message(self, msg: Dict[str, Any], msg_type: RPCMessageType) -> Optional[str]: @@ -513,9 +512,9 @@ class Telegram(RPCHandler): Get emoji for sell-side """ - if float(msg['profit_percent']) >= 5.0: + if float(msg['profit_ratio']) >= 0.05: return "\N{ROCKET}" - elif float(msg['profit_percent']) >= 0.0: + elif float(msg['profit_ratio']) >= 0.0: return "\N{EIGHT SPOKED ASTERISK}" elif msg['exit_reason'] == "stop_loss": return "\N{WARNING SIGN}" diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index 54f346cad..f98990990 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -2497,13 +2497,13 @@ def test_send_msg_sell_notification_no_fiat( @pytest.mark.parametrize('msg,expected', [ - ({'profit_percent': 20.1, 'exit_reason': 'roi'}, "\N{ROCKET}"), - ({'profit_percent': 5.1, 'exit_reason': 'roi'}, "\N{ROCKET}"), - ({'profit_percent': 2.56, 'exit_reason': 'roi'}, "\N{EIGHT SPOKED ASTERISK}"), - ({'profit_percent': 1.0, 'exit_reason': 'roi'}, "\N{EIGHT SPOKED ASTERISK}"), - ({'profit_percent': 0.0, 'exit_reason': 'roi'}, "\N{EIGHT SPOKED ASTERISK}"), - ({'profit_percent': -5.0, 'exit_reason': 'stop_loss'}, "\N{WARNING SIGN}"), - ({'profit_percent': -2.0, 'exit_reason': 'sell_signal'}, "\N{CROSS MARK}"), + ({'profit_ratio': 0.201, 'exit_reason': 'roi'}, "\N{ROCKET}"), + ({'profit_ratio': 0.051, 'exit_reason': 'roi'}, "\N{ROCKET}"), + ({'profit_ratio': 0.0256, 'exit_reason': 'roi'}, "\N{EIGHT SPOKED ASTERISK}"), + ({'profit_ratio': 0.01, 'exit_reason': 'roi'}, "\N{EIGHT SPOKED ASTERISK}"), + ({'profit_ratio': 0.0, 'exit_reason': 'roi'}, "\N{EIGHT SPOKED ASTERISK}"), + ({'profit_ratio': -0.05, 'exit_reason': 'stop_loss'}, "\N{WARNING SIGN}"), + ({'profit_ratio': -0.02, 'exit_reason': 'sell_signal'}, "\N{CROSS MARK}"), ]) def test__sell_emoji(default_conf, mocker, msg, expected): del default_conf['fiat_display_currency']