Files
sanguo_vnpy_v2/scripts/data_platform/probe_etf_v2.py
T
claude_dev 774170ec05 feat(data): 数据源融合 P0 补全 + 每日增量脚本
采集层(多源各下):
- baostock: 日线全字段全量(baostock_daily_fullmarket) + 15min全市场 + 静态(基础/复权/分红/季频/三表) + 成份股
- akshare: 静态(估值/龙虎榜/大宗/融资融券/北向/指数成分/行业/股本/解禁/业绩预告)
- xtdata(miniQMT): build_daily_from_xtdata + daily_update_xtdata

数据补全 P0:
- ETF全市场: universe 扩展 沪深A股∪ETF∪基金(7414), dividend_type='front' 前复权
- 历史成份股(治幸存者偏差): index_const_hist_download 深证/国证 adjust_cni 4指数 + 中证1000/2000快照 + 新浪交叉校验
- 退市K线: baostock_delisted_download + import_delisted_to_db(实证 Day1 fetch_all_stocks 已含退市)

灌库:
- import_baostock_to_db: daily_baostock_full(5537股/1826万行,18字段)+ bs_index_constituent + bs_adjust_factor
- INSERT OR REPLACE 幂等, WAL+busy_timeout, dbbardata 不碰

每日增量 #7(用户决策A: VPS直跑):
- daily_update_static: login探针防黑名单graceful skip + LOOKBACK7 + query_stock_basic含退市 + INSERT OR REPLACE + QUERY_COUNT守48000/天

设计文档: spec(13节三层融合) + P0 plan + 数据gap设计
2026-07-22 10:34:22 +08:00

58 lines
2.3 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""ETF 探针 v2: 先 download 再读,对比 dividend_type,确认 ETF 在 sector 中。"""
import sys
from xtquant import xtdata as xd
def main():
etf = xd.get_stock_list_in_sector("沪深ETF") or []
fund = xd.get_stock_list_in_sector("沪深基金") or []
a = xd.get_stock_list_in_sector("沪深A股") or []
u = list(set(a + etf + fund))
print(f"A={len(a)} ETF={len(etf)} fund={len(fund)} union={len(u)}")
# 1) 检查目标 samples 是否在 universe
for sym in ("510300.SH", "513050.SH", "159919.SZ"):
print(f" {sym} in A={sym in a} in ETF={sym in etf} in fund={sym in fund}")
# 2) 重叠分析: ETF 与 fund 是否相同
overlap = set(etf) & set(fund)
only_etf = set(etf) - set(fund)
only_fund = set(fund) - set(etf)
print(f"overlap(ETF&fund)={len(overlap)} only_etf={len(only_etf)} only_fund={len(only_fund)}")
if only_etf:
print(f" only_etf sample: {list(only_etf)[:5]}")
if only_fund:
print(f" only_fund sample: {list(only_fund)[:5]}")
# 3) 先 download 再读
samples = ["510300.SH", "513050.SH", "159919.SZ"]
print(f"\n=== download_history_data(1d, 20240101~20260721) ===")
for sym in samples:
try:
n = xd.download_history_data(sym, "1d", "20240101", "20260721")
print(f" {sym} download returned: {n}")
except Exception as e:
print(f" {sym} download err: {e}")
# 4) 读两种 dividend_type
for dt in ("front", "none"):
print(f"\n=== get_market_data_ex dividend_type={dt} ===")
r = xd.get_market_data_ex([], samples, period="1d",
start_time="20240101", end_time="20260721",
dividend_type=dt)
for sym in samples:
df = r.get(sym) if r else None
bars = 0 if df is None else len(df)
tail_close = None if df is None or not len(df) else float(df["close"].iloc[-1])
head_date = None if df is None or not len(df) else str(df.index[0])[:8]
tail_date = None if df is None or not len(df) else str(df.index[-1])[:8]
print(f" {sym}: bars={bars} date=[{head_date}~{tail_date}] tail_close={tail_close}")
sys.stdout.flush()
if __name__ == "__main__":
main()