增加资金费率
This commit is contained in:
+18
-1
@@ -8,6 +8,7 @@ from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from .aggregator import aggregate_period, enrich_snapshot_meta
|
||||
from .config import ROOT_DIR, settings
|
||||
from .funding_store import enrich_items_with_funding, get_funding_bundle
|
||||
from .kline_store import get_daily_candles, sync_daily_klines
|
||||
from .db import get_latest_snapshot, init_db, log_push
|
||||
from .exceptions import BinanceRateLimitedError
|
||||
@@ -62,6 +63,7 @@ async def index():
|
||||
async def api_yesterday_top30():
|
||||
snap = get_latest_snapshot("yesterday")
|
||||
if snap:
|
||||
items = await enrich_items_with_funding(snap["items"])
|
||||
return {
|
||||
"period_start": snap["period_start"],
|
||||
"period_end": snap["period_end"],
|
||||
@@ -69,7 +71,7 @@ async def api_yesterday_top30():
|
||||
"top_n": settings.top_n,
|
||||
"volume_threshold": settings.volume_threshold,
|
||||
"change_threshold": settings.change_threshold,
|
||||
"items": snap["items"],
|
||||
"items": items,
|
||||
}
|
||||
start, end = get_yesterday_period()
|
||||
try:
|
||||
@@ -87,6 +89,7 @@ async def api_yesterday_top30():
|
||||
async def api_today_top30():
|
||||
cached = get_today_cache()
|
||||
if cached:
|
||||
cached["items"] = await enrich_items_with_funding(cached.get("items", []))
|
||||
return cached
|
||||
start, end = get_today_period()
|
||||
try:
|
||||
@@ -154,6 +157,20 @@ async def api_chart_daily(symbol: str, limit: int | None = None, refresh: bool =
|
||||
raise HTTPException(502, "K线获取失败") from e
|
||||
|
||||
|
||||
@app.get("/api/funding/{symbol}/history")
|
||||
async def api_funding_history(symbol: str, limit: int | None = None, refresh: bool = False):
|
||||
sym = symbol.upper().strip()
|
||||
if not sym.endswith("USDT"):
|
||||
raise HTTPException(400, "invalid symbol")
|
||||
try:
|
||||
return await get_funding_bundle(sym, limit, force_refresh=refresh)
|
||||
except BinanceRateLimitedError as e:
|
||||
raise HTTPException(503, f"币安限流,请 {e.retry_after_sec} 秒后再试") from e
|
||||
except Exception as e:
|
||||
logger.error("funding %s failed: %s", sym, e)
|
||||
raise HTTPException(502, "资金费率获取失败") from e
|
||||
|
||||
|
||||
@app.post("/api/chart/{symbol}/daily/refresh")
|
||||
async def api_chart_daily_refresh(symbol: str, limit: int | None = None):
|
||||
"""强制从币安同步日 K 到本地库。"""
|
||||
|
||||
Reference in New Issue
Block a user