Skip to content

refactor: remove akshare, use direct Sina/Tencent/eastmoney APIs#10

Merged
ShuhaoQing merged 7 commits into
mainfrom
refactor/remove-akshare
Apr 3, 2026
Merged

refactor: remove akshare, use direct Sina/Tencent/eastmoney APIs#10
ShuhaoQing merged 7 commits into
mainfrom
refactor/remove-akshare

Conversation

@ShuhaoQing

@ShuhaoQing ShuhaoQing commented Apr 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • Remove akshare dependency — replace all 6 akshare function calls with direct API calls to Sina, Tencent, and eastmoney web endpoints, eliminating unstable push2.eastmoney.com dependency
  • New market/sources/ architecture — split by data source (sina.py, tencent.py, eastmoney.py) with shared utilities in _common.py for long-term maintainability
  • New eastmoney datacenter financial indicators APIget_financial_indicators() using datacenter-web.eastmoney.com RPT_LICO_FN_CPD report (ROE, gross margin, computed profit margin)
  • Rename AKShareProviderAShareProvider — all references updated across CLI, analysis, and tests

Source Priority

Function Primary Fallback
current_price Sina hq.sinajs.cn Tencent qt.gtimg.cn
price_history Tencent web.ifzq.gtimg.cn
basic_info eastmoney emweb + Tencent valuation
financial_indicators eastmoney datacenter graceful fail
sector_list Sina newSinaHy.php
sector_constituents Sina getHQNodeData

Test Plan

  • 263 unit tests pass (pytest -m "not integration")
  • Lint and format clean (ruff check . && ruff format --check .)
  • Integration tests with real APIs (pytest -m integration)
  • grep -r "akshare" haoinvest/ tests/ pyproject.toml returns nothing

🤖 Generated with Claude Code

Shuhao Qing and others added 7 commits April 3, 2026 12:17
Move existing direct-API implementations into dedicated source modules
(sina.py, tencent.py, eastmoney.py) under market/sources/. Shared
utilities (parse_float, market_prefix, bypass_proxy, etc.) go into
_common.py. No callers changed yet — akshare_provider.py still works.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add get_financial_indicators() to eastmoney source module, using the
datacenter-web.eastmoney.com RPT_LICO_FN_CPD report for ROE, gross
margin, and computed profit margin. Gracefully returns empty dict on
failure. Includes unit tests with mocked API responses.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace all akshare imports with calls to source modules:
- current_price: Sina (primary) + Tencent (fallback)
- price_history: Tencent
- basic_info: eastmoney CompanySurvey + Tencent valuation + eastmoney datacenter financial indicators
- sector: Sina

No more `import akshare` in the codebase. Updated contract tests to
mock source modules instead of akshare.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Rename akshare_provider.py -> ashare_provider.py and class
AKShareProvider -> AShareProvider. Update all imports and mock paths
across CLI, analysis, and test files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove akshare from pyproject.toml and update lockfile. Update all
documentation (CLAUDE.md, README.md) and config to reflect the switch
to direct Sina/Tencent/eastmoney APIs. Rename AKSHARE_TIMEOUT config
to API_TIMEOUT.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add unit tests for each source module:
- test_sina.py: current price, sector list, sector constituents
- test_tencent.py: current price, price history, valuation
- test_eastmoney.py: basic info, financial indicators

Expand integration tests with financial indicators, sector list,
and sector constituents. Fix unused import and format issues.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Use Sina sector name "酿酒行业" instead of eastmoney's "白酒" in
  sector constituents test
- Fix fundamental test to match actual output key "Overall_Valuation"
  (pre-existing issue on main)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ShuhaoQing ShuhaoQing merged commit e2aa8cc into main Apr 3, 2026
1 check passed
@ShuhaoQing ShuhaoQing deleted the refactor/remove-akshare branch April 3, 2026 05:07
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