Fix: P&L reads dynamically from DB, not hardcoded 0%

This commit is contained in:
Marc Blatter 2026-07-17 13:11:23 +02:00
parent 23f2e0ddce
commit 361a599242
1 changed files with 13 additions and 3 deletions

View File

@ -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: