feat: Telegram уведомления при старте/остановке бота

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
anor
2026-03-09 03:04:40 +10:00
co-authored by Claude Opus 4.6
parent f82cc4aa3a
commit f53afcfa5a
2 changed files with 26 additions and 2 deletions
+15 -2
View File
@@ -184,12 +184,21 @@ def daemon():
"""Run as daemon — auto-cycle on schedule + web dashboard."""
from apscheduler.schedulers.background import BackgroundScheduler
import platform
from .core.executor import run_cycle
from .notify import format_cycle_report, send_telegram
from .notify import format_cycle_report, send_status, send_telegram
from .web.app import create_app
cfg = load_config()
# Notify: bot started
if cfg.telegram.enabled:
info = (f"Host: <code>{platform.node()}</code>\n"
f"TF: {cfg.timeframe}, Assets: {len(cfg.assets)}\n"
f"Mode: {cfg.mode}")
send_status(cfg.telegram, "start", info)
def scheduled_cycle():
conn = get_db()
init_db(conn)
@@ -226,7 +235,11 @@ def daemon():
# Start web server (blocking)
import uvicorn
app = create_app(cfg)
uvicorn.run(app, host=cfg.web.host, port=cfg.web.port)
try:
uvicorn.run(app, host=cfg.web.host, port=cfg.web.port)
finally:
if cfg.telegram.enabled:
send_status(cfg.telegram, "stop")
@main.command()
+11
View File
@@ -32,6 +32,17 @@ def send_telegram(cfg: TelegramConfig, message: str) -> bool:
return False
def send_status(cfg: TelegramConfig, event: str, details: str = "") -> bool:
"""Send bot status notification (start, stop, restart, error)."""
icons = {"start": "\u2705", "restart": "\U0001f504", "stop": "\u26d4",
"error": "\u26a0\ufe0f", "crash": "\U0001f4a5"}
icon = icons.get(event, "\u2139\ufe0f")
msg = f"{icon} <b>RemizovTrader — {event.upper()}</b>"
if details:
msg += f"\n{details}"
return send_telegram(cfg, msg)
def format_cycle_report(logs: list[str]) -> str:
"""Format cycle logs into a Telegram message."""
if not logs: