TdxData 方法签名¶
本页由
mkdocstrings从src/pytdxdata/api.py的 docstring 实时渲染。 你看到的签名就是当前代码的签名——不需要手动维护,也就不会过期。
用法¶
import asyncio
from pytdxdata import TdxData
from pytdxdata.models import KlinePeriod
async def main():
async with TdxData() as td:
bars = await td.get_bars("sh600000", KlinePeriod.DAY, count=240)
print(bars[-1])
asyncio.run(main())
本页太长?
想看「有哪些能力」的地图,去 接口总览。
本页是完整的签名字典,适合用浏览器 Ctrl+F 搜方法名。
完整定义¶
TdxData
¶
TdxData(
*,
standard_servers: Sequence[str] | None = None,
mac_servers: Sequence[str] | None = None,
ex_servers: Sequence[str] | None = None,
port: int = 7709,
timeout: float = 3.0,
cache_dir: str | Path | None = None,
default_adjust: Adjust = NONE,
max_inflight: int = 64,
pool_min: int = 3,
pool_max: int = 12,
mac_pool_cap: int = 4,
std_pool_cap: int = 4,
)
通达信行情数据统一入口。
标的一律用字符串(见 :mod:pytdxdata.symbols);方法名与方法数只按数据类型分,
不再按通道/市场分。旧的按通道分裂的方法保留为 deprecated 别名。
方法:¶
get_universe
async
¶
get_universe(
market: str | None = None,
) -> list[SecurityInfo]
标的清单(A股证券列表 + 扩展市场商品列表),一次覆盖所有市场。
参数
market: 市场选择器 —— None/"all"=全部市场;"sz"/"sh"/"bj"=A股某市;
"hk"/"us"/"cffex"/"zz"/"dl"/"shf"/"gz"=扩展市场(也可用完整枚举名,
如 "hk_gem")。
返回
list[SecurityInfo],每条带 symbol 规范化标的串与 kind 分类描述。
EX 通道无昨收/单位,对应字段为 0。
get_quotes
async
¶
get_quotes(
symbols: str | Sequence[str],
*,
fields: Sequence[int] | None = None,
) -> list[SecurityQuote]
报价,一次可跨市场、跨通道混合查询。
参数
symbols: 一个或多个标的字符串("sz000001" / "hk00700" / "usAAPL" /
"cffex:IFL0")。
fields: 可选自定义字段位(如 [0x00, 0x04, 0x38])。给了就走 MAC/EX 的
0x122B 字段位通道(有 name,无五档);不给时 A股走标准通道
(有五档 bid/ask、买卖量、涨跌停价,无 name),扩展市场走 0x122B。
返回
list[SecurityQuote],按入参顺序排列(各记录带 symbol)。
A股标准通道与扩展市场的可用字段不同:五档只在 A股标准通道有,
名称只在 fields= / 扩展市场有,其余字段位统一落在 .fields。
get_snapshot
async
¶
get_snapshot(
symbols: str | Sequence[str],
) -> list[SymbolSnapshot]
个股特征快照(当日/换手/活跃度等,仅 A股)。
get_capital_flow
async
¶
get_capital_flow(
symbols: str | Sequence[str],
) -> list[CapitalFlow]
个股资金流向(仅 A股)。
get_bars
async
¶
get_bars(
symbols: str | Sequence[str],
period: KlinePeriod = DAY,
*,
start: int = 0,
count: int = 800,
adjust: Adjust | None = None,
start_date: datetime | None = None,
end_date: datetime | None = None,
concurrency: int = 6,
) -> list[SecurityBar]
K线(多标的并发,自动判指数、自动复权选路、自动跨市场)。
参数
symbols: 一个或多个标的字符串;混合市场会按通道并发拉取后按入参顺序拼接。
period: K线周期(KlinePeriod.DAY 等)。
start: 起始偏移量(从最早K线开始的索引,默认0)。
count: 获取条数(默认800;超过单页会自动多连接并发分页)。
adjust: 复权方式(默认用实例 default_adjust);QFQ/HFQ 自动走 MAC 通道。
start_date / end_date: 按日期区间取(与 start/count 互斥,优先日期过滤)。
只给 start_date 即增量更新语义(取该日期之后的全部K线)。
返回
list[SecurityBar],按入参标的顺序拼接,每根带 symbol;组内按时间正序。
get_indicators
async
¶
get_indicators(
symbols: str | Sequence[str],
indicators: Sequence[str],
*,
period: KlinePeriod = DAY,
count: int = 30,
adjust: Adjust | None = None,
params: dict | None = None,
) -> list[IndicatorSet]
K线 + 技术指标(MACD/KDJ/RSI/BOLL/MA/EMA)。
返回 list[IndicatorSet](每个标的一组:bars + indicators),
指标序列与 bars 等长(尾部对齐)。
get_ticks
async
¶
get_ticks(
symbols: str | Sequence[str],
*,
date: int | None = None,
start: int = 0,
count: int | None = None,
concurrency: int = 6,
) -> list[TransactionRecord]
逐笔成交(A股 MAC 0x122F / 港股 EX 0x23FC·0x2406 / 其他扩展市场 MAC)。
参数
date: None=当日,YYYYMMDD=历史某日。
start: 起始偏移。
count: None=尽量取全量(自动翻页,上限 50 页);给了就取这么多条。
返回
list[TransactionRecord],按入参标的顺序拼接(A股含 trade_count,
港股为 HH:MM 时间 + fields["zengcang"] 增仓)。
get_minutes
async
¶
get_minutes(
symbols: str | Sequence[str],
*,
date: int | None = None,
sampling: bool = False,
concurrency: int = 6,
) -> list[MinuteBar]
分时(A股 MAC 0x122D / 扩展市场 0x122D 同构)。
参数
date: None=今天;YYYYMMDD=历史某日(A股支持历史分时)。
sampling: True 取缩略采样(约 240 个价格点,无时间),vol/
avg_price 为 0,点位序号在 fields["i"]。A股由分时数据派生,
扩展市场走 0x254D。
返回
list[MinuteBar],按入参标的顺序拼接,每条带 symbol/market/
code/date(扩展市场的动量落在 fields["momentum"])。
get_xdxr
async
¶
get_xdxr(symbols: str | Sequence[str]) -> list[XdxrRecord]
除权除息历史,仅 A股。标的用字符串("sz000001")。
get_finance
async
¶
get_finance(
symbols: str | Sequence[str],
) -> list[FinanceRecord]
财务快照(仅 A股)。无数据的标的会被跳过(原单标的接口返回 None)。
get_price_limits
async
¶
get_price_limits(
symbol: str,
name: str | None = None,
pre_close: float | None = None,
listed_days: int = 9999,
) -> tuple[float | None, float | None]
涨跌停价(本地计算,无网络;仅 A股,指数/基金返回 (None, None))。
get_f10
async
¶
get_f10(
symbol: str,
section: str | None = None,
*,
offset: int = 0,
length: int = 65535,
) -> list | str
F10 公司资料(仅 A股)。
section=None 返回目录(list[CompanyInfoCategory],含 name/
filename/length);给了 section 则返回该条目正文
(str,用 offset/length 分块读取长文)。
get_unusual
async
¶
get_unusual(
market: str = "all", *, start: int = 0, count: int = 600
) -> list[UnusualItem]
市场异动(仅 A股;market="all" = 深市 + 沪市)。
get_kline_offset
async
¶
K线偏移信息(MAC 0x124A,返回 (总根数, 本次返回数))。
get_boards
async
¶
get_boards(
kind: str = "all", *, count: int = 10000
) -> list[BoardInfo]
板块列表(kind: all/industry/concept/style,也接受数字)。
每条除板块本身外还带领涨股信息(symbol_* 字段)。
get_board_members
async
¶
get_board_members(
board: str,
count: int = 100000,
sort_type: int = 0,
*,
fields: Sequence[int] | None = None,
) -> list[SecurityQuote]
板块成分股报价(board 如 "881001";返回归一报价模型)。
fields 可加取自定义字段位(如 [0x38] 主力净流入),默认取基础字段位
(昨收/开/高/低/现价/量/量比/额),全部字段位同时保留在 .fields。
get_board_of
async
¶
get_board_of(
symbols: str | Sequence[str],
) -> list[BelongBoard]
个股所属板块(仅 A股;symbol 记录被查询的个股)。
get_board_ranking
async
¶
板块当日涨跌幅排行(基于板块报价的现价/昨收)。
get_board_change_ranking
async
¶
get_board_change_ranking(
kind: str = "industry",
*,
days: int = 20,
top_n: int = 20,
) -> list[dict]
板块 N 日涨跌幅排行(基于板块指数K线)。
get_file
async
¶
下载服务器文件原始字节(按文件名自动选通道)。
block_*.dat—— 板块文件(标准 0x1869/0x186A,先查元数据再分块)tdxhy.cfg/tdxfin/*—— 报告财务文件(标准 0x06B9,分块)- 其他 —— MAC 远程文件(0x1215 查元数据 + 0x1217 分块)
通常不用直接调它:板块/行业/财报都有解析好的 get_*_parsed。
get_block_parsed
async
¶
get_block_parsed(filename: str) -> list[TdxBlock]
板块文件 -> list[TdxBlock](板块名/类别/成分股)。
常用文件名:block_zs.dat(行业)/ block_gn.dat(概念)/ block_fg.dat(风格)。
category 由文件名推断(0=行业 1=地域 2=概念 3=风格)。
get_industry_map
async
¶
get_industry_map() -> dict[str, IndustryInfo]
tdxhy.cfg -> {6位代码: IndustryInfo}(通达信 + 申万行业)。
get_financial_file_infos
async
¶
get_financial_file_infos() -> list[FinancialFileInfo]
tdxfin/gpcw.txt -> list[FinancialFileInfo](文件名/MD5/大小)。
get_financial_records_parsed
async
¶
get_financial_records_parsed(
filename: str,
) -> list[FinancialRecord]
财报数据解析 -> list[FinancialRecord]。
可直接把 :meth:get_financial_file_infos 条目里的 filename 原样传进来:
内部会自动纠正「索引名与服务器实际文件名不一致」的问题(索引写
gpcwYYYYMMDD.zip 且不带 tdxfin/ 前缀,服务器实际只提供未压缩的
tdxfin/gpcwYYYYMMDD.dat),并兼容 zip 包与未压缩 dat 两种形态。
报告期优先取文件名中的 8 位日期,缺失时回退到 .dat 头部内嵌值。
get_kline
async
¶
get_kline(
market,
code,
period,
*,
start: int = 0,
count: int = 800,
adjust: Adjust | None = None,
start_date: datetime | None = None,
end_date: datetime | None = None,
) -> list[SecurityBar]
已废弃 -> :meth:get_bars。
get_kline_since
async
¶
get_kline_since(
market,
code,
period,
since: datetime,
adjust: Adjust | None = None,
) -> list[SecurityBar]
已废弃 -> :meth:get_bars(start_date=since)。
get_kline_batch
async
¶
get_kline_batch(
stocks,
period,
*,
start: int = 0,
count: int = 800,
adjust: Adjust | None = None,
concurrency: int = 6,
) -> dict[str, list[SecurityBar]]
已废弃 -> :meth:get_bars(返回值由 {code: bars} 变为平铺列表)。
get_index_kline
async
¶
get_index_kline(
market,
code,
period,
*,
start: int = 0,
count: int = 800,
) -> list[SecurityBar]
已废弃 -> :meth:get_bars(指数自动识别,无需单独接口)。
get_stock_kline_with_indicators
async
¶
get_stock_kline_with_indicators(
market,
code,
indicators,
*,
period: KlinePeriod = DAY,
count: int = 30,
adjust: Adjust | None = None,
params: dict | None = None,
) -> dict
已废弃 -> :meth:get_indicators。
get_stock_quotes
async
¶
get_stock_quotes(stocks, bits=None) -> list[SecurityQuote]
已废弃 -> :meth:get_quotes(fields=bits)。
get_stock_quotes_list
async
¶
get_stock_quotes_list(
category: int,
*,
start: int = 0,
count: int = 80,
sort_type: int = 0,
) -> list[SecurityQuote]
已废弃 -> :meth:get_board_members(分类码 = 板块码口径)。
get_transactions
async
¶
get_transactions(
market,
code,
*,
date: int | None = None,
start: int = 0,
count: int = 2000,
) -> list[TransactionRecord]
已废弃 -> :meth:get_ticks。
get_minute
async
¶
get_minute(
market, code, *, date: int | None = None
) -> list[MinuteBar]
已废弃 -> :meth:get_minutes。
get_minute_batch
async
¶
get_minute_batch(
stocks, *, date: int | None = None, concurrency: int = 6
) -> dict[str, list[MinuteBar]]
已废弃 -> :meth:get_minutes(返回值由 {code: bars} 变为平铺列表)。
get_chart_sampling
async
¶
已废弃 -> :meth:get_minutes(sampling=True)。
get_security_list
async
¶
get_security_list(
market, *, start: int = 0, count: int | None = None
) -> list[SecurityInfo]
已废弃 -> :meth:get_universe(本地切片 [start:start+count])。
get_security_list_all
async
¶
get_security_list_all(market) -> list[SecurityInfo]
已废弃 -> :meth:get_universe。
get_financial_file_list
async
¶
已废弃 -> :meth:get_financial_file_infos(返回 FinancialFileInfo)。
get_financial_records
async
¶
已废弃 -> :meth:get_financial_records_parsed。
返回 gpcw 财报 .dat 原始字节(服务器给未压缩 .dat 时自动回退,
不再像旧实现那样静默返回 0~1 字节空壳);取不到时返回 b""。
get_company_info_category
async
¶
已废弃 -> :meth:get_f10。
get_company_info_content
async
¶
get_company_info_content(
market,
code,
filename: str,
offset: int = 0,
length: int = 65535,
) -> str
已废弃 -> :meth:get_f10。
download_file
async
¶
已废弃 -> :meth:get_file。
get_board_list
async
¶
get_board_list(
board_type: int | str = 0, count: int = 10000
) -> list[BoardInfo]
已废弃 -> :meth:get_boards。
get_belong_board
async
¶
get_belong_board(market, code) -> list[BelongBoard]
已废弃 -> :meth:get_board_of。
get_symbol_info
async
¶
get_symbol_info(market, code) -> SymbolSnapshot | None
已废弃 -> :meth:get_snapshot(旧版返回单个对象)。
get_goods_list
async
¶
get_goods_list(
market, start: int = 0, count: int = 100
) -> list[SecurityInfo]
已废弃 -> :meth:get_universe(扩展到 SecurityInfo 统一模型)。
get_goods_count
async
¶
已废弃 -> len(get_universe(...))。
get_goods_quotes
async
¶
get_goods_quotes(stocks, bits=None) -> list[SecurityQuote]
已废弃 -> :meth:get_quotes。
get_goods_quotes_list
async
¶
get_goods_quotes_list(
market, count: int = 80
) -> list[SecurityQuote]
已废弃 -> :meth:get_quotes(或 get_universe 取清单后自选)。
get_goods_chart_sampling
async
¶
已废弃 -> :meth:get_minutes(sampling=True)。
get_goods_tick_chart
async
¶
get_goods_tick_chart(
market, code, ymd: int = 0
) -> list[MinuteBar]
已废弃 -> :meth:get_minutes(扩展到统一分时模型)。
get_goods_transaction
async
¶
get_goods_transaction(
market,
code,
*,
ymd: int = 0,
start: int = 0,
count: int = 1800,
) -> list[TransactionRecord]
已废弃 -> :meth:get_ticks(扩展到统一逐笔模型)。
get_goods_transaction_all
async
¶
get_goods_transaction_all(
market, code, ymd: int = 0
) -> list[TransactionRecord]
已废弃 -> :meth:get_ticks(count=None 即全量翻页)。