fix: улучшить форматирование /status в Telegram
Разделение на блоки: Портфель, Позиции, Статистика, Настройки. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -52,50 +52,59 @@ 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"
|
||||
pv = pos["pos_value"]
|
||||
stop = pos["stop_price"]
|
||||
open_positions.append(f" {a['ticker']}: {d} @ ${pos['entry_price']:,.2f} "
|
||||
f"(${pv:,.2f}, stop ${stop:,.2f})")
|
||||
|
||||
total_equity = sum(a["equity"] for a in assets)
|
||||
total_initial = cfg.initial_capital * len(assets) if assets else cfg.initial_capital
|
||||
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 = ["\U0001f4ca <b>RemizovTrader</b>"]
|
||||
lines.append("")
|
||||
|
||||
# --- Portfolio ---
|
||||
lines.append(f"\U0001f4b0 <b>Портфель</b>")
|
||||
lines.append(f" Капитал: <b>${total_equity:,.2f}</b> ({total_pct:+.1f}%)")
|
||||
lines.append(f" PnL: ${total_pnl:+,.2f}")
|
||||
lines.append("")
|
||||
|
||||
# --- Open positions ---
|
||||
open_positions = []
|
||||
for a in assets:
|
||||
pos = get_open_position(conn, a["ticker"])
|
||||
if pos:
|
||||
open_positions.append((a, pos))
|
||||
|
||||
if open_positions:
|
||||
lines.append(f"<b>Открытые позиции ({len(open_positions)}/{cfg.risk.max_open_positions}):</b>")
|
||||
lines.extend(open_positions)
|
||||
lines.append(f"\U0001f4c8 <b>Позиции</b> ({len(open_positions)}/{cfg.risk.max_open_positions})")
|
||||
for a, pos in open_positions:
|
||||
d = "\U0001f7e2 LONG" if pos["direction"] == 1 else "\U0001f534 SHORT"
|
||||
entry = pos["entry_price"]
|
||||
stop = pos["stop_price"]
|
||||
size = pos["pos_value"]
|
||||
risk_pct = abs(entry - stop) / entry * 100
|
||||
lines.append(f" {a['ticker']}: {d}")
|
||||
lines.append(f" Вход: ${entry:,.2f} | Стоп: ${stop:,.2f} ({risk_pct:.1f}%)")
|
||||
lines.append(f" Размер: ${size:,.2f}")
|
||||
else:
|
||||
lines.append(f"<b>Открытые позиции:</b> 0/{cfg.risk.max_open_positions}")
|
||||
|
||||
lines.append(f"\U0001f4c8 <b>Позиции:</b> нет")
|
||||
lines.append("")
|
||||
lines.append("<b>Активы:</b>")
|
||||
|
||||
# --- Stats per asset ---
|
||||
lines.append(f"\U0001f4ca <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}")
|
||||
|
||||
trades = a["trades_count"]
|
||||
wr = a["wins"] / trades * 100 if trades > 0 else 0
|
||||
cb = " \u26a0\ufe0f CB" if a["cb_active"] else ""
|
||||
lines.append(f" {a['ticker']}: {trades} сделок, WR {wr:.0f}%{cb}")
|
||||
lines.append("")
|
||||
lines.append(f"<b>Режим:</b> {cfg.mode} | <b>TF:</b> {cfg.timeframe}")
|
||||
leverage_str = f" | <b>Плечо:</b> {cfg.risk.leverage}x" if cfg.risk.leverage > 1 else ""
|
||||
lines.append(f"<b>Риск:</b> {cfg.risk.per_trade*100:.0f}% | "
|
||||
f"<b>Макс. позиция:</b> {cfg.risk.max_position_pct*100:.0f}%{leverage_str}")
|
||||
|
||||
# --- Settings ---
|
||||
lines.append(f"\u2699\ufe0f <b>Настройки</b>")
|
||||
lines.append(f" {cfg.mode} | {cfg.timeframe} | "
|
||||
f"риск {cfg.risk.per_trade*100:.0f}% | "
|
||||
f"макс {cfg.risk.max_position_pct*100:.0f}%")
|
||||
if cfg.risk.leverage > 1:
|
||||
lines.append(f" Плечо: {cfg.risk.leverage}x")
|
||||
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user