stock-ai-agent/backend/app/skills/fundamental.py
2026-02-03 10:08:15 +08:00

62 lines
1.6 KiB
Python

"""
基本面分析技能
提供股票基本信息查询
"""
from typing import Dict, Any
from app.skills.base import BaseSkill, SkillParameter
from app.services.tushare_service import tushare_service
from app.services.cache_service import cache_service
from app.utils.logger import logger
class FundamentalSkill(BaseSkill):
"""基本面分析技能"""
def __init__(self):
super().__init__()
self.name = "fundamental"
self.description = "查询股票基本面信息(公司概况、行业、上市日期等)"
self.parameters = [
SkillParameter(
name="stock_code",
type="string",
description="股票代码",
required=True
)
]
async def execute(self, **kwargs) -> Dict[str, Any]:
"""
执行基本面查询
Args:
stock_code: 股票代码
Returns:
基本面信息
"""
stock_code = kwargs.get("stock_code")
logger.info(f"查询基本面信息: {stock_code}")
# 尝试从缓存获取
cache_key = f"fundamental:{stock_code}"
cached_data = cache_service.get(cache_key)
if cached_data:
logger.info(f"从缓存获取基本面信息: {stock_code}")
return cached_data
# 从Tushare获取
basic_info = tushare_service.get_stock_basic(stock_code)
if not basic_info:
return {
"error": f"未找到股票基本信息: {stock_code}"
}
# 缓存1天
cache_service.set(cache_key, basic_info, ttl=86400)
return basic_info