Files
daily_stock_analysis/data_provider/__init__.py
DragonL641 51e7337882 feat: add Finnhub & AlphaVantage US market data source adapters (#1313)
* feat: add Finnhub and AlphaVantage API key config fields

* feat: add FinnhubFetcher for US market OHLCV and realtime quotes

* feat: add AlphaVantageFetcher for US market OHLCV and realtime quotes

* feat: register FinnhubFetcher and AlphaVantageFetcher in DataFetcherManager

* fix: address PR review feedback on US fetcher routing and AlphaVantage pct_chg

- Fix AlphaVantage pct_chg calculation: sort by date ascending before
  computing percentage change to handle newest-first API response
- Extend US daily routing source_order to include FinnhubFetcher and
  AlphaVantageFetcher in the failover chain
- Add newest-first pct_chg regression test for AlphaVantage
- Add US routing fallback order test
- Update CHANGELOG.md with new feature and fix entries
- Add docs/specs/ to .gitignore to prevent accidental commits

Verified: 1956 tests passed, ci_gate.sh clean

* fix: address third round PR review - routing gaps, index isolation, CHANGELOG cleanup

- Isolate US index routing: YFinance-first, skip Finnhub/AlphaVantage for index codes
- Add Finnhub/AlphaVantage to US realtime_quote and get_stock_name routing
- Clean CHANGELOG.md: only our 3 Finnhub/AlphaVantage entries in [Unreleased]
2026-05-17 21:24:34 +08:00

63 lines
2.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
"""
===================================
数据源策略层 - 包初始化
===================================
本包实现策略模式管理多个数据源,实现:
1. 统一的数据获取接口
2. 自动故障切换
3. 防封禁流控策略
数据源优先级(动态调整):
【配置了 TUSHARE_TOKEN 时】
1. TushareFetcher (Priority 0) - 🔥 最高优先级(动态提升)
2. EfinanceFetcher (Priority 0) - 同优先级
3. AkshareFetcher (Priority 1) - 来自 akshare 库
4. PytdxFetcher (Priority 2) - 来自 pytdx 库(通达信)
5. BaostockFetcher (Priority 3) - 来自 baostock 库
6. YfinanceFetcher (Priority 4) - 来自 yfinance 库
【未配置 TUSHARE_TOKEN 时】
1. EfinanceFetcher (Priority 0) - 最高优先级,来自 efinance 库
2. AkshareFetcher (Priority 1) - 来自 akshare 库
3. PytdxFetcher (Priority 2) - 来自 pytdx 库(通达信)
4. TushareFetcher (Priority 2) - 来自 tushare 库(不可用)
5. BaostockFetcher (Priority 3) - 来自 baostock 库
6. YfinanceFetcher (Priority 4) - 来自 yfinance 库
7. LongbridgeFetcher (Priority 5) - 长桥 OpenAPI美股/港股兜底)
提示:优先级数字越小越优先,同优先级按初始化顺序排列
"""
from .base import BaseFetcher, DataFetcherManager
from .efinance_fetcher import EfinanceFetcher
from .akshare_fetcher import AkshareFetcher, is_hk_stock_code
from .tushare_fetcher import TushareFetcher
from .pytdx_fetcher import PytdxFetcher
from .baostock_fetcher import BaostockFetcher
from .yfinance_fetcher import YfinanceFetcher
from .longbridge_fetcher import LongbridgeFetcher
from .finnhub_fetcher import FinnhubFetcher
from .alphavantage_fetcher import AlphaVantageFetcher
from .us_index_mapping import is_us_index_code, is_us_stock_code, get_us_index_yf_symbol, US_INDEX_MAPPING
__all__ = [
'BaseFetcher',
'DataFetcherManager',
'EfinanceFetcher',
'AkshareFetcher',
'TushareFetcher',
'PytdxFetcher',
'BaostockFetcher',
'YfinanceFetcher',
'LongbridgeFetcher',
'FinnhubFetcher',
'AlphaVantageFetcher',
'is_us_index_code',
'is_us_stock_code',
'is_hk_stock_code',
'get_us_index_yf_symbol',
'US_INDEX_MAPPING',
]