BUGFIX: P&L calculation now properly included in get_state() → Dashboard shows real profit/loss

This commit is contained in:
Marc Blatter 2026-07-07 09:04:44 +02:00
parent b9bd1b2e96
commit 6dec4231d0
1 changed files with 11 additions and 0 deletions

View File

@ -76,6 +76,13 @@ async def get_state():
portfolio_value += data['total'] * price
usdt_free = balance.get('USDT', {}).get('free', 0)
# P&L CALCULATION
initial_capital = 137.79
pnl_usdt = portfolio_value - initial_capital
pnl_pct = (pnl_usdt / initial_capital * 100) if initial_capital > 0 else 0
pnl_status = "🟢 PROFIT" if pnl_usdt > 0.01 else ("🔴 LOSS" if pnl_usdt < -0.01 else "⚪ BREAK")
pnl_color = "accent" if pnl_usdt > 0.01 else ("negative" if pnl_usdt < -0.01 else "neutral")
# Count active positions = locked coins (NOT trades.json)
active_positions = 0
@ -91,6 +98,10 @@ async def get_state():
'usdt_free': round(usdt_free, 2),
'active_positions': active_positions, # ← NEW: Real count!
'current_trades': trades.get('current', {}),
'pnl_usdt': round(pnl_usdt, 2),
'pnl_pct': round(pnl_pct, 2),
'pnl_status': pnl_status,
'pnl_color': pnl_color,
'completed_trades': trades.get('completed', []),
'prices': prices,
'timestamp': datetime.now().isoformat()