financial.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. """
  2. 智能股票分析助手 — 财务数据API路由
  3. 提供财务指标、公司概况、股东信息查询接口。
  4. """
  5. from fastapi import APIRouter, Query
  6. from app.services import market_service
  7. from app.utils.mx_http import mx_result_to_http
  8. from app.utils.response import error_response
  9. router = APIRouter(prefix="/financial", tags=["财务数据"])
  10. @router.get("/indicators/{code}")
  11. async def get_financial_indicators(
  12. code: str,
  13. indicators: str = Query(default="净利润 营业收入 净资产收益率 每股收益", description="需要的财务指标"),
  14. ):
  15. """获取个股财务指标
  16. - **code**: 6位股票代码
  17. - **indicators**: 财务指标描述(自然语言),如 "净利润 营业收入 ROE"
  18. """
  19. if not code or len(code) < 4:
  20. return error_response(code=400, message="请输入有效的股票代码")
  21. result = market_service.get_stock_financial(code, indicators)
  22. return mx_result_to_http(result)
  23. @router.get("/profile/{code}")
  24. async def get_company_profile(code: str):
  25. """获取公司概况
  26. - **code**: 6位股票代码
  27. """
  28. if not code or len(code) < 4:
  29. return error_response(code=400, message="请输入有效的股票代码")
  30. result = market_service.get_stock_profile(code)
  31. return mx_result_to_http(result)
  32. @router.get("/holders/{code}")
  33. async def get_top_holders(code: str):
  34. """获取十大股东信息
  35. - **code**: 6位股票代码
  36. """
  37. if not code or len(code) < 4:
  38. return error_response(code=400, message="请输入有效的股票代码")
  39. result = market_service.get_stock_holders(code)
  40. return mx_result_to_http(result)