From 6c0c6eb016aa2ac4195808490831ad3640b80b44 Mon Sep 17 00:00:00 2001 From: anor Date: Mon, 9 Mar 2026 14:21:14 +1000 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=BF=D0=BE=D0=BA=D0=B0=D0=B7=D1=8B?= =?UTF-8?q?=D0=B2=D0=B0=D1=82=D1=8C=20=D1=82=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE?= =?UTF-8?q?=20=D0=B0=D0=BA=D1=82=D0=B8=D0=B2=D0=BD=D1=8B=D0=B5=20assets=20?= =?UTF-8?q?+=20unrealized=20PnL=20=D0=BF=D0=BE=20=D0=BF=D0=BE=D0=B7=D0=B8?= =?UTF-8?q?=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Капитал считается только по assets из текущего конфига (не все в БД) 2. Позиция показывает текущий PnL с иконкой и текущей ценой Co-Authored-By: Claude Opus 4.6 --- src/remizov_trader/notify.py | 45 +++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/src/remizov_trader/notify.py b/src/remizov_trader/notify.py index f82603c..4c074c5 100644 --- a/src/remizov_trader/notify.py +++ b/src/remizov_trader/notify.py @@ -48,11 +48,30 @@ def send_status(cfg: TelegramConfig, event: str, details: str = "") -> bool: return send_telegram(cfg, msg) +def _get_current_price(cfg, ticker): + """Fetch current price for ticker via exchange.""" + try: + # Find symbol from config + for a in cfg.assets: + if a.ticker == ticker: + from .core.signals import fetch_prices_ccxt + prices, _ = fetch_prices_ccxt(a.symbol, "4h", "1d", cfg.exchange) + if prices is not None and len(prices) > 0: + return float(prices[-1]) + return None + except Exception: + return None + + def format_status_report(cfg, conn) -> str: """Format full status report for Telegram.""" - from .state import get_all_assets, get_open_position + from .state import get_asset, get_open_position + + # Only show assets from current config + active_tickers = {a.ticker for a in cfg.assets} + assets = [get_asset(conn, t) for t in active_tickers] + assets = [a for a in assets if a is not None] - assets = get_all_assets(conn) 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 @@ -67,7 +86,7 @@ def format_status_report(cfg, conn) -> str: lines.append(f" PnL: ${total_pnl:+,.2f}") lines.append("") - # --- Open positions --- + # --- Open positions with unrealized PnL --- open_positions = [] for a in assets: pos = get_open_position(conn, a["ticker"]) @@ -81,10 +100,22 @@ def format_status_report(cfg, conn) -> str: entry = pos["entry_price"] stop = pos["stop_price"] size = pos["pos_value"] + pos_size = pos["pos_size"] risk_pct = abs(entry - stop) / entry * 100 + + # Fetch current price for unrealized PnL + cur_price = _get_current_price(cfg, a["ticker"]) + if cur_price: + upnl = pos_size * (cur_price - entry) * pos["direction"] + upnl_pct = (cur_price / entry - 1) * 100 * pos["direction"] + pnl_icon = "\U0001f7e2" if upnl >= 0 else "\U0001f534" + pnl_str = f"\n {pnl_icon} PnL: ${upnl:+,.2f} ({upnl_pct:+.1f}%) @ ${cur_price:,.2f}" + else: + pnl_str = "" + lines.append(f" {a['ticker']}: {d}") lines.append(f" Вход: ${entry:,.2f} | Стоп: ${stop:,.2f} ({risk_pct:.1f}%)") - lines.append(f" Размер: ${size:,.2f}") + lines.append(f" Размер: ${size:,.2f}{pnl_str}") else: lines.append(f"\U0001f4c8 Позиции: нет") lines.append("") @@ -112,9 +143,11 @@ def format_status_report(cfg, conn) -> str: def format_startup_details(cfg, conn) -> str: """Format startup message with key parameters.""" import platform - from .state import get_all_assets, get_open_position + from .state import get_asset, get_open_position - assets = get_all_assets(conn) + active_tickers = {a.ticker for a in cfg.assets} + assets = [get_asset(conn, t) for t in active_tickers] + assets = [a for a in assets if a is not None] 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)