# 币安订单同步 ## 1. 建表 首次使用需执行 SQL 建表: ```bash mysql -u user -p auto_trade_sys < backend/database/add_binance_sync_tables.sql ``` ## 2. 定时任务脚本 `sync_binance_orders.py` 从币安拉取各账号最近 6 小时的订单/成交,去重写入 DB。 ```bash # 同步所有有效账号 python scripts/sync_binance_orders.py # 指定账号 python scripts/sync_binance_orders.py -a 2 # 拉取最近 12 小时 python scripts/sync_binance_orders.py --hours 12 ``` ## 3. Crontab 配置示例 每 3 小时执行一次(与 6 小时拉取窗口重叠,便于去重): ```cron 0 */3 * * * cd /path/to/auto_trade_sys && /path/to/.venv/bin/python scripts/sync_binance_orders.py >> logs/sync_binance.log 2>&1 ``` 或每 6 小时: ```cron 0 */6 * * * cd /path/to/auto_trade_sys && /path/to/.venv/bin/python scripts/sync_binance_orders.py >> logs/sync_binance.log 2>&1 ``` ## 4. 数据管理 管理后台「数据管理」-「币安订单/成交查询」从 DB 读取,不再调用币安 API。