feat: 接入同花顺官方SDK,新增v2数据接口,股票详情K线改用v2(前复权日K)
- vendor 同花顺官方 SDK 到 backend/sdk(含K线>10年自动切片、重试、拼音首字母检索兜底) - 新增 /api/v2 路由:行情/估值/财务/日历/指数/K线/标的检索 - 股票详情页K线改用 v2 同花顺接口(前复权日K+总手+按昨收涨跌幅) - 密钥仅后端持有,响应/日志无泄露 - 新增 run_local.sh 本地直接拉起(不再依赖 docker)
This commit is contained in:
+10
-2
@@ -7,7 +7,7 @@ from contextlib import asynccontextmanager
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from database import init_db
|
||||
from routes import stock, collections, shares, themes, core_stocks
|
||||
from routes import stock, collections, shares, themes, core_stocks, fuyao
|
||||
from services.daily_collector import collector_loop, cache_cleanup_loop
|
||||
|
||||
load_dotenv()
|
||||
@@ -45,18 +45,26 @@ app.include_router(collections.router, prefix="/api/collections")
|
||||
app.include_router(shares.router, prefix="/api/share")
|
||||
app.include_router(themes.router, prefix="/api/themes")
|
||||
app.include_router(core_stocks.router, prefix="/api/core-stocks")
|
||||
app.include_router(fuyao.router, prefix="/api/v2")
|
||||
|
||||
# 生产模式:后端同时托管前端静态文件
|
||||
# catch-all 路由在 API 路由之后注册,所以 API 优先级更高
|
||||
dist_path = os.path.join(os.path.dirname(__file__), "dist")
|
||||
|
||||
# HTML 不缓存:保证 index.html 永远最新(引用的资源文件名带 hash,可长缓存)
|
||||
_NO_CACHE_HTML = {"Cache-Control": "no-cache, no-store, must-revalidate"}
|
||||
|
||||
if os.path.isdir(dist_path):
|
||||
@app.get("/{full_path:path}")
|
||||
async def serve_spa(full_path: str):
|
||||
file_path = os.path.join(dist_path, full_path) if full_path else os.path.join(dist_path, "index.html")
|
||||
if os.path.isfile(file_path):
|
||||
# 静态资源(带 hash 的文件名)可缓存;HTML 不缓存
|
||||
if file_path.endswith(".html"):
|
||||
return FileResponse(file_path, headers=_NO_CACHE_HTML)
|
||||
return FileResponse(file_path)
|
||||
# SPA fallback: 非文件路径统一返回 index.html
|
||||
index_path = os.path.join(dist_path, "index.html")
|
||||
if os.path.isfile(index_path):
|
||||
return FileResponse(index_path, media_type="text/html")
|
||||
return FileResponse(index_path, media_type="text/html", headers=_NO_CACHE_HTML)
|
||||
return JSONResponse({"detail": "Not Found"}, status_code=404)
|
||||
|
||||
Reference in New Issue
Block a user