feat: расширенное стартовое сообщение + команда /status в Telegram

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
anor
2026-03-09 03:10:36 +10:00
co-authored by Claude Opus 4.6
parent 9b556e0b55
commit 3e497b72d5
2 changed files with 121 additions and 7 deletions
+71
View File
@@ -48,6 +48,77 @@ def send_status(cfg: TelegramConfig, event: str, details: str = "") -> bool:
return send_telegram(cfg, msg)
def format_status_report(cfg, conn) -> str:
"""Format full status report for Telegram."""
from .state import get_all_assets, get_open_position
lines = ["\U0001f4ca <b>RemizovTrader — СТАТУС</b>", ""]
assets = get_all_assets(conn)
total_equity = 0.0
total_initial = 0.0
open_positions = []
for a in assets:
total_equity += a["equity"]
total_initial += cfg.initial_capital
pos = get_open_position(conn, a["ticker"])
if pos:
d = "LONG" if pos["direction"] == 1 else "SHORT"
open_positions.append(f" {a['ticker']}: {d} @ ${pos['entry_price']:,.2f}")
total_pnl = total_equity - total_initial
total_pct = (total_equity / total_initial - 1) * 100 if total_initial > 0 else 0
lines.append(f"<b>Капитал:</b> ${total_equity:,.2f} ({total_pct:+.1f}%)")
lines.append(f"<b>PnL:</b> ${total_pnl:+,.2f}")
lines.append("")
if open_positions:
lines.append(f"<b>Открытые позиции ({len(open_positions)}/{cfg.risk.max_open_positions}):</b>")
lines.extend(open_positions)
else:
lines.append(f"<b>Открытые позиции:</b> 0/{cfg.risk.max_open_positions}")
lines.append("")
lines.append("<b>Активы:</b>")
for a in assets:
wr = a["wins"] / a["trades_count"] * 100 if a["trades_count"] > 0 else 0
cb = " [CB]" if a["cb_active"] else ""
lines.append(f" {a['ticker']}: ${a['equity']:,.2f} | "
f"{a['trades_count']} сделок, WR {wr:.0f}%{cb}")
lines.append("")
lines.append(f"<b>Режим:</b> {cfg.mode} | <b>TF:</b> {cfg.timeframe}")
lines.append(f"<b>Риск:</b> {cfg.risk.per_trade*100:.0f}% | "
f"<b>Макс. позиция:</b> {cfg.risk.max_position_pct*100:.0f}%")
return "\n".join(lines)
def format_startup_details(cfg, conn) -> str:
"""Format startup message with key parameters."""
import platform
from .state import get_all_assets, get_open_position
assets = get_all_assets(conn)
open_count = sum(1 for a in assets if get_open_position(conn, a["ticker"]))
total_equity = sum(a["equity"] for a in assets)
total_trades = sum(a["trades_count"] for a in assets)
lines = [
f"Сервер: <code>{platform.node()}</code>",
f"Режим: {cfg.mode} | TF: {cfg.timeframe}",
f"Активов: {len(cfg.assets)} | Позиций: {open_count}/{cfg.risk.max_open_positions}",
f"Капитал: ${total_equity:,.2f} | Сделок: {total_trades}",
"",
f"Риск/сделка: {cfg.risk.per_trade*100:.0f}%",
f"Макс. позиция: {cfg.risk.max_position_pct*100:.0f}% от equity",
f"CB: ATR>{cfg.circuit_breaker.atr_ratio_on}x | DD>{cfg.circuit_breaker.max_drawdown*100:.0f}%",
]
return "\n".join(lines)
def format_cycle_report(logs: list[str]) -> str:
"""Format cycle logs into a Telegram message."""
if not logs: