通达信行情协议 Python 库,支持快照、分时、逐笔、K 线、集合竞价和历史 09:25 竞价接口
Project description
eltdx
通达信在线行情协议 Python 库。可以拿沪深北 A 股的实时快照、分时、逐笔、K 线、集合竞价、历史 09:25 竞价、股本变化和复权因子。
安装
pip install eltdx
需要 Python 3.10 或更高版本。
快速示例
from eltdx import TdxClient
with TdxClient() as client:
quotes = client.get_quote(["sz000001", "sh600000"])
for quote in quotes:
print(quote.code, quote.last_price, quote.last_close_price, quote.server_time)
K 线:
from eltdx import TdxClient
with TdxClient() as client:
kline = client.get_kline("sz000001", "day", count=5)
for item in kline.items:
print(item.time, item.close_price, item.volume)
历史 09:25 竞价:
from eltdx import TdxClient
with TdxClient() as client:
row = client.get_auction_0925("000001", "2026-04-09")
print(row.code, row.trading_date, row.has_auction_0925)
print(row.price, row.volume, row.amount)
接口
| 数据 | 方法 | 说明 |
|---|---|---|
| 行情快照 | get_quote() |
最新价、昨收、今开、最高、最低、五档盘口、成交量额等 |
| 代码表 | get_codes() / get_codes_all() |
底层代码表,包含股票、指数、ETF、基金等 |
| 常用代码清单 | get_a_share_codes_all() / get_etf_codes_all() / get_index_codes_all() |
对代码表做常用过滤 |
| 分时 | get_minute() / get_history_minute() |
实时分时和历史分时 |
| 逐笔 | get_trades() / get_trades_all() |
实时逐笔、历史逐笔、自动翻页 |
| K 线 | get_kline() / get_kline_all() |
支持分钟、日、周、月等周期 |
| 复权 K 线 | get_adjusted_kline() / get_adjusted_kline_all() |
支持前复权和后复权 |
| 集合竞价 | get_call_auction() |
集合竞价序列 |
| 历史 09:25 | get_auction_0925() |
快速定位指定交易日 09:25 那一笔 |
| 公司行为 / 股本 | get_gbbq() / get_xdxr() / get_equity() / get_factors() |
除权除息、股本变化、复权因子 |
完整参数和字段说明见 API_REFERENCE.md 和 FIELD_REFERENCE.md。
服务器选择
不传服务器地址时,会使用包内 tdx_server.json 的默认列表,已按测速结果排序。
from eltdx import TdxClient
with TdxClient() as client:
quote = client.get_quote("sz000001")[0]
print(quote.last_price)
需要重新测速时打开 probe_hosts=True:
from eltdx import TdxClient
with TdxClient(probe_hosts=True) as client:
print(client.get_quote("sz000001")[0].last_price)
手动指定服务器:
from eltdx import TdxClient
hosts = ["116.205.183.150:7709", "116.205.171.132:7709"]
with TdxClient(hosts=hosts, pool_size=2, timeout=8.0) as client:
print(client.get_quote(["sz000001", "sh600000"]))
| 参数 | 默认值 | 说明 |
|---|---|---|
host |
None |
指定单个服务器 |
hosts |
None |
指定多个服务器,优先级高于 host |
pool_size |
2 |
连接池大小 |
batch_size |
80 |
get_quote() 自动分批大小,上限为 80 |
probe_hosts |
False |
初始化时对候选服务器测速并重排 |
timeout |
8.0 |
socket 请求超时秒数 |
MCP
普通 SDK 不依赖 MCP。需要给 MCP 客户端或 Agent 用时:
pip install "eltdx[mcp]"
eltdx-mcp
| 类别 | 工具 | 作用 |
|---|---|---|
| 行情 | tdx_get_quote |
实时行情快照 |
| 行情 | tdx_get_minute |
实时 / 历史分时 |
| K 线 | tdx_get_kline / tdx_get_kline_all |
单页 / 全量 K 线,支持 qfq、hfq 复权 |
| 逐笔 | tdx_get_trades / tdx_get_trades_all |
单页 / 全量逐笔成交 |
| 竞价 | tdx_get_auction_0925 / tdx_get_call_auction |
历史 09:25 竞价笔、实时集合竞价序列 |
| 代码表 | tdx_get_count / tdx_get_codes / tdx_get_code_list |
市场数量、分页代码表、A 股 / 股票 / ETF / 指数列表 |
| 股本复权 | tdx_get_gbbq / tdx_get_xdxr / tdx_get_factors |
股本变迁、除权除息、复权因子 |
| 股本复权 | tdx_get_equity_changes / tdx_get_equity / tdx_get_turnover |
股本变化、指定日期股本、换手率计算 |
| 衍生 | tdx_get_trade_minute_kline |
用逐笔聚合分钟 K 线 |
带 _all 的 MCP 工具默认只返回前 1000 条,并带 total、start、limit 字段;需要全量时显式传 limit=null。
注意
get_count() 不是股票总数
get_count("sh") 读的是通达信代码表条目数,不是股票数量。A 股数量和列表:
client.get_a_share_count("sh")
client.get_a_share_codes_all()
get_codes() 不只返回股票
底层代码表会混有股票、指数、ETF、基金、债券回购、板块分类项等。常用过滤:
client.get_a_share_codes_all()
client.get_etf_codes_all()
client.get_index_codes_all()
代码建议带市场前缀
推荐写完整代码,例如 sz000001、sh600000、bj920001。
原始协议数据可以保留
排查协议解析问题时用 include_raw=True:
with TdxClient() as client:
minute = client.get_minute("sz000001", include_raw=True)
print(minute.raw_frame_hex)
print(minute.raw_payload_hex)
文档
| 文档 | 内容 |
|---|---|
| docs/API_REFERENCE.md | API 参数和返回值 |
| docs/EXAMPLES.md | 可直接复制的示例 |
| docs/FIELD_REFERENCE.md | 字段含义和口径 |
| docs/DEBUG_GUIDE.md | 连接、服务器和 raw 数据排查 |
| scripts/README.md | smoke / validation 脚本说明 |
开发
pytest tests/unit
python -m build
联网测试需要真实服务器:
set ELTDX_RUN_LIVE=1
pytest tests/integration
参考
感谢 injoyai/tdx 的启发。
联系
- QQ 群:点击链接加入群聊
- 邮箱:dapaoxixixi@163.com
许可证
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file eltdx-0.5.1.tar.gz.
File metadata
- Download URL: eltdx-0.5.1.tar.gz
- Upload date:
- Size: 98.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa2b08a75978914f694e6cb155b0d2380ff6131129a432c5a6301125a0d91f88
|
|
| MD5 |
e8585fbff2d95137d044caca7e5c6815
|
|
| BLAKE2b-256 |
e2fadc4787fbc60b9aac3c0c8111ea01f7553772e03aee4af4b4d35cb6ef188c
|
Provenance
The following attestation bundles were made for eltdx-0.5.1.tar.gz:
Publisher:
publish.yml on electkismet/eltdx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
eltdx-0.5.1.tar.gz -
Subject digest:
fa2b08a75978914f694e6cb155b0d2380ff6131129a432c5a6301125a0d91f88 - Sigstore transparency entry: 1513506235
- Sigstore integration time:
-
Permalink:
electkismet/eltdx@25271c9397fbff1296b4285b0479671fcf1ef905 -
Branch / Tag:
refs/tags/v0.5.1 - Owner: https://github.com/electkismet
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@25271c9397fbff1296b4285b0479671fcf1ef905 -
Trigger Event:
push
-
Statement type:
File details
Details for the file eltdx-0.5.1-py3-none-any.whl.
File metadata
- Download URL: eltdx-0.5.1-py3-none-any.whl
- Upload date:
- Size: 46.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cdf50638c01418085cb1192b1b42d00db0cc0e38614e71f60f56cb3e83c09ba5
|
|
| MD5 |
a08bff061f615f5fe14fd0b47c021687
|
|
| BLAKE2b-256 |
5223cc071f42cc5afbe7412b176646f70f85148d3fadd44e4ea6280790c6431b
|
Provenance
The following attestation bundles were made for eltdx-0.5.1-py3-none-any.whl:
Publisher:
publish.yml on electkismet/eltdx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
eltdx-0.5.1-py3-none-any.whl -
Subject digest:
cdf50638c01418085cb1192b1b42d00db0cc0e38614e71f60f56cb3e83c09ba5 - Sigstore transparency entry: 1513506363
- Sigstore integration time:
-
Permalink:
electkismet/eltdx@25271c9397fbff1296b4285b0479671fcf1ef905 -
Branch / Tag:
refs/tags/v0.5.1 - Owner: https://github.com/electkismet
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@25271c9397fbff1296b4285b0479671fcf1ef905 -
Trigger Event:
push
-
Statement type: