mirror of
https://ghfast.top/https://github.com/aeroxw/easy_tdx_max.git
synced 2026-09-12 16:54:20 +08:00
- 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>
26 lines
807 B
Python
26 lines
807 B
Python
"""演示:获取指数 K 线数据。
|
|
|
|
常用指数代码:
|
|
上证指数: Market.SH, "000001"
|
|
深证成指: Market.SZ, "399001"
|
|
创业板指: Market.SZ, "399006"
|
|
"""
|
|
|
|
import pandas as pd
|
|
from xmtdx import TdxClient, Market, KlineCategory
|
|
|
|
with TdxClient.from_best_host() as c:
|
|
bars = c.get_index_bars(Market.SH, "999999", KlineCategory.DAY, 0, 10)
|
|
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线:")
|
|
fmt = {"成交量": lambda x: f"{x:,.0f}", "成交额": lambda x: f"{x:,.0f}"}
|
|
print(df.to_string(index=False, formatters=fmt))
|