From a87ed7ba63e9a09aabbe69e70c789eb84a4d0054 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 20 Aug 2026 21:03:30 -0400 Subject: [PATCH] Fix chart pattern alert Markdown --- telegram_bot.py | 5 ++++- test_all.py | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/telegram_bot.py b/telegram_bot.py index 964cccd..4a60782 100755 --- a/telegram_bot.py +++ b/telegram_bot.py @@ -341,7 +341,10 @@ def format_signal_message(report: SignalReport) -> str: f"๐Ÿ“Š Regime: {regime_str} ยท Vol: {vol_str}", ] if report.action_recommendation: - lines.append(f"_{_escape_md(report.action_recommendation)}_") + # Pattern identifiers use underscores, which legacy Telegram Markdown + # can misparse even when escaped inside this italicized action line. + action = report.action_recommendation.replace("_", " ") + lines.append(f"_{_escape_md(action)}_") if report.trade_setup and sig not in (SignalStrength.NEUTRAL,): ts = report.trade_setup diff --git a/test_all.py b/test_all.py index f854353..54b9719 100644 --- a/test_all.py +++ b/test_all.py @@ -1685,6 +1685,15 @@ def _(): assert "Not financial advice" in msg +@test("format_signal_message makes chart pattern actions Markdown-safe") +def _(): + report = SignalReport(symbol="XAU/USD", display_name="XAU/USD", timestamp="now") + report.action_recommendation = "BUY โ€” double_bottom pattern completion" + msg = format_signal_message(report) + assert "_BUY โ€” double bottom pattern completion_" in msg + assert "double_bottom" not in msg + + @test("format_signal_message renders stamped per-TF trail plan") def _(): def _setup(**extra):