1
系统开发/数据导入
xiaowu edited this page 2026-08-25 15:16:44 +08:00
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.

数据导入

运行环境

所有命令在小强容器(openclaw-1)里执行:

sudo docker exec -u node openclaw-1 bash -c 'cd /home/node/quanxiel/quantitative_data && /opt/quant-venv/bin/python xxx.py'

全量导入(首次/重建)

# 交互式或脚本里
from importer import full_import
full_import(start_date="2010-01-01", end_date="2025-12-31", import_financials=True)

注意:财务表很慢(数小时),可先跑行情、再单独补财务。

增量导入(日常)

# 每日行情(trade_cal/stock_basic/daily/daily_basic/adj_factor/index_daily)
/opt/quant-venv/bin/python incremental_import.py

# 每周一次,加财务表
/opt/quant-venv/bin/python incremental_import.py --weekly

# 只看计划不执行
/opt/quant-venv/bin/python incremental_import.py --dry-run

逻辑:查各表 MAX(trade_date),只拉「最后日期+1 → 昨天」。幂等(UPSERT)。

定时任务(群晖任务计划,推荐)

容器内无 systemd,crontab 重启会丢 → 用群晖「控制面板 → 任务计划」:

每天 18:30(A股数据 16~18 点齐):

docker exec -u node openclaw-1 bash -c 'cd /home/node/quanxiel && git pull --ff-only && cd quantitative_data && /opt/quant-venv/bin/python incremental_import.py >> incr.log 2>&1'

每周日 18:30(财务): 同上命令加 --weekly

断点续传工具

from importer import resume_daily_by_date, check_daily_progress, check_table_summary
check_daily_progress()          # 查看 daily 缺失日期
resume_daily_by_date()          # 自动补缺失日期
check_table_summary()           # 各表行数统计

Tushare 接口

  • 实测接口清单 + 示例代码:tushare_api_reference.md
  • 改代码前自检:/opt/quant-venv/bin/python tushare_api_check.py
  • ⚠️ 普通接口按 trade_date 全市场需 2000 积分;财务 vip 接口需 5000 积分(当前账号 5120 够)