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 = """