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 |
|