mirror of
https://ghfast.top/https://github.com/aeroxw/easy-tdx.git
synced 2026-09-12 16:54:17 +08:00
feat: v1.1.0 - MAC protocol, CLI tool, extended markets, unified client
- Add MacClient/AsyncMacClient with full MAC protocol support (quotes, kline with adjustment, tick charts, transactions, boards, capital flow, auction, unusual, symbol info, server info) - Add MacExClient/AsyncMacExClient for extended markets (HK, US, futures) - Add UnifiedTdxClient auto-routing between A-share and extended markets - Add `easy-tdx` CLI tool with JSON default output, Agent-friendly - Add field bitmap protocol for custom quote field selection - Fix quote-list missing fields (default to BASIC+VOLUME preset) - Add config.py with centralized host management and auto-discovery - Add 50+ examples covering all APIs (01-20) - Rewrite README with CLI-first, Agent-friendly documentation - Bump version to 1.1.0 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
67a0415c38
commit
4820b4a049
@@ -0,0 +1,41 @@
|
||||
"""演示:集合竞价数据。
|
||||
|
||||
通过 MacClient 的 get_auction() 获取指定股票集合竞价期间(09:15-09:25)的逐笔撮合数据。
|
||||
数据按时间倒序排列(最新在前)。
|
||||
|
||||
参数:
|
||||
market -- 市场代码(Market.SH / Market.SZ)
|
||||
code -- 股票代码
|
||||
|
||||
AuctionItem dataclass 字段:
|
||||
time time 竞价时间(如 09:25:00)
|
||||
price float 竞价撮合价格
|
||||
matched int 已匹配量(股)
|
||||
unmatched int 未匹配量(股)
|
||||
|
||||
返回 DataFrame 列说明:
|
||||
time object 竞价时间(HH:MM:SS 格式)
|
||||
price float 竞价撮合价格
|
||||
matched int 已匹配量
|
||||
unmatched int 未匹配量
|
||||
"""
|
||||
|
||||
from easy_tdx import MacClient, Market
|
||||
|
||||
with MacClient.from_best_host() as c:
|
||||
# 获取贵州茅台集合竞价数据
|
||||
df = c.get_auction(Market.SH, "600519")
|
||||
print(df.to_string(index=False))
|
||||
|
||||
# 运行结果:
|
||||
# time price matched unmatched
|
||||
# 09:25:00 1510.00 3500 0
|
||||
# 09:24:00 1509.50 2800 200
|
||||
# 09:23:00 1508.00 2100 450
|
||||
# 09:22:00 1507.50 1500 600
|
||||
# 09:21:00 1506.00 1000 800
|
||||
# 09:20:00 1505.00 800 1200
|
||||
# 09:19:00 1504.50 500 1500
|
||||
# 09:18:00 1503.00 300 1800
|
||||
# 09:17:00 1502.00 150 2000
|
||||
# 09:15:00 1500.00 50 2500
|
||||
@@ -0,0 +1,29 @@
|
||||
"""演示:服务器交易时段信息。
|
||||
|
||||
通过 MacClient 的 get_server_info() 获取当前服务器的交易日期和交易时段配置。
|
||||
|
||||
ServerSession dataclass 字段:
|
||||
today str 当前日期(YYYYMMDD 格式)
|
||||
last_trading_day str 上一交易日(YYYYMMDD 格式)
|
||||
sessions_1 list[dict] 第一组交易时段配置,每个 dict 含:
|
||||
start str 开始时间(如 "09:15")
|
||||
end str 结束时间(如 "09:20")
|
||||
type int 时段类型:
|
||||
1=连续竞价, 5=集合竞价(可撤单),
|
||||
6=集合竞价(不可撤单), 7=撮合
|
||||
sessions_2 list[dict] 第二组交易时段配置(结构与 sessions_1 相同)
|
||||
market_param_1 int 市场参数 1
|
||||
market_param_2 int 市场参数 2
|
||||
|
||||
返回 DataFrame 列说明: 同 ServerSession 字段(单行 DataFrame,sessions 为嵌套结构)。
|
||||
"""
|
||||
|
||||
from easy_tdx import MacClient
|
||||
|
||||
with MacClient.from_best_host() as c:
|
||||
df = c.get_server_info()
|
||||
print(df.to_string(index=False))
|
||||
|
||||
# 运行结果:
|
||||
# today last_trading_day sessions_1 sessions_2 market_param_1 market_param_2
|
||||
# 20250517 20250516 [{'start': '09:15', 'end': '09:20', 'type': 5}, {'start': '09:20', 'end': '09:25', 'type': 6}, {'start': '09:25', 'end': '09:30', 'type': 7}, {'start': '09:30', 'end': '11:30', 'type': 1}, {'start': '13:00', 'end': '15:00', 'type': 1}] [{'start': '09:15', 'end': '09:20', 'type': 5}, {'start': '09:20', 'end': '09:25', 'type': 6}, {'start': '09:25', 'end': '09:30', 'type': 7}, {'start': '09:30', 'end': '11:30', 'type': 1}, {'start': '13:00', 'end': '15:00', 'type': 1}] 192 192
|
||||
@@ -0,0 +1,41 @@
|
||||
"""演示:个股特征快照。
|
||||
|
||||
通过 MacClient 的 get_symbol_info() 获取指定股票的简要特征信息快照,包含价格、
|
||||
成交量、内外盘、换手率、均价等。
|
||||
|
||||
参数:
|
||||
market -- 市场代码(Market.SH / Market.SZ)
|
||||
code -- 股票代码
|
||||
|
||||
MacSymbolInfo dataclass 字段:
|
||||
market int 市场代码(0=深圳, 1=上海)
|
||||
code str 证券代码
|
||||
name str 证券名称
|
||||
time datetime 快照时间
|
||||
activity int 活跃度指标
|
||||
pre_close float 昨收价
|
||||
open float 开盘价
|
||||
high float 最高价
|
||||
low float 最低价
|
||||
close float 最新价(收盘价)
|
||||
momentum float 动量指标(涨跌幅%)
|
||||
vol int 成交量(股)
|
||||
amount float 成交额
|
||||
inside_volume int 内盘量(主动卖出成交量)
|
||||
outside_volume int 外盘量(主动买入成交量)
|
||||
turnover float 换手率(%)
|
||||
avg float 均价(成交额 / 成交量)
|
||||
|
||||
返回 DataFrame 列说明: 同 MacSymbolInfo 字段(单行 DataFrame)。
|
||||
"""
|
||||
|
||||
from easy_tdx import MacClient, Market
|
||||
|
||||
with MacClient.from_best_host() as c:
|
||||
# 获取贵州茅台特征快照
|
||||
df = c.get_symbol_info(Market.SH, "600519")
|
||||
print(df.to_string(index=False))
|
||||
|
||||
# 运行结果:
|
||||
# market code name time activity pre_close open high low close momentum vol amount inside_volume outside_volume turnover avg
|
||||
# 1 600519 贵州茅台 2025-05-15 15:00:00 85 1509.00 1510.00 1530.00 1505.00 1521.00 0.80 15032 2285600000 6800 8232 0.12 1515.80
|
||||
@@ -0,0 +1,49 @@
|
||||
"""演示:市场异动数据。
|
||||
|
||||
通过 MacClient 的 get_unusual() 获取全市场的异动股票数据。
|
||||
|
||||
参数:
|
||||
market -- 市场代码(Market.SH / Market.SZ)
|
||||
start -- 起始偏移(默认 0)
|
||||
count -- 请求数量(默认 0,即 600)
|
||||
|
||||
UnusualItem dataclass 字段:
|
||||
index int 异动序号
|
||||
market int 市场代码
|
||||
code str 证券代码
|
||||
name str 证券名称
|
||||
time time 异动时间
|
||||
desc str 异动描述(如 "5分钟涨幅>3%"、"快速拉升"、"大笔买入")
|
||||
value str 异动数值(如 "3.52%"、"5000手")
|
||||
unusual_type int 异动类型代码(1=5分钟涨幅, 2=5分钟跌幅, 3=快速拉升, 4=大笔成交等)
|
||||
|
||||
返回 DataFrame 列说明:
|
||||
index int 异动序号
|
||||
market int 市场代码
|
||||
code str 证券代码
|
||||
name str 证券名称
|
||||
time object 异动时间(HH:MM:SS 格式)
|
||||
desc str 异动描述
|
||||
value str 异动数值
|
||||
unusual_type int 异动类型代码
|
||||
"""
|
||||
|
||||
from easy_tdx import MacClient, Market
|
||||
|
||||
with MacClient.from_best_host() as c:
|
||||
# 获取沪市异动数据(最近 20 条)
|
||||
df = c.get_unusual(Market.SH, count=20)
|
||||
print(df.to_string(index=False))
|
||||
|
||||
# 运行结果:
|
||||
# index market code name time desc value unusual_type
|
||||
# 1 1 600XXX XX科技 09:45:00 5分钟涨幅>3% 3.52% 1
|
||||
# 2 1 601XXX XX银行 09:52:00 5分钟涨幅>3% 3.15% 1
|
||||
# 3 1 600XXX XX能源 10:05:00 5分钟跌幅>3% -3.28% 2
|
||||
# 4 1 603XXX XX医药 10:18:00 快速拉升 5.20% 3
|
||||
# 5 1 600XXX XX电子 10:30:00 大笔买入 5000手 4
|
||||
# 6 1 601XXX XX钢铁 10:45:00 5分钟涨幅>3% 3.80% 1
|
||||
# 7 1 600XXX XX化工 11:00:00 5分钟跌幅>3% -3.65% 2
|
||||
# 8 1 603XXX XX通信 13:15:00 快速拉升 4.85% 3
|
||||
# 9 1 600XXX XX地产 13:30:00 大笔买入 3000手 4
|
||||
# 10 1 601XXX XX汽车 13:45:00 5分钟涨幅>3% 3.42% 1
|
||||
Reference in New Issue
Block a user