feat(api): 为美股/港股数据添加 stock info 信息

- 在 universal_fetcher._fetch_yfinance 中获取公司信息
- 包含 sector、industry、market_cap 字段
- 将信息存储在 DataFrame.attrs 中
- Flask API 自动提取并返回 info 字段
This commit is contained in:
2026-05-07 23:45:00 +08:00
parent 270f4fe7f4
commit 7cf20268cf
2 changed files with 26 additions and 1 deletions

View File

@@ -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: