- runner.py: grid search по параметрам (shift, stop_mult, K, lr, cooldown) для 20 монет - dashboard.py + dashboard.html: real-time web-дашборд (FastAPI + SSE + Chart.js) - динамические asset filter pills, asset summary, sortable table - evaluate.py: бэктест с 4 фиксами trading best practices: - стопы по OHLCV low/high вместо close (intra-bar stop-outs) - exit at stop_price с учётом gap-down (fill at open if worse) - Sharpe: sqrt(365) вместо sqrt(252), PnL распределён по дням удержания - out-of-sample holdout split (60% val / 40% OOS от test периода) - dataset.py: добавлены 14 новых Bybit USDC пар (XRP, AVAX, LINK, UNI, ATOM, LTC, NEAR, APT, FIL, ARB, OP, SUI, INJ, SEI) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
117 lines
3.2 KiB
Python
117 lines
3.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Real-time dashboard for autoresearch experiments.
|
|
|
|
Usage:
|
|
python dashboard.py # start on port 8050
|
|
python dashboard.py --port 8080 # custom port
|
|
"""
|
|
import argparse
|
|
import asyncio
|
|
import json
|
|
from datetime import datetime
|
|
from pathlib import Path
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.responses import HTMLResponse, StreamingResponse
|
|
import uvicorn
|
|
|
|
ROOT = Path(__file__).parent
|
|
RUNS_DIR = ROOT / "runs"
|
|
BEST_DIR = ROOT / "best"
|
|
STATUS_FILE = ROOT / "status.json"
|
|
HTML_FILE = ROOT / "dashboard.html"
|
|
|
|
app = FastAPI(title="Autoresearch Dashboard")
|
|
|
|
|
|
@app.get("/", response_class=HTMLResponse)
|
|
async def index():
|
|
"""Serve the dashboard HTML."""
|
|
if HTML_FILE.exists():
|
|
return HTML_FILE.read_text()
|
|
return "<h1>dashboard.html not found</h1>"
|
|
|
|
|
|
@app.get("/api/status")
|
|
async def api_status():
|
|
"""Current runner status."""
|
|
if STATUS_FILE.exists():
|
|
try:
|
|
return json.loads(STATUS_FILE.read_text())
|
|
except json.JSONDecodeError:
|
|
pass
|
|
return {"state": "idle", "run_number": 0, "total_planned": 0}
|
|
|
|
|
|
@app.get("/api/runs")
|
|
async def api_runs():
|
|
"""All runs sorted by timestamp."""
|
|
if not RUNS_DIR.exists():
|
|
return []
|
|
runs = []
|
|
for f in sorted(RUNS_DIR.glob("run_*.json")):
|
|
try:
|
|
data = json.loads(f.read_text())
|
|
data["_file"] = f.name
|
|
runs.append(data)
|
|
except (json.JSONDecodeError, OSError):
|
|
continue
|
|
return runs
|
|
|
|
|
|
@app.get("/api/best")
|
|
async def api_best():
|
|
"""Current best result."""
|
|
best_file = BEST_DIR / "best_sharpe.json"
|
|
if best_file.exists():
|
|
try:
|
|
return json.loads(best_file.read_text())
|
|
except json.JSONDecodeError:
|
|
pass
|
|
return None
|
|
|
|
|
|
@app.get("/api/events")
|
|
async def sse_events():
|
|
"""Server-Sent Events stream for real-time updates."""
|
|
async def event_stream():
|
|
last_count = 0
|
|
last_status = ""
|
|
while True:
|
|
# Check for new runs
|
|
count = len(list(RUNS_DIR.glob("run_*.json"))) if RUNS_DIR.exists() else 0
|
|
status_data = ""
|
|
if STATUS_FILE.exists():
|
|
try:
|
|
status_data = STATUS_FILE.read_text()
|
|
except OSError:
|
|
pass
|
|
|
|
if count != last_count or status_data != last_status:
|
|
last_count = count
|
|
last_status = status_data
|
|
event = json.dumps({
|
|
"runs_count": count,
|
|
"status": json.loads(status_data) if status_data else None,
|
|
"timestamp": datetime.now().isoformat(),
|
|
})
|
|
yield f"data: {event}\n\n"
|
|
|
|
await asyncio.sleep(2)
|
|
|
|
return StreamingResponse(event_stream(), media_type="text/event-stream")
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--port", type=int, default=8050)
|
|
parser.add_argument("--host", default="0.0.0.0")
|
|
args = parser.parse_args()
|
|
|
|
print(f"Dashboard: http://localhost:{args.port}")
|
|
uvicorn.run(app, host=args.host, port=args.port, log_level="warning")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|