fix: экранировать HTML в Telegram уведомлениях цикла

Символы < > в сообщениях (например corr=-1.000 < 0.50)
ломали HTML-парсинг Telegram API.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
anor
2026-03-09 12:16:22 +10:00
co-authored by Claude Opus 4.6
parent c2be13975f
commit 7cd49f2af6
+10 -4
View File
@@ -133,6 +133,11 @@ def format_startup_details(cfg, conn) -> str:
return "\n".join(lines)
def _escape_html(text: str) -> str:
"""Escape HTML special characters for Telegram."""
return text.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
def format_cycle_report(logs: list[str]) -> str:
"""Format cycle logs into a Telegram message."""
if not logs:
@@ -140,13 +145,14 @@ def format_cycle_report(logs: list[str]) -> str:
lines = ["<b>RemizovTrader</b>"]
for msg in logs:
safe = _escape_html(msg)
if "SIGNAL" in msg or "CLOSED" in msg:
lines.append(f" {msg}")
lines.append(f" {safe}")
elif "CB ON" in msg:
lines.append(f" {msg}")
lines.append(f" {safe}")
elif "retrained" in msg:
lines.append(f" {msg}")
lines.append(f" {safe}")
else:
lines.append(f" <i>{msg}</i>")
lines.append(f" <i>{safe}</i>")
return "\n".join(lines)