Skip to content

fix(market): route 5xxxxx ETF codes to Shanghai exchange prefix#16

Merged
ShuhaoQing merged 2 commits into
mainfrom
fix/etf-56-prefix-routing
Apr 13, 2026
Merged

fix(market): route 5xxxxx ETF codes to Shanghai exchange prefix#16
ShuhaoQing merged 2 commits into
mainfrom
fix/etf-56-prefix-routing

Conversation

@ShuhaoQing

Copy link
Copy Markdown
Owner

Summary

  • 56xxxx cross-market ETFs (e.g. 563020 红利低波) were routed with sz prefix on Sina/Tencent quote APIs, hitting a different security (bond "新疆2437") and returning price=100.0 instead of ~1.19
  • This caused guardrails alerts to report 8303% phantom gains for 563020
  • Fix: all 5xxxxx codes (51/56 ETFs, 50 funds) now route to sh (Shanghai) prefix via a shared _is_sh() helper, applied to market_prefix, secid, and exchange_prefix

Root cause

market_prefix() only checked for 6/9 prefixes → sh, everything else → sz. But 56xxxx ETFs are cross-market products that route via Shanghai on Sina/Tencent quote APIs. Using sz563020 returns a bond ("新疆2437", price=100), not the ETF.

Test plan

  • 25 new parametrized unit tests covering all A-share code ranges (6xx/68x/51x/56x/000/002/300/15x)
  • Full test suite: 381 passed, 0 failed
  • Verified via curl: sh563020 returns correct price=1.188 on both Sina and Tencent APIs

🤖 Generated with Claude Code

Shuhao Qing and others added 2 commits April 13, 2026 23:09
56xxxx cross-market ETFs (e.g. 563020 红利低波) were incorrectly routed
with 'sz' prefix on Sina/Tencent APIs, hitting a different security
(bond "新疆2437") and returning price=100.0 instead of ~1.19. This
caused guardrails alerts to report 8303% phantom gains.

All 5xxxxx codes (51/56 ETFs, 50 funds) belong to Shanghai exchange on
quote APIs. Extract _is_sh() helper and include '5' prefix alongside
'6' and '9'.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Address code review feedback:
- Remove secid() which had no consumers in application code
- Add 900001 (Shanghai B-share) test case for complete _is_sh() coverage

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ShuhaoQing ShuhaoQing merged commit 650527b into main Apr 13, 2026
1 check passed
@ShuhaoQing ShuhaoQing deleted the fix/etf-56-prefix-routing branch April 13, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant