#!/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()