feat: Flask统一数据服务迁移(分层架构)
架构设计: - 对外统一接口 fetch():自动识别资产类型并路由 - 对内分层实现:各资产类型独立方法,职责单一 新增文件: - datasource/universal_fetcher.py: 统一数据获取器 - _fetch_china_index: A股指数(Tushare) - _fetch_china_etf: A股ETF(含净值) - _fetch_us_index: 美股指数(YFinance+SSH) - _fetch_hk_index: 港股指数(YFinance+SSH) - _fetch_futures: 期货(Tushare/YFinance) - fetch_etf_with_nav: ETF价格+净值(计算溢价率) - datasource/asset_type_detector.py: 资产类型检测器 - AssetType枚举:9种资产类型 - detect(): 自动识别资产类型 - group_by_type(): 批量分组 - datasource/flask_server.py: Flask API服务 - LRU + TTL 双缓存机制 - 8个API端点:ohlcv、etf/nav、batch、cache等 更新: - datasource/__init__.py: 导出新模块 验证: - 模块导入成功 - 资产类型检测正确 - A股数据获取正常(沪深300: 5条)
This commit is contained in:
@@ -4,16 +4,31 @@
|
||||
核心数据获取能力:
|
||||
- A股数据:Tushare(指数、ETF、期货)
|
||||
- 境外数据:YFinance(港股、美股)通过SSH隧道
|
||||
|
||||
架构设计:
|
||||
- 分层架构:对外统一接口,对内各资产类型独立实现
|
||||
- Flask API:LRU + TTL 双缓存机制
|
||||
|
||||
用法:
|
||||
from datasource import UniversalDataFetcher, AssetType
|
||||
|
||||
fetcher = UniversalDataFetcher()
|
||||
df = fetcher.fetch("000300.SH", "2024-01-01", "2024-12-31")
|
||||
"""
|
||||
|
||||
from .ssh_tunnel import SSHTunnelManager
|
||||
from .tushare_source import TushareSource
|
||||
from .yfinance_source import YFinanceSource
|
||||
from .hybrid_source import HybridDataSource
|
||||
from .asset_type_detector import AssetTypeDetector, AssetType
|
||||
from .universal_fetcher import UniversalDataFetcher
|
||||
|
||||
__all__ = [
|
||||
'SSHTunnelManager',
|
||||
'TushareSource',
|
||||
'YFinanceSource',
|
||||
'HybridDataSource',
|
||||
'AssetTypeDetector',
|
||||
'AssetType',
|
||||
'UniversalDataFetcher',
|
||||
]
|
||||
Reference in New Issue
Block a user