fix: утренний отчёт — exchange balance fallback из snapshots, фильтр portfolio_rebalance
- Если API недоступен, берём последний exchange_balance из balance_snapshots (mark-to-market) вместо DB equity (не включает unrealized PnL) - Добавлен portfolio_rebalance в фильтр исключений Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user