Files
easy_tdx_max/examples/07_block/block_info.py
T
GitHubandClaude Opus 4.7 7fd6e610cf feat: add examples (01-08), fix index bars parsing, add ruff hook
- Add example scripts for all API categories (connection, market info,
  kline, minute, transaction, finance, block, fund flow)
- Fix GetIndexBarsCmd: index bar records have 4 extra bytes (advance/
  decline counts) that were not consumed, causing pos drift and
  corrupted dates/volumes for all records after the first
- Fix price_limits.py example (SecurityQuote has no name attr)
- Fix finance_info.py display (scientific notation -> formatted numbers)
- Add PostToolUse ruff hook (scripts/ruff_hook.py)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-21 18:36:50 +08:00

22 lines
612 B
Python

"""演示:获取板块信息(行业、概念、风格)。
常用板块文件:
'block_zs.dat' - 行业/指数板块
'block_gn.dat' - 概念板块
'block_fg.dat' - 风格板块
"""
import pandas as pd
from xmtdx import TdxClient
with TdxClient.from_best_host() as c:
blocks = c.get_block_info("block_gn.dat")
df = pd.DataFrame([{
"板块名称": b.name,
"分类": b.category,
"成分股数": b.count,
"代码(前5)": ", ".join(b.codes[:5]),
} for b in blocks])
print(f"概念板块,共 {len(df)} 个:")
print(df.head(20).to_string(index=False))