From fece3052b0e631add0928451b96d2eb0ef9aa97d Mon Sep 17 00:00:00 2001 From: anor Date: Tue, 10 Mar 2026 13:42:52 +1000 Subject: [PATCH] =?UTF-8?q?fix:=20=D1=83=D1=82=D1=80=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D0=B8=D0=B9=20=D0=BE=D1=82=D1=87=D1=91=D1=82=20=E2=80=94=20exc?= =?UTF-8?q?hange=20balance=20fallback=20=D0=B8=D0=B7=20snapshots,=20=D1=84?= =?UTF-8?q?=D0=B8=D0=BB=D1=8C=D1=82=D1=80=20portfolio=5Frebalance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Если API недоступен, берём последний exchange_balance из balance_snapshots (mark-to-market) вместо DB equity (не включает unrealized PnL) - Добавлен portfolio_rebalance в фильтр исключений Co-Authored-By: Claude Opus 4.6 --- src/remizov_trader/notify.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/remizov_trader/notify.py b/src/remizov_trader/notify.py index e671d51..576128b 100644 --- a/src/remizov_trader/notify.py +++ b/src/remizov_trader/notify.py @@ -228,10 +228,15 @@ def format_morning_report(cfg, conn) -> str: active_tickers = {a.ticker for a in cfg.assets} assets = [a for a in get_all_assets(conn) if a["ticker"] in active_tickers] - # Exchange balance + # Exchange balance (mark-to-market) exchange_balance = _get_exchange_balance(cfg) if exchange_balance is None: - exchange_balance = sum(a["equity"] for a in assets) + # Fallback: last known exchange balance from snapshots + snap = conn.execute( + "SELECT exchange_balance FROM balance_snapshots " + "WHERE exchange_balance IS NOT NULL ORDER BY id DESC LIMIT 1" + ).fetchone() + exchange_balance = snap["exchange_balance"] if snap else sum(a["equity"] for a in assets) total_initial = cfg.total_capital if cfg.total_capital > 0 else cfg.initial_capital * len(assets) total_pct = (exchange_balance / total_initial - 1) * 100 if total_initial > 0 else 0 @@ -272,7 +277,7 @@ def format_morning_report(cfg, conn) -> str: rows = conn.execute( "SELECT ticker, direction, entry_price, exit_price, exit_reason, pnl_net, pnl_pct " "FROM positions WHERE status='closed' AND exit_date >= ? " - "AND exit_reason NOT IN ('live_buy_failed', 'manual_reset', 'phantom_cleanup') " + "AND exit_reason NOT IN ('live_buy_failed', 'manual_reset', 'phantom_cleanup', 'portfolio_rebalance') " "ORDER BY id DESC", (since[:10],) ).fetchall()