feat: blocks 命令 — 本地板块文件同步(行业/概念/指数/地区) - #40
Merged
Conversation
- 新模块 blocks.py:四条数据链解析(infoharbor_block.dat 概念/指数/风格、 tdxhy×tdxzs3 类别12 行业多级、spblock.dat 跨市场指数补充、base.dbf DY×tdxzs 地区) - infoharbor 截断板块名经 880 码还原 tdxzs 官方全名;空板块由 spblock 同名成分补齐(中证500/1000 等);spblock 独有板块归为"特殊" - block_stock_relation 表:新增 block_type,唯一约束改 (block_type, block_name, code)(880 码可空 + 同名跨体系);全量替换式快照写入 - cli:blocks 子命令 + sync 末尾自动执行;status 纳入板块表统计 - 迁移脚本 scripts/migrate_block_relation.sql(原表无写入路径,直接重建) - 测试 +7:四链解析逐字段断言(合成 GBK/DBF fixture)+ 快照替换语义 + 缺文件降级 - 真实数据验证:136,143 条入库;与导出 CSV 比对行业 127/127、地区 32/32、 概念 269/270(1 个为 tdxzs 官方全名变体)、指数 73+9 小众缺失(无本地源) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- DELETE + INSERT 同一 engine.begin() 事务,任一批次失败不再留下 空表/半新半旧快照 - 新增回滚测试:坏数据写入失败后旧快照行数不变 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
xbfighting
added a commit
that referenced
this pull request
Jul 7, 2026
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tdx2db sync自动同步板块-个股关系入库,替代"通达信手工导出 CSV → 导入"流程;板块新鲜度与行情同节奏。Related Issue
Closes #39
What Changed
infoharbor_block.dat(文本 GBK;截断名经 880 码还原 tdxzs 官方全名)tdxhy.cfgX 码 ×tdxzs3.cfg类别 12(881 研究行业,一/二/三级各一行)spblock.dat(中证500/1000/2000/A500、国证2000、深证成指等,infoharbor 空板块自动补齐;独有板块归"特殊")base.dbfDY 字段(struct 手工解析 DBF,仅取 GPDM/DY)×tdxzs.cfg类别 3block_stock_relation:+block_type 列,唯一约束 (block_type, block_name, code),全量替换式快照(板块关系无历史语义);迁移脚本附blocks子命令(--csv-only/--db-only)+sync第 3 步自动执行;status纳入统计Why This Approach
Done Criteria Mapping(vs issue #39)
How to Test
pytest(62 passed)tdx2db --tdx-path <TDX> --db-type sqlite --db-name t blocks --db-only→ 实测入库 136,143 条(行业 467 / 概念 270 / 指数 115 / 地区 32 / 风格 157 / 特殊 23 个板块)tdx2db status应显示 block_stock_relation 行数Risks / Tradeoffs
🤖 Generated with Claude Code