diff --git a/src/web_dashboard.py b/src/web_dashboard.py index 01d3e93..6f5a766 100644 --- a/src/web_dashboard.py +++ b/src/web_dashboard.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +"""Trading Bot Dashboard v0.32 - with Collapsible Holdings, USD values, Mobile-optimized""" from fastapi import FastAPI from fastapi.responses import HTMLResponse from binance.client import Client @@ -18,8 +19,7 @@ DB = '/home/marc/bot-deploy/pnl_charts.db' def init_db(): c = sqlite3.connect(DB).cursor() - c.execute("""CREATE TABLE IF NOT EXISTS history ( - ts INTEGER PRIMARY KEY, pv REAL, pu REAL, pp REAL, uf REAL, ap INTEGER)""") + c.execute("""CREATE TABLE IF NOT EXISTS history (ts INTEGER PRIMARY KEY, pv REAL, pu REAL, pp REAL, uf REAL, ap INTEGER)""") sqlite3.connect(DB).commit() init_db() @@ -39,8 +39,7 @@ async def state(): try: t = binance.get_ticker(symbol=p) prices[p.replace('USDT', '')] = float(t['lastPrice']) - except: - pass + except: pass 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) @@ -51,17 +50,14 @@ async def state(): try: with open('/home/marc/bot-deploy/active_trades.json') as f: ap = json.load(f).get('count', 0) - except: - pass + except: pass conn = sqlite3.connect(DB) - conn.execute("INSERT OR REPLACE INTO history VALUES (?, ?, ?, ?, ?, ?)", - (int(time.time()), pv, pu, pp, uf, ap)) + conn.execute("INSERT OR REPLACE INTO history VALUES (?, ?, ?, ?, ?, ?)", (int(time.time()), pv, pu, pp, uf, ap)) conn.commit() conn.close() - return {'portfolio_value': round(pv, 2), 'pnl_usdt': round(pu, 2), 'pnl_pct': round(pp, 2), - 'usdt_free': round(uf, 2), 'active_positions': ap, 'balance': bal, 'prices': prices} + return {'portfolio_value': round(pv, 2), 'pnl_usdt': round(pu, 2), 'pnl_pct': round(pp, 2), 'usdt_free': round(uf, 2), 'active_positions': ap, 'balance': bal, 'prices': prices} except Exception as e: return {'error': str(e)} @@ -87,7 +83,228 @@ async def history(hours: int = 24): @app.get('/') async def dashboard(): - return HTMLResponse("""Trading Bot v0.32

🤖 Trading Bot v0.32

P&L Analytics

● LOADING
Portfolio
-
P&L
-
-
USDT
-
Trades
-

Holdings

📈 P&L Performance (Live)
Current
-
-
Min
-
-
Max
-
-
Avg
-
-
""") + html = """ + + + + +Trading Bot v0.32 + + + + +
+ +
+

🤖 Trading Bot v0.32

P&L Analytics

+
● LOADING
+
+ +
+ + +
+ +
+
+
Portfolio
-
+
P&L
-
-
+
USDT
-
+
Trades
-
+
+ +
+

Holdings

+ +
+
+
+ +
+
+
📈 P&L Performance (Live)
+
+ + + +
+ +
+
+
Current
+- +- +
+
+
Min
+- +- +
+
+
Max
+- +- +
+
+
Avg
+- +- +
+
+
+
+ +
+ + + +""" + return HTMLResponse(content=html) if __name__ == '__main__': import uvicorn