# 后端服务 (Backend) 币安自动交易系统后端API服务 ## 功能 - 配置管理API(从数据库读取/更新配置) - 交易记录API - 统计分析API - 仪表板数据API ## 安装 ```bash cd backend pip install -r requirements.txt ``` ## 数据库配置 设置环境变量: ```bash export DB_HOST=localhost export DB_PORT=3306 export DB_USER=root export DB_PASSWORD=your_password export DB_NAME=auto_trade_sys ``` ## 初始化数据库 ```bash mysql -u root -p < database/init.sql ``` ## 运行 ```bash # 开发模式 uvicorn api.main:app --reload --host 0.0.0.0 --port 8000 # 生产模式 uvicorn api.main:app --host 0.0.0.0 --port 8000 --workers 4 ``` ## API文档 启动后访问: - Swagger UI: http://localhost:8000/docs - ReDoc: http://localhost:8000/redoc ## 目录结构 ``` backend/ ├── api/ # FastAPI应用 │ ├── main.py # 应用入口 │ ├── routes/ # 路由 │ └── models/ # API模型 ├── database/ # 数据库 │ ├── connection.py │ ├── models.py │ └── init.sql ├── config_manager.py # 配置管理器 └── requirements.txt ```