Files
easy_tdx_max/examples/03_kline/security_bars.py
T
GitHubandClaude Opus 4.7 50491f9aae feat!: rename project from xmtdx to easy-tdx
- Package directory: src/xmtdx/ -> src/easy_tdx/
- Import path: from easy_tdx import ...
- pip install easy-tdx
- Add LICENSE (MIT) with upstream attribution (pytdx, xmtdx)
- Add NOTICE with detailed attribution
- Update all examples, tests, scripts, docs
- Bump version to 1.0.0

BREAKING CHANGE: import path changed from `xmtdx` to `easy_tdx`

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

24 lines
707 B
Python

"""演示:获取个股 K 线数据。
K 线类别:
KlineCategory.MIN_1 / MIN_5 / MIN_15 / MIN_30 / MIN_60
KlineCategory.DAY / WEEK / MONTH / YEAR
"""
import pandas as pd
from easy_tdx import TdxClient, Market, KlineCategory
with TdxClient.from_best_host() as c:
bars = c.get_security_bars(Market.SZ, "002176", KlineCategory.DAY, 0, 100)
df = pd.DataFrame([{
"日期": f"{b.year}-{b.month:02d}-{b.day:02d}",
"开盘": b.open,
"最高": b.high,
"最低": b.low,
"收盘": b.close,
"成交量": b.vol,
"成交额": b.amount,
} for b in reversed(bars)])
print("上证指数 日K线:")
print(df.to_string(index=False))