feat(api): 为美股/港股数据添加 stock info 信息
- 在 universal_fetcher._fetch_yfinance 中获取公司信息 - 包含 sector、industry、market_cap 字段 - 将信息存储在 DataFrame.attrs 中 - Flask API 自动提取并返回 info 字段
This commit is contained in:
@@ -232,7 +232,8 @@ def dataframe_to_json(df: pd.DataFrame) -> Dict:
|
||||
# 转换为字典列表
|
||||
records = df_reset.to_dict(orient='records')
|
||||
|
||||
return {
|
||||
# 构建返回结果
|
||||
result = {
|
||||
"data": records,
|
||||
"count": len(records),
|
||||
"columns": list(df_reset.columns),
|
||||
@@ -241,6 +242,12 @@ def dataframe_to_json(df: pd.DataFrame) -> Dict:
|
||||
"end": df.index.max().strftime('%Y-%m-%d') if hasattr(df.index.max(), 'strftime') else str(df.index.max()),
|
||||
} if len(df) > 0 else None
|
||||
}
|
||||
|
||||
# 添加股票信息(如果存在)
|
||||
if hasattr(df, 'attrs') and df.attrs.get('info'):
|
||||
result['info'] = df.attrs['info']
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def validate_date(date_str: str) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user