Justin Gu
d0b72e1bd1
release: v1.31.3 — 紧急修复盘中分时数据错乱(实时命令解析错位,全程改走历史分时)
2026-09-04 12:42:44 +08:00
Justin Gu
9d2b0397bd
release: v1.31.2 — 修复分时接口盘前/休市/指数返回空(最近交易日锚定+指数K线适配)
2026-09-04 04:40:50 +08:00
GitHub
eeed45b171
fix(bars): 指数/个股 K 线 vol 字段协议语义修正(#64)
...
通达信服务端 K 线记录第一个 4 字节字段的语义随周期/品种变化,此前原样
透传错误数据(逐字节拆包 + 新浪实时行情/东方财富三方交叉验证锁定):
- 指数分钟线(MIN_1/3/5/15/30/60,含 880xxx 板块指数):f1 实为
成交额(百元),与 amount 恒差 100 倍,真实分钟成交量不在报文中
(15:00 上证 5min 真值 13,954,814 手 vs 返回 208,748,512≈amount/100)
→ vol 置 NaN,不拿成交额冒充成交量;
- 指数与个股周/月/季/年线(cat 5/6/10/11):f1 = 真实成交量/100
(上证本周三日日线 vol 合计 1,666,668,288 手 vs 周线 16,666,683)
→ ×100 还原,与日线单位对齐(指数=手、个股=股);
- 日线(cat 4)与 cat 9(日线变体,枚举名误标 YEAR,真年线是 cat 11)
不受影响,cat 9 明确不套 ×100 并由测试锁定。
配套:DataFrameResponse NaN→null(Starlette allow_nan=False 透传会 500);
client/路由 docstring 写明各单位;回归测试 7 例(实抓原始字节构造报文);
验收脚本 scripts/verify_issue64.py 连真实服务器复测。附带发现仅记录:
指数分时 vol=成交额(万元)、/bars?category=YEAR 实际返回日线(cat 9)。
2026-09-02 17:12:00 +08:00
GitHub
1b7d8a5fff
docs(client): 资金流口径标注——0x0fb5 逐笔为聚合记录、按成交额分档,与东财主力净额不可比(issue #55)
2026-08-28 20:14:41 +08:00
GitHub
574ffdd2a4
fix(client): 历史资金流当日行全零 + 主力净额列缺失(issue #52)
...
三个根因(全部实测核实):
1. Category 22 直连接口为虚构协议——52 台已知服务器中 46 台可达的
全部仅回 2 字节空包,从未成功过;移除死代码与臆造解析格式。
2. 历史逐笔接口当日数据要收盘清算后才有,日 K 盘中已含当日 bar,
故 start=0 的最新一行恒为全 0——当日 bar 改走当日实时逐笔接口。
3. main_net_inflow 此前仅为 dataclass property,asdict 静默丢弃,
返回 DataFrame 无主力净额列——新增 _fund_flow_df_with_net 物化
(history 紧随 date 列、当日快照放首列)。
sync + async 双客户端同步修改;更新示例与三份文档;重写/新增回归
测试(当日实时逐笔路径、主力净额列断言)。
2026-08-26 15:00:53 +08:00
GitHub
0490f67a16
fix(client): get_history_fund_flow 加空数据故障转移(issue #41)
...
用户反馈 get_history_fund_flow(SH, "600519") 返回空 DataFrame,日志显示
"K线响应为空(声称 800 条但首条即解析失败...)"。排查定位:当前 host 对
常见标的也返回 ret_count 撒谎的空 body,但资金流兼容回退路径(直连空 →
拉 K 线 + 历史逐笔重算)未接入 v1.20.4 的空数据故障转移,"服务器回包正常
但内容是假的空" 既非 TdxConnectionError 也不触发换台,用户卡在坏服务器上。
修复:get_history_fund_flow(sync+async)当前 host 直连与 K 线回退均空时,
按延迟顺序逐台实测找首台返回有效数据的服务器(与 get_security_bars/
get_index_bars 同源逻辑)。因资金流获取涉及多命令,无法用单 cmd 复用泛化版
_find_host_returning_data,故内联 _fund_flow_failover:每台候选上跑完整
_fetch_fund_flow_records(原直连+K线回退逻辑抽出成独立方法),返回首台非空
结果。全空返回空 DataFrame(不 raise,区分"真无历史数据"与"服务器缺数据")。
测试:新增 6 个(4 sync + 2 async)。全套 989 passed;ruff/mypy 改动文件零错误。
2026-08-05 15:53:49 +08:00
Justin Gu
1f040afabf
feat(reconnect): 引入服务器健康分引擎 + K线空数据故障转移
...
彻底解决通达信服务器"跳来跳去"问题:
1. 新增 _health.py 健康分引擎:失败乘性降权(×0.5)、连续失败3次进
120s 冷却、成功加性恢复(+0.2)。rank_by_health 按 latency/score
(有效延迟)重排,冷却中的剔除。全健康时恒等映射,对既有测试零影响。
2. get_index_bars/get_security_bars 空数据时自动逐台换台(此前直接
返回空 DataFrame,是日志"指数K线响应在第1/800条处被截断"后用户拿
不到数据的根因)。复用泛化后的 _find_host_returning_data。
3. select_best_host_*/find_working_host_* 应用 rank_by_health 重排;
空数据验证失败/异常时调 record_failure,命中调 record_success。
4. 8 个 _execute(A股/MAC/EX/MAC-EX × sync/async)统一注入健康分记录:
成功 record_success、连接失败 record_failure。
5. security_bars 截断日志区分"首条即空(服务器无数据)"与"末尾截断"。
测试:26 个新增(15 health + 7 failover + 4 ex-client 健康分追踪),
全量 reconnect/failover/decode 回归通过,ruff/mypy 通过。
2026-07-13 15:59:28 +08:00
Justin Gu
6b98715a14
fix(client): get_index_bars/get_security_bars 加空数据故障转移
...
指数/板块指数(880xxx 等)并非所有服务器都提供,延迟最低的不一定返回数据。
实测约 6/47 台可达主机对所有指数返回空 body 且不报错,from_best_host() 按纯
延迟选主会选中这种"快但空"的主机,导致 get_index_bars 返回空 DataFrame。
get_market_stat 早有 _find_host_returning_quotes 兜底,但 K 线查询缺失同类逻辑。
本提交补齐对称设计:
- 新增 _find_host_returning_bars(sync + async):照搬 _find_host_returning_quotes
模式,复用 find_working_host_sync/_async(最多试 5 台、带持久化、异常吞掉、
全失败回退原 host)
- get_security_bars / get_index_bars(sync + async 共 4 处)接入:空数据且
auto_reconnect 开启时触发逐台实测,找首台返回数据的 host
- 新增 TestIndexBarsEmptyFailover(5 个测试):覆盖空数据切 host、全候选空、
非空不触发、auto_reconnect=False 不触发、个股 K 线同链路
验证:23 个 failover 测试全绿,941 个单元测试无回归。
2026-07-10 19:37:31 +08:00
GitHub
d0d65d64b8
feat: v1.20.0 服务器失败自动 ping 切换(无需手动 easy-tdx ping)
...
服务器连不上或返回空数据时,自动测速切到延迟最低的可用服务器再试,
Python API / CLI / Web API 三入口全部自动生效。
核心改动:
- _reconnect.py 新增 select_best_host_sync/async(连接失败 failover)
和 find_working_host_sync/async(空数据逐台实测)
- 8 个 client 的 _execute 注入跨主机故障转移(复用 auto_reconnect 开关)
- get_market_stat 空数据时按延迟顺序逐台实测找返回数据的服务器
- 新增 _reconnect/_areconnect helper 收敛重建连接副本
- MacClient failover 用 save_best_mac_host(延续 v1.19.4 不污染 best_host)
- 顺手修复 test_commands_offline 未使用 import(main CI failure 根因)
测试:925 passed(新增 18 个 failover 测试),ruff/mypy 零新增错误。
2026-07-08 18:07:37 +08:00
Justin Gu
14debdb446
feat(web-ui): v1.19.7 服务器设置页面(测速+切换通达信服务器)
...
新增 web UI 第六个页面「服务器设置」,让用户在浏览器上:
1. 列出全部 50+ 候选服务器
2. 一键并发测速(显示延迟和可达性)
3. 点选切换到最快或可用的服务器(热重连,无需重启)
解决不同地区/运营商对通达信各服务器连通性不同的问题。
新增:
- AsyncTdxClient.reconnect_to(host) 热切换方法(持锁,关旧建新)
- GET/POST /api/v1/server/hosts|test|switch 三个端点
- ServerSettingsView.vue 页面(列表+测速+切换)
- 导航栏第六个入口
设计: 先reconnect成功再save_best_host(避免污染config),
host校验只允许候选列表内IP,不自动测速避免首屏卡顿。
2026-07-07 23:08:32 +08:00
Justin Gu
133c208510
release: v1.16.3 — 修复 market-stat 全市场涨跌统计家数偏小10倍
...
通达信统计指数 880005/880006 的计数类字段返回真实家数的 1/10,
get_market_stat 未做缩放还原,导致 up/down/total/limit_up 等系统性偏小 10 倍。
对 6 个计数字段统一 round(field * 10),成交额/量/市值不动。
重写 test_get_market_stat_mapping 覆盖还原逻辑。761 单测全绿。
2026-07-02 12:46:27 +08:00
GitHub
155328df8b
release: v1.16.2 — 三轮审计质量加固(B6.9→A7.9)
...
经三轮代码审计后的综合质量加固版本,覆盖协议核心层、数据正确性、
错误处理、测试真实度与可维护性。761 单测全绿(+58),ruff/mypy 全过。
主要修复:
- 离线 .day 写入原子化(fsync + _repair_tail + 读取校验,CQS 守住)
- 回测止损前视偏差(延迟下一根开盘 + 跳空保护)
- VWAP 权重索引 / bar_time fail-fast / 绩效除零保护
- 闭包绑定 / 路径穿越 / naive datetime 跨时区 / ruff UP038
重构:
- 抽 AsyncHeartbeatMixin 收敛 4 处心跳副本(12→1)
- 统一 _RETRY_DELAYS 退避序列 / scanner 失败可观测性
新增 5 个测试文件 + 公共 API 类型契约,CI 加 Windows 矩阵 +
trusted publishing 签名 + 锁文件。
详见 CHANGELOG.md
2026-07-02 03:37:37 +08:00
GitHub
615994ad72
feat(kline): 分钟级K线时间戳可选bar_time对齐Tushare (Discussion #7 )
...
通达信协议用bar开始时间打时间戳(5min线上午最后一根标11:25、下午第一根标13:00;午休11:30-13:00无bar),而Tushare/同花顺/聚宽用bar结束时间(标11:30/13:05)。新增bar_time参数让用户一键切换,避免自行+5分钟偏移。
- 全部3条K线路径覆盖:A股get_security_bars/get_index_bars、扩展行情get_instrument_bars、MAC get_stock_kline(含同步+异步、get_stock_kline_with_indicators)
- CLI kline新增--bar-time {start,end}选项;Web /bars、/bars/index新增bar_time查询参数
- bar_time=start(默认)保持完全向后兼容;bar_time=end仅对分钟级周期(1/5/15/30/60min)生效,自动按周期时长右移并处理跨小时/跨日边界
- 协议解码层零改动,偏移作为纯展示语义在client层后处理,单一工具函数_apply_bar_time_align_df/_apply_bar_time_align_bars复用于全部路径
- 新增27个单元测试(test_codec_datetime.py偏移逻辑 + test_kline_bar_time.py三路径覆盖),全量700单测通过
- bump 版本号至 1.16.0
2026-06-30 15:02:27 +08:00
GitHub and Claude Opus 4.8
4dfd18050e
fix: resolve all CI mypy (265→0) and ruff (26→0) errors
...
- pyproject.toml: add mypy overrides for pandas/tabulate/matplotlib stubs,
disable strict checking for vendored MyTT library
- config.py: use cast() for dict[str, Any] .get() returns
- beichi.py: widen _calc_bi_force param to BI | XD, import XD
- backtest/cli.py: split combo/single strategy into separate typed variables
- backtest/combo.py: add bool_array() helper for numpy return types
- chanlun/analyser.py: type ignore for pandas row access, fix dict type arg
- unified.py: change fields param from object to Any
- ex/mac_client.py: add type args to list literals
- cli/cmd_offline.py: wrap int market as Market enum before API call
- cli/cmd_chanlun.py: fix dict type arg
- offline/write_*.py: explicit int() cast for struct.unpack returns
- MyTT.py: fix line-too-long comments, UP038 isinstance syntax
- tests: fix E712 (==False → ~mask), E741 (noqa), F841, import sorting
- ruff format applied across codebase
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com >
2026-06-10 15:03:41 +08:00
GitHub and Claude Opus 4.7
4820b4a049
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 >
2026-05-22 22:44:45 +08:00
Justin Gu
00825eb24a
feat: merge datetime fields in DataFrame output, hide MinuteBar internal fields
...
- K-line: daily+ periods output 'date' only, minute periods output 'datetime'
- Transactions (tick-by-tick): combine date param + hour/minute into 'datetime'
- XdxrRecord, HistoricalFundFlow: year/month/day merged to 'date'
- MinuteBar: rename unknown_1 to _unknown_1 (hidden from DataFrame)
- MinuteBar: add datetime column computed from bar index (A-share 240-bar pattern)
- get_minute_time_data: use history endpoint only (current-day endpoint broken in pytdx too)
- Update all examples to reflect new DataFrame column names
2026-05-22 04:19:07 +08:00
GitHub and Claude 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