feat: 新增题材页面(列表 + 详情)
- 主页增加「题材热点」入口,跳转题材列表页 - 题材列表页:展示全部题材,支持按涨幅/强度/热度/成交额排序 - 题材详情页:简介、热点事件、相关新闻、板块涨跌统计、全部相关股票(含入选理由默认展开) - 后端逆向封装东方财富题材接口 getThemeList/getDetail/getStockList,含交易时段感知缓存 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
"""题材数据路由:题材列表、题材详情、题材相关股票"""
|
||||
|
||||
from fastapi import APIRouter, Query, HTTPException
|
||||
from fastapi.responses import JSONResponse
|
||||
from services import themes
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
# 上游反代/CDN 可能按 path 缓存,显式禁止缓存
|
||||
_NO_CACHE_HEADERS = {"Cache-Control": "no-store, no-cache, must-revalidate, max-age=0"}
|
||||
|
||||
|
||||
@router.get("", summary="题材列表")
|
||||
async def theme_list(
|
||||
sort_field: int = Query(1, ge=1, le=5, description="排序字段:1=涨幅 3=强度 4=热度排名 5=成交额"),
|
||||
asc: bool = Query(False, description="True=升序, False=降序"),
|
||||
):
|
||||
if sort_field not in (1, 3, 4, 5):
|
||||
raise HTTPException(status_code=400, detail="排序字段仅支持 1/3/4/5")
|
||||
|
||||
data = await themes.fetch_theme_list(sort_field, asc)
|
||||
return JSONResponse(
|
||||
{"data": data, "count": len(data), "sort_field": sort_field, "asc": asc},
|
||||
headers=_NO_CACHE_HEADERS,
|
||||
)
|
||||
|
||||
|
||||
@router.get("/{theme_code}/detail", summary="题材详情")
|
||||
async def theme_detail(theme_code: str):
|
||||
data = await themes.fetch_theme_detail(theme_code)
|
||||
if not data:
|
||||
return JSONResponse(
|
||||
{"data": None, "theme_code": theme_code},
|
||||
headers=_NO_CACHE_HEADERS,
|
||||
)
|
||||
return JSONResponse(
|
||||
{"data": data, "theme_code": theme_code},
|
||||
headers=_NO_CACHE_HEADERS,
|
||||
)
|
||||
|
||||
|
||||
@router.get("/{theme_code}/stocks", summary="题材相关股票(全部)")
|
||||
async def theme_stocks(theme_code: str):
|
||||
result = await themes.fetch_theme_stocks(theme_code)
|
||||
return JSONResponse(
|
||||
{
|
||||
"data": result.get("stockList", []),
|
||||
"statistic": result.get("statistic", {}),
|
||||
"total": result.get("total", 0),
|
||||
"theme_code": theme_code,
|
||||
},
|
||||
headers=_NO_CACHE_HEADERS,
|
||||
)
|
||||
Reference in New Issue
Block a user