auto_trade_sys/scripts/SYNC_BINANCE_README.md
薇薇安 74c21bea9b feat(stats): Update admin dashboard stats to include recent 30-day account snapshots and enhance trade data source options
Modified the admin dashboard statistics to retrieve account snapshots from the last 30 days instead of just 1 day, ensuring more comprehensive data. Additionally, introduced a new data source option for trades, allowing users to select between 'binance' and 'local' records, with appropriate handling for each source. Updated the frontend components to reflect these changes and improve user experience in managing trade data.
2026-03-01 12:58:49 +08:00

1.7 KiB
Raw Blame History

币安订单同步

1. 建表

首次使用需执行 SQL 建表:

mysql -u user -p auto_trade_sys < backend/database/add_binance_sync_tables.sql

2. 定时任务脚本

sync_binance_orders.py 从币安拉取各账号最近 6 小时的订单/成交,去重写入 DB。

# 同步所有有效账号
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 小时的第 0 分钟执行一次(与 6 小时拉取窗口重叠,便于去重):

0 */3 * * * cd /path/to/auto_trade_sys && /path/to/.venv/bin/python scripts/sync_binance_orders.py >> logs/sync_binance.log 2>&1

延时说明:因定时任务为每 3 小时跑一次,页面或统计里看到的「币安成交」数据存在一定延时,最多可能滞后约 3 小时;如需最新可手动执行一次脚本。

或每 6 小时:

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。