From a6a832a4e7202a3caf6e2b86771b227c1b101e3e Mon Sep 17 00:00:00 2001 From: Marc Blatter Date: Sat, 4 Jul 2026 16:45:01 +0200 Subject: [PATCH] Bot auto-update: src/web_dashboard.py --- src/web_dashboard.py | 247 +++++++++++++++++++++++++++---------------- 1 file changed, 153 insertions(+), 94 deletions(-) diff --git a/src/web_dashboard.py b/src/web_dashboard.py index d8cff00..8c0a9cb 100644 --- a/src/web_dashboard.py +++ b/src/web_dashboard.py @@ -1,107 +1,166 @@ #!/usr/bin/env python3 from fastapi import FastAPI -from fastapi.responses import HTMLResponse -from datetime import datetime -import asyncio +from fastapi.responses import HTMLResponse, FileResponse +from fastapi.staticfiles import StaticFiles +from fastapi.middleware.cors import CORSMiddleware +import json app = FastAPI() -trading_state = { - "current_trades": {}, - "completed_trades": [], - "balance": {"USDT": 0.0}, - "trades_today": 0, - "daily_pnl": 0.0, - "wins_today": 0, - "last_update": datetime.now().isoformat() +app.add_middleware( + CORSMiddleware, + allow_origins=['*'], + allow_credentials=True, + allow_methods=['*'], + allow_headers=['*'], +) + +# Global state +state = { + 'current_trades': {}, + 'completed_trades': [], + 'balance': {'USDT': {'free': 0.0}}, + 'trades_today': 0, + 'daily_pnl': 0.0, + 'wins_today': 0, + 'losses_today': 0, + 'last_update': '', } -@app.post("/api/update") -async def update(data: dict): - global trading_state - trading_state = data - trading_state["last_update"] = datetime.now().isoformat() - return {"status": "ok"} +@app.post('/api/update') +async def update_state(data: dict): + global state + state.update(data) + return {'status': 'ok'} -@app.get("/api/state") +@app.get('/api/state') async def get_state(): - return trading_state + return state -@app.get("/") +@app.get('/', response_class=HTMLResponse) async def dashboard(): - html = """Bot
-

Trading Bot Dashboard

-
-
LIQUID USDT
$0.00
-
TRADES TODAY
0
-
DAILY P&L
$0.00
-
WIN RATE
0%
-
OPEN
0
-
-

Open Trades

No open trades
-

Closed Trades

No closed trades
-
Last update: -
-
- """; - return HTMLResponse(html) + html = ''' + + +Bot Dashboard + + + +

Trading Bot Dashboard

+
+
Liquid USDT
bash.00
+
Trades Today
0
+
Daily P&L
bash.00
+
Win Rate
0%
+
Open Positions
0
+
-if __name__ == "__main__": +
+

Open Trades

+
No open trades
+
+ +
+

Closed Trades

+
No closed trades
+
+ + + + + +''' + return html + +if __name__ == '__main__': import uvicorn - uvicorn.run(app, host="0.0.0.0", port=7000) + uvicorn.run(app, host='0.0.0.0', port=7000)