auto_trade_sys/backend
薇薇安 1446bf852b feat(config): Introduce layered profit locking mechanism and manual trading adjustments
Added new configurations for a layered profit locking system, allowing for gradual profit protection at specified thresholds. Introduced manual trading options, including reduced and blocked symbol lists, to enhance trading strategy flexibility. Updated relevant backend and frontend components to reflect these changes, improving risk management and user control over trading activities.
2026-03-09 14:51:08 +08:00
..
api feat(config): Introduce layered profit locking mechanism and manual trading adjustments 2026-03-09 14:51:08 +08:00
database feat(stats): 增加全局交易统计功能 2026-02-27 13:29:49 +08:00
security 增加多账号的支持体系 2026-01-20 15:55:34 +08:00
check_db_symbols.py 1 2026-02-08 09:27:49 +08:00
check_dependencies.sh 1 2026-02-17 23:13:49 +08:00
config_manager.py feat(config): Introduce layered profit locking mechanism and manual trading adjustments 2026-03-09 14:51:08 +08:00
ENV_SETUP.md a 2026-01-14 10:57:14 +08:00
fix_config_category.sql a 2026-01-14 14:17:25 +08:00
init_config.py a 2026-01-14 19:17:22 +08:00
market_overview.py feat(strategy_overview): 添加策略执行概览功能以优化策略分析 2026-02-25 09:39:33 +08:00
NGINX_CONFIG.md a 2026-01-14 13:25:29 +08:00
README.md a 2026-01-14 10:57:14 +08:00
requirements.txt 增加多账号的支持体系 2026-01-20 15:55:34 +08:00
restart_recommendations.sh feat(recommendations): 添加推荐服务管理API与前端控制功能 2026-02-23 18:02:53 +08:00
restart.sh 1 2026-02-08 20:33:37 +08:00
spot_scanner.py feat(recommendations): 添加现货推荐扫描与API支持 2026-02-25 08:40:52 +08:00
start_dev.sh a 2026-01-14 10:57:14 +08:00
start_recommendations.sh fix(start_recommendations): 优化虚拟环境激活逻辑 2026-02-23 19:24:33 +08:00
start.sh a 2026-01-14 10:57:14 +08:00
stop_recommendations.sh feat(recommendations): 添加推荐服务管理API与前端控制功能 2026-02-23 18:02:53 +08:00
stop.sh a 2026-02-03 09:49:25 +08:00
sync_global_config_defaults.py feat(config): 添加4H趋势过滤配置以优化交易策略 2026-02-22 22:51:36 +08:00
TROUBLESHOOTING.md 1 2026-02-17 23:13:49 +08:00
查看同步日志.sh feat(binance_client): 优化 listenKey 创建与延长逻辑,支持 WebSocket API 2026-02-17 23:28:28 +08:00
检查内存问题.sh feat(kline_stream, diagnostics): 增强 K线缓存管理与系统负载诊断功能 2026-02-19 00:06:23 +08:00
诊断负载.sh feat(kline_stream, diagnostics): 增强 K线缓存管理与系统负载诊断功能 2026-02-19 00:06:23 +08:00

后端服务 (Backend)

币安自动交易系统后端API服务

功能

  • 配置管理API从数据库读取/更新配置)
  • 交易记录API
  • 统计分析API
  • 仪表板数据API

安装

cd backend
pip install -r requirements.txt

数据库配置

方式1使用.env文件推荐

backend/ 目录或项目根目录创建 .env 文件:

# 复制示例文件
cp .env.example .env

# 编辑.env文件
DB_HOST=localhost
DB_PORT=3306
DB_USER=root
DB_PASSWORD=your_password
DB_NAME=auto_trade_sys
CORS_ORIGINS=http://localhost:3000,http://localhost:5173

方式2使用环境变量

export DB_HOST=localhost
export DB_PORT=3306
export DB_USER=root
export DB_PASSWORD=your_password
export DB_NAME=auto_trade_sys
export CORS_ORIGINS=http://localhost:3000,http://localhost:5173

注意:系统会优先从 .env 文件读取配置,然后才是环境变量。

初始化数据库

mysql -u root -p < database/init.sql

运行

开发模式(自动重载)

代码修改后会自动重启,无需手动重启:

# 方式1使用开发启动脚本
./start_dev.sh

# 方式2直接运行
uvicorn api.main:app --reload --host 0.0.0.0 --port 8001

生产模式

代码修改后需要手动重启:

# 方式1使用生产启动脚本
./start.sh

# 方式2使用重启脚本
./restart.sh

# 方式3手动重启
# 1. 查找进程: ps aux | grep uvicorn
# 2. 停止服务: kill <PID>
# 3. 启动服务: ./start.sh

注意

  • 开发模式使用 --reload 参数,代码修改后自动重启
  • 生产模式不使用 --reload,需要手动重启才能生效
  • 重启脚本 restart.sh 会自动查找并重启服务

API文档

启动后访问:

目录结构

backend/
├── api/              # FastAPI应用
│   ├── main.py      # 应用入口
│   ├── routes/      # 路由
│   └── models/      # API模型
├── database/        # 数据库
│   ├── connection.py
│   ├── models.py
│   └── init.sql
├── config_manager.py # 配置管理器
└── requirements.txt