refactor(datasource): 统一数据获取架构,使用 df.attrs 传递元数据

核心改进:
- CCXTSource 添加 df.attrs 支持(source, exchange, symbol, timeframe, adj)
- UniversalDataFetcher 简化透传方法,保留兼容接口
- fetch_etf_with_nav 标记为 deprecated,推荐使用 fetch_etf + df.attrs
- 所有数据源统一契约:返回 DataFrame + df.attrs

架构改进:
- 统一返回单 DataFrame,元数据通过 attrs 传递
- 消除多返回值接口(price_df, nav_df, premium_series)
- 文档注释更新,反映新接口用法
- 添加 DeprecationWarning 提示迁移路径
This commit is contained in:
2026-05-23 23:40:18 +08:00
parent 7446d1b2e8
commit 3619e26bf1
2 changed files with 31 additions and 4 deletions

View File

@@ -212,6 +212,13 @@ class CCXTSource:
# 过滤日期范围
df = df.loc[start_dt:end_dt]
# 添加元数据到 attrs
df.attrs['source'] = 'ccxt'
df.attrs['exchange'] = self.exchange_name
df.attrs['symbol'] = symbol
df.attrs['timeframe'] = tf
df.attrs['adj'] = 'raw'
print(f"✓ 获取成功: {len(df)} 条数据")
return df
@@ -263,6 +270,13 @@ class CCXTSource:
df = df.set_index('date')
df = df[['open', 'high', 'low', 'close', 'volume']]
# 添加元数据到 attrs
df.attrs['source'] = 'ccxt'
df.attrs['exchange'] = self.exchange_name
df.attrs['symbol'] = symbol
df.attrs['timeframe'] = tf
df.attrs['adj'] = 'raw'
# 注意:不再使用 normalize(),保留完整时间精度
return df