feat: баланс в сделках / свободно в cycle report Telegram

- format_cycle_report теперь принимает cfg и показывает:
  💰 $115.96  →  в сделках $72.30 | свободно $43.66
- Берёт реальный баланс с биржи (free USDC + mark-to-market позиций)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
anor
2026-03-10 19:08:00 +10:00
co-authored by Claude Opus 4.6
parent 122c674259
commit 295dbc043d
2 changed files with 20 additions and 2 deletions
+1 -1
View File
@@ -219,7 +219,7 @@ def daemon():
click.echo(f" {msg}")
if cfg.telegram.enabled:
report = format_cycle_report(logs)
report = format_cycle_report(logs, cfg)
send_telegram(cfg.telegram, report)
scheduler = BackgroundScheduler()
+19 -1
View File
@@ -593,7 +593,7 @@ def format_morning_report_with_ai(cfg, conn) -> tuple[str, str | None]:
return report, ai_text
def format_cycle_report(logs: list[str]) -> str:
def format_cycle_report(logs: list[str], cfg=None) -> str:
"""Format cycle logs into a clean Telegram message.
Groups by importance: signals/closes first, then holdings,
@@ -688,4 +688,22 @@ def format_cycle_report(logs: list[str]) -> str:
dot = " \u00b7 "
lines.append(f"<i>\u041f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u044b: {dot.join(parts)}</i>")
# Balance line: in positions / free
if cfg is not None:
try:
from .core.spot import SpotExecutor
spot = SpotExecutor(cfg.exchange, leverage=cfg.risk.leverage)
spot._ensure_markets()
b = spot.exchange.fetch_balance()
free_usdc = float(b.get("USDC", {}).get("free", 0) or 0)
total_balance = _get_exchange_balance(cfg)
if total_balance is not None:
in_positions = total_balance - free_usdc
lines.append("")
lines.append(f"\U0001f4b0 ${total_balance:,.2f}"
f" \u2192 \u0432 \u0441\u0434\u0435\u043b\u043a\u0430\u0445 ${in_positions:,.2f}"
f" | \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e ${free_usdc:,.2f}")
except Exception:
pass
return "\n".join(lines)