auto_trade_sys/scripts/SYNC_BINANCE_README.md
薇薇安 3b0526f392 feat(data_management): 增强交易数据统计与推算功能
在后端 API 中新增按小时和星期的交易统计功能,优化 `_compute_binance_stats` 函数以支持更细致的统计分析。同时,新增 `_enrich_trades_with_derived` 函数,补充交易记录的推算字段,包括入场价、交易小时和星期,提升策略分析的便利性。前端 `DataManagement` 组件更新,展示按小时和星期的统计信息,增强用户对交易数据的可视化理解。
2026-02-22 11:16:33 +08:00

52 lines
1.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 币安订单同步
## 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。