diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index d1ef75cf5..4e4c080d0 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -20,7 +20,7 @@ logger = logging.getLogger(__name__) logger.debug('Included module rpc.telegram ...') -MAX_TELEGRAM_MESSAGE = 4096 +MAX_TELEGRAM_MESSAGE_LENGTH = 4096 def authorized_only(command_handler: Callable[..., None]) -> Callable[..., Any]: @@ -339,7 +339,7 @@ class Telegram(RPC): curr_output = "*{currency}:* not showing <1$ amount \n".format(**currency) # Handle overflowing messsage length - if len(output + curr_output) >= MAX_TELEGRAM_MESSAGE: + if len(output + curr_output) >= MAX_TELEGRAM_MESSAGE_LENGTH: self._send_msg(output, bot=bot) output = curr_output else: diff --git a/freqtrade/tests/rpc/test_rpc_telegram.py b/freqtrade/tests/rpc/test_rpc_telegram.py index 137d7b3b6..f2f3f3945 100644 --- a/freqtrade/tests/rpc/test_rpc_telegram.py +++ b/freqtrade/tests/rpc/test_rpc_telegram.py @@ -621,6 +621,11 @@ def test_balance_handle_too_large_response(default_conf, update, mocker) -> None telegram._balance(bot=MagicMock(), update=update) assert msg_mock.call_count > 1 + # Test if wrap happens around 4000 - + # and each single currency-output is around 120 characters long so we need + # an offset to avoid random test failures + assert len(msg_mock.call_args_list[0][0][0]) < 4096 + assert len(msg_mock.call_args_list[0][0][0]) > (4096 - 120) def test_start_handle(default_conf, update, mocker) -> None: