Skip to content

Fix HK historical data provider routing - #1232

Merged
ZhuLinsen merged 1 commit into
mainfrom
codex/fix-hk-data-provider-routing
May 9, 2026
Merged

Fix HK historical data provider routing#1232
ZhuLinsen merged 1 commit into
mainfrom
codex/fix-hk-data-provider-routing

Conversation

@ZhuLinsen

@ZhuLinsen ZhuLinsen commented May 8, 2026

Copy link
Copy Markdown
Owner

PR Type

  • fix
  • feat
  • refactor
  • docs
  • chore
  • test

Background And Problem

Issue #1231 reports HK stock 1211.HK returning an obviously wrong price around 30 when BYD H shares should be above 100 HKD. The root cause is that HK daily history still used the generic historical fetcher priority, so built-in providers that do not support HK daily history could receive HK01211 before an HK-capable provider handled it.

Scope Of Change

  • Add market-aware filtering for daily-history fetchers: HK daily requests skip built-in providers that do not support HK daily data, such as efinance, pytdx, and baostock.
  • Keep a defensive efinance-level guard so direct calls also reject HK daily history instead of hitting the Eastmoney historical K-line path.
  • Document the HK daily routing behavior in docs/full-guide.md, docs/full-guide_EN.md, and docs/CHANGELOG.md.
  • Add offline regression tests for HK routing and efinance HK rejection.

Issue Link

Fixes #1231

Verification Commands And Results

python -m py_compile data_provider/base.py data_provider/efinance_fetcher.py tests/test_fetcher_logging.py
python -m pytest tests/test_fetcher_logging.py -q
./scripts/ci_gate.sh

Key output / conclusion:

  • Targeted pytest: 5 passed in 0.54s
  • Backend gate: 1738 passed, 2 deselected, 49 warnings, 154 subtests passed
  • ./scripts/ci_gate.sh: all checks passed

Compatibility And Risk

HK daily history no longer attempts built-in providers known not to support HK daily data before reaching HK-capable providers. This reduces market mismatch risk while keeping normal fallback through AkShare/Tushare/YFinance/Longbridge.

No new runtime configuration is introduced. Unknown custom fetchers are left in the route by default to avoid breaking extension use cases.

Rollback Plan

Revert this PR to restore the previous historical fetcher behavior. No config or data migration rollback is required.

EXTRACT_PROMPT Change (if applicable)

Not applicable.

Checklist

  • 本 PR 有明确动机和业务价值 / This PR has a clear motivation and value
  • 已提供可复现的验证命令与结果 / Reproducible verification commands and results are included
  • 已评估兼容性与风险 / Compatibility and risk have been assessed
  • 已提供回滚方案 / A rollback plan is provided
  • 若涉及用户可见变更,已同步更新相关文档与 docs/CHANGELOG.mdREADME.md 仅在首页级信息变化时更新,细节优先写入 docs/*.md / If user-visible changes are included, relevant docs and docs/CHANGELOG.md are updated; README.md is updated only for homepage-level changes, with details kept in docs/*.md

@github-actions github-actions Bot added configuration data-source documentation Improvements or additions to documentation size/M testing labels May 8, 2026
@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown

🤖 自动审查报告

项目 结果
📊 变更文件 6 个
➕ 新增行数 94 行
➖ 删除行数 3 行
🔍 静态检查 ✅ 通过
🧠 AI 审查 ✅ 已完成

📁 修改的文件

  • 📝 data_provider/base.py (+41/-2)
  • 📝 data_provider/efinance_fetcher.py (+6/-1)
  • 📝 docs/CHANGELOG.md (+1/-0)
  • 📝 docs/full-guide.md (+2/-0)
  • 📝 docs/full-guide_EN.md (+2/-0)
  • 📝 tests/test_fetcher_logging.py (+42/-0)

🧠 AI 代码审查意见

结论: Ready to Merge

结构化审查结果:

  • 必要性通过

  • 关联性通过

  • 类型:建议类型:fix, test, docs

    • PR 描述中已勾选 fixtest。根据文件修改列表 (docs/CHANGELOG.md, docs/full-guide.md, docs/full-guide_EN.md),也涉及了文档更新,因此补充 docs 类型更全面。
  • 描述完整性完整

    • 缺失项:无。PR 描述详细包含了背景、变更范围、验证命令与结果、兼容性与风险评估、回滚方案。特别是对 Python 后端改动所需的 ./scripts/ci_gate.sh 的执行情况及输出也已提供,符合审查要求。
  • 风险级别

    • 关键风险:本次变更通过对港股日线数据源进行更精确的过滤和路由,并增加了防御性检查,旨在修复错误数据,降低了数据获取的市场错配风险。未引入新的运行时配置,对未知自定义 fetcher 保持兼容,且提供了全面测试,风险可控。
  • 必改项:无

  • 建议项:无


💡 提示: 请确保代码已通过本地测试,并遵循项目代码规范。

@ZhuLinsen
ZhuLinsen force-pushed the codex/fix-hk-data-provider-routing branch from 73f58dd to 28f7764 Compare May 8, 2026 14:16
@ZhuLinsen
ZhuLinsen marked this pull request as ready for review May 8, 2026 14:33
Copilot AI review requested due to automatic review settings May 8, 2026 14:33
@ZhuLinsen ZhuLinsen changed the title [codex] Fix HK historical data provider routing Fix HK historical data provider routing May 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes incorrect Hong Kong (HK) daily historical price routing by making DataFetcherManager market-aware for daily-history fetcher selection, ensuring HK codes don’t get handled by built-in providers that are known to return mismatched/non-HK data.

Changes:

  • Add HK market filtering for daily-history fetchers in DataFetcherManager to skip incompatible built-in providers before attempting HK-capable ones.
  • Add a defensive guard in EfinanceFetcher to explicitly reject HK daily history when called directly.
  • Add regression tests plus documentation/changelog updates describing the HK daily routing behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
data_provider/base.py Adds market-aware filtering for daily-history fetchers and applies it for HK daily requests before the standard fallback loop.
data_provider/efinance_fetcher.py Rejects HK daily history early to avoid accidental Eastmoney historical K-line calls that can return wrong-market data.
tests/test_fetcher_logging.py Adds offline regression tests verifying HK daily routing skips incompatible built-ins and that efinance rejects HK daily without hitting Eastmoney.
docs/full-guide.md Documents that HK daily history skips incompatible built-in providers and uses HK-capable fallbacks.
docs/full-guide_EN.md English counterpart documentation for HK daily routing behavior.
docs/CHANGELOG.md Adds an [Unreleased] fix entry describing the HK daily provider routing change.

@ZhuLinsen ZhuLinsen left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

评审结论

  • 必要性:通过,修复港股日线可能被不支持港股的内置数据源错误接收并返回错配价格的问题,动机明确。
  • 是否有对应 issue:有,Fixes #1231
  • PR 类型:fix/test/docs,核心是修复港股历史数据源路由,并补充离线回归测试与中英文文档/CHANGELOG。
  • description 完整性:完整,已覆盖问题背景、根因、改动范围、验证命令与结果、兼容性风险、回滚方案和 EXTRACT_PROMPT 说明,符合 AGENTS.md 对 fix 类 PR 的交付要求。
  • 是否可直接合入:可,当前 CI 为 success,backend-gateai-governance 已通过;mergeable_state=blocked 在本仓库规则下不单独构成阻断。

🤖 此回复由 OpenReview Bot 自动生成,仅供参考。如有疑问请 @维护者。

@ZhuLinsen
ZhuLinsen merged commit 7bb7dc9 into main May 9, 2026
14 checks passed
cwjyu pushed a commit to cwjyu/daily_stock_analysis that referenced this pull request May 10, 2026
zbl-96 pushed a commit to zbl-96/daily_stock_analysis that referenced this pull request May 10, 2026
EchoingFootsteps pushed a commit to EchoingFootsteps/daily_stock_analysis that referenced this pull request Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 默认的数据源优先级在分析港股是会遇到拿错数据的问题,需要能通过配置关闭

2 participants