From a861127afc726d58b50022311e837d4edecbf8e3 Mon Sep 17 00:00:00 2001 From: Marc Blatter Date: Sun, 5 Jul 2026 08:19:56 +0200 Subject: [PATCH] Dashboard V12: Fix Open Positions count - PROBLEM: Dashboard showed 0 positions (read from empty trades.json) - SOLUTION: Count locked coins instead (BTC/ETH/SOL/BNB/XRP) - RESULT: Now shows 5 active positions correctly - API: Added active_positions field to /api/state --- src/web_dashboard.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/web_dashboard.py b/src/web_dashboard.py index 5992b81..753b2d9 100644 --- a/src/web_dashboard.py +++ b/src/web_dashboard.py @@ -76,26 +76,34 @@ async def get_state(): portfolio_value += data['total'] * price usdt_free = balance.get('USDT', {}).get('free', 0) + + # Count active positions = locked coins (NOT trades.json) + active_positions = 0 + for asset in ['BTC', 'ETH', 'SOL', 'BNB', 'XRP']: + if asset in balance and balance[asset]['locked'] > 0.00001: + active_positions += 1 + trades = load_bot_state() return { 'balance': balance, 'portfolio_value': round(portfolio_value, 2), 'usdt_free': round(usdt_free, 2), + 'active_positions': active_positions, # ← NEW: Real count! 'current_trades': trades.get('current', {}), 'completed_trades': trades.get('completed', []), 'prices': prices, 'timestamp': datetime.now().isoformat() } except Exception as e: - return {'error': str(e), 'portfolio_value': 0, 'usdt_free': 0} + return {'error': str(e), 'portfolio_value': 0, 'usdt_free': 0, 'active_positions': 0} @app.get('/') async def root(): state = await get_state() portfolio_val = state.get('portfolio_value', 0) usdt_free = state.get('usdt_free', 0) - trades_count = len(state.get('current_trades', {})) + trades_count = state.get('active_positions', 0) # ← FIXED: Use real count! prices = state.get('prices', {}) html = f'''