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:
@@ -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("&", "&").replace("<", "<").replace(">", ">")
|
||||
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user