feat: 创建数据源模块 datasource/

核心功能:
- ssh_tunnel.py: SSH隧道管理器(连接香港ECS)
- tushare_source.py: A股数据获取(指数、ETF、期货)
- yfinance_source.py: 境外数据获取(港股、美股)
- hybrid_source.py: 混合数据源(整合所有)

使用方式:
  from datasource import HybridDataSource

  source = HybridDataSource.from_yaml('config/strategies/rotation.yaml')
  result = source.fetch_all()

更新 RotationStrategy 使用新数据源模块
This commit is contained in:
2026-05-12 00:03:25 +08:00
parent e6b2c8cfb7
commit e56bd39400
6 changed files with 781 additions and 14 deletions

View File

@@ -106,7 +106,7 @@ class RotationStrategy(StrategyBase):
return group_mapping
def get_data(self) -> dict:
"""获取数据(复用归档的数据源)"""
"""获取数据(使用新数据源模块"""
code_list_config = self.config.get('code_list', {})
benchmark_config = self.config.get('benchmark', {})
benchmark_code = benchmark_config.get('code', '000300.SH')
@@ -114,27 +114,17 @@ class RotationStrategy(StrategyBase):
if not code_list_config:
raise ValueError("配置中未找到 code_list")
# 使用归档的HybridDataSource
from archive.legacy_core.core.datasource.hybrid_source import HybridDataSource
# 使用新数据源模块
from datasource import HybridDataSource
ssh_config = self.config.get('ssh_tunnel', {})
if ssh_config.get('enabled'):
ssh_config = {
'host': ssh_config.get('host'),
'port': ssh_config.get('port', 22),
'username': ssh_config.get('username', 'root'),
'key_path': ssh_config.get('key_path', 'hk_ecs.pem'),
'local_port': ssh_config.get('local_port', 1080)
}
else:
ssh_config = None
data_source = HybridDataSource(
ssh_config=ssh_config,
use_cache=self.config.get('use_cache', True)
)
# 调用 fetch_all(返回元组)
# 调用 fetch_all
index_data, etf_data, etf_nav_data, benchmark_data, valid_codes, index_ohlcv_data = \
data_source.fetch_all(
code_config=code_list_config,