# 币安订单同步 ## 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 # 多账号时减少账号间隔(默认 90 秒,避免限频) python scripts/sync_binance_orders.py --delay-between-accounts 60 ``` ## 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. 限频说明 - 多账号时每个账号之间默认等待 90 秒,可用 `--delay-between-accounts` 调整 - 单账号内已降低并发(Semaphore 2)和请求间隔,减少触发 "Way too many requests" 封 IP - 若已被封,需等待提示时间后重试;建议 crontab 间隔不少于 3 小时 ## 5. 数据管理 管理后台「数据管理」-「币安订单/成交查询」从 DB 读取,不再调用币安 API。