From 6dec4231d078bc535c9d5cb9dc7c0bd3767088c8 Mon Sep 17 00:00:00 2001 From: Marc Blatter Date: Tue, 7 Jul 2026 09:04:44 +0200 Subject: [PATCH] =?UTF-8?q?BUGFIX:=20P&L=20calculation=20now=20properly=20?= =?UTF-8?q?included=20in=20get=5Fstate()=20=E2=86=92=20Dashboard=20shows?= =?UTF-8?q?=20real=20profit/loss?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web_dashboard.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/web_dashboard.py b/web_dashboard.py index 2ebe962..163e94a 100644 --- a/web_dashboard.py +++ b/web_dashboard.py @@ -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()