feat(data): xt_eod 扩展补全北交所 920xxx 日线(exc_of+universe+import容错,复用×100 normalize)
- exc_of: 920 -> BJSE (3 位前缀优先于 2 位 SSE/SZSE 判断, 防 sym[:2]='92' 落 SZSE) - universe: 沪深ETF/基金 ∪ 北交所920xxx (从 constituent_unified 932000 取, baostock 不覆盖) - import xtquant 容错 (mac xd=None 可单测 exc_of, main() 开头 return 2) - --full-bj: 北交所 backfill start=20240101 (默认 LOOKBACK=30 与 ETF 同窗) - 复用 normalize_daily_dt + ×100 volume 口径, 不动已有 ETF 写入路径 Tests: tests/data_platform/test_xt_eod_bj.py 14 cases RED -> GREEN (3 位前缀 critical + ETF/沪深/深市 覆盖)
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""TDD for xt_eod.exc_of — 北交所 920xxx exchange 判定扩展。
|
||||
|
||||
背景:
|
||||
中证2000(932000)有 39 只北交所成份股全 920xxx, baostock 完全不覆盖,
|
||||
由 xt_eod.py 用 xtdata 补全 (主力 ETF/基金管线之外的扩展)。
|
||||
920 是 3 位前缀, 必须在原 2 位 SSE/SZSE 判断前优先识别, 否则 sym[:2]="92"
|
||||
会被错误归到 SZSE。
|
||||
|
||||
exc_of 是纯函数, 不依赖 xtquant, mac 无 xtquant 也可单测 (xt_eod.py 顶层
|
||||
xtquant import 失败时降级 xd=None, 仅 main() 受影响)。
|
||||
"""
|
||||
import pytest
|
||||
|
||||
from scripts.data_platform.xt_eod import exc_of
|
||||
|
||||
|
||||
@pytest.mark.parametrize("sym,expected", [
|
||||
# 北交所 920xxx (3 位前缀优先, 任务核心)
|
||||
("920001", "BJSE"),
|
||||
("920002", "BJSE"),
|
||||
("920999", "BJSE"),
|
||||
# 沪市 ETF/基金 (51/56/58/50)
|
||||
("510300", "SSE"),
|
||||
("588000", "SSE"),
|
||||
("561000", "SSE"),
|
||||
("501000", "SSE"),
|
||||
# 沪市个股 (60/68)
|
||||
("600519", "SSE"),
|
||||
("688981", "SSE"),
|
||||
# 深市个股/基金 (00/15/16/30 等)
|
||||
("000001", "SZSE"),
|
||||
("002001", "SZSE"),
|
||||
("300750", "SZSE"),
|
||||
("159915", "SZSE"),
|
||||
])
|
||||
def test_exc_of(sym, expected):
|
||||
assert exc_of(sym) == expected
|
||||
|
||||
|
||||
def test_exc_of_3digit_priority_critical():
|
||||
"""关键防坑: 920 必须在 2 位判断前拦截, 否则 sym[:2]='92' 落 SZSE。
|
||||
这是本任务的核心 invariant — 单独显式断言一次。"""
|
||||
assert exc_of("920001") == "BJSE"
|
||||
# 同时确认 92 开头但非 920 仍归 SZSE (未来 921/929 等若出现, 走默认分支)
|
||||
# 注意: 现网北交所目前只有 920 段;83/87/43 段归 BJ 应 separately handled if needed
|
||||
Reference in New Issue
Block a user