From 2e36837e80e80e5b484840769aaced14f6488f25 Mon Sep 17 00:00:00 2001 From: anor Date: Mon, 9 Mar 2026 15:12:45 +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=20mark-to-market=20=D0=B1=D0=B0=D0=BB?= =?UTF-8?q?=D0=B0=D0=BD=D1=81=20(equity=20+=20unrealized=20PnL)=20=D0=BA?= =?UTF-8?q?=D0=B0=D0=BA=20=D0=BD=D0=B0=20=D0=B1=D0=B8=D1=80=D0=B6=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 --- src/remizov_trader/notify.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/remizov_trader/notify.py b/src/remizov_trader/notify.py index 4c074c5..c4f3425 100644 --- a/src/remizov_trader/notify.py +++ b/src/remizov_trader/notify.py @@ -74,28 +74,34 @@ def format_status_report(cfg, conn) -> str: 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 + + # Collect open positions and calculate unrealized PnL + open_positions = [] + total_unrealized = 0.0 + for a in assets: + pos = get_open_position(conn, a["ticker"]) + if pos: + cur_price = _get_current_price(cfg, a["ticker"]) + open_positions.append((a, pos, cur_price)) + if cur_price: + total_unrealized += pos["pos_size"] * (cur_price - pos["entry_price"]) * pos["direction"] + + total_balance = total_equity + total_unrealized + total_pnl = total_balance - total_initial + total_pct = (total_balance / total_initial - 1) * 100 if total_initial > 0 else 0 lines = ["\U0001f4ca RemizovTrader"] lines.append("") # --- Portfolio --- lines.append(f"\U0001f4b0 Портфель") - lines.append(f" Капитал: ${total_equity:,.2f} ({total_pct:+.1f}%)") + lines.append(f" Баланс: ${total_balance:,.2f} ({total_pct:+.1f}%)") lines.append(f" PnL: ${total_pnl:+,.2f}") lines.append("") - # --- Open positions with unrealized PnL --- - 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"\U0001f4c8 Позиции ({len(open_positions)}/{cfg.risk.max_open_positions})") - for a, pos in open_positions: + for a, pos, cur_price in open_positions: d = "\U0001f7e2 LONG" if pos["direction"] == 1 else "\U0001f534 SHORT" entry = pos["entry_price"] stop = pos["stop_price"] @@ -103,8 +109,6 @@ def format_status_report(cfg, conn) -> str: 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"]