49 lines
1.2 KiB
Python
49 lines
1.2 KiB
Python
"""
|
||
FastAPI应用主入口
|
||
"""
|
||
from fastapi import FastAPI
|
||
from fastapi.middleware.cors import CORSMiddleware
|
||
from api.routes import config, trades, stats, dashboard
|
||
import os
|
||
|
||
app = FastAPI(
|
||
title="Auto Trade System API",
|
||
version="1.0.0",
|
||
description="币安自动交易系统API"
|
||
)
|
||
|
||
# CORS配置(允许React前端访问)
|
||
cors_origins = os.getenv('CORS_ORIGINS', 'http://localhost:3000,http://localhost:5173').split(',')
|
||
app.add_middleware(
|
||
CORSMiddleware,
|
||
allow_origins=cors_origins,
|
||
allow_credentials=True,
|
||
allow_methods=["*"],
|
||
allow_headers=["*"],
|
||
)
|
||
|
||
# 注册路由
|
||
app.include_router(config.router, prefix="/api/config", tags=["配置管理"])
|
||
app.include_router(trades.router, prefix="/api/trades", tags=["交易记录"])
|
||
app.include_router(stats.router, prefix="/api/stats", tags=["统计分析"])
|
||
app.include_router(dashboard.router, prefix="/api/dashboard", tags=["仪表板"])
|
||
|
||
|
||
@app.get("/")
|
||
async def root():
|
||
return {
|
||
"message": "Auto Trade System API",
|
||
"version": "1.0.0",
|
||
"docs": "/docs"
|
||
}
|
||
|
||
|
||
@app.get("/api/health")
|
||
async def health():
|
||
return {"status": "ok"}
|
||
|
||
|
||
if __name__ == "__main__":
|
||
import uvicorn
|
||
uvicorn.run(app, host="0.0.0.0", port=8000)
|