From 361a59924262b6514f158c8c397eaac97a368b6c Mon Sep 17 00:00:00 2001 From: Marc Blatter Date: Fri, 17 Jul 2026 13:11:23 +0200 Subject: [PATCH] Fix: P&L reads dynamically from DB, not hardcoded 0% --- src/web_dashboard.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/web_dashboard.py b/src/web_dashboard.py index c516e05..8bac185 100644 --- a/src/web_dashboard.py +++ b/src/web_dashboard.py @@ -1,10 +1,11 @@ #!/usr/bin/env python3 """Trading Bot Dashboard v0.4 (Dynamic Positioning) - Auto-load 1-Day chart on page load""" +import sqlite3 from fastapi import FastAPI from fastapi.responses import HTMLResponse from binance.client import Client from datetime import datetime -import json, os, time, sqlite3 +import json, os, time app = FastAPI() @@ -43,8 +44,17 @@ async def state(): pv = sum(bal.get(a, {}).get('total', 0) * prices.get(a, 0) for a in ['BTC', 'ETH', 'SOL', 'BNB', 'XRP', 'USDT']) uf = bal.get('USDT', {}).get('free', 0) - pu = 0.0 # Reset: Baseline now at current portfolio - pp = 0.0 # ✅ Reset P&L % to baseline (0%) + # Get latest P&L from database + try: + conn = sqlite3.connect('/home/marc/bot-deploy/pnl_charts.db') + row = conn.execute('SELECT pu, pp FROM history ORDER BY ts DESC LIMIT 1').fetchone() + conn.close() + if row: + pu, pp = row[0], row[1] + else: + pu, pp = 0.0, 0.0 + except: + pu, pp = 0.0, 0.0 ap = 0 try: