From c645178f7beaeaeba2048cd8fb94ed3cc72ba6bc Mon Sep 17 00:00:00 2001 From: root Date: Tue, 3 Mar 2026 12:45:36 +0000 Subject: [PATCH] fix: H4 - restrict /api/kline to BTC/ETH, return 400 for XRP/SOL --- backend/main.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/backend/main.py b/backend/main.py index 42082a2..dea97aa 100644 --- a/backend/main.py +++ b/backend/main.py @@ -142,14 +142,21 @@ async def get_snapshots(hours: int = 24, limit: int = 5000, user: dict = Depends @app.get("/api/kline") async def get_kline(symbol: str = "BTC", interval: str = "5m", limit: int = 500, user: dict = Depends(get_current_user)): + symbol_upper = symbol.upper() + supported = {"BTC", "ETH"} + if symbol_upper not in supported: + raise HTTPException( + status_code=400, + detail=f"K线数据仅支持 BTC / ETH,暂不支持 {symbol_upper}。XRP/SOL 的 K 线功能在 V5.3 中规划。" + ) interval_secs = { "1m": 60, "5m": 300, "30m": 1800, "1h": 3600, "4h": 14400, "8h": 28800, "1d": 86400, "1w": 604800, "1M": 2592000, } bar_secs = interval_secs.get(interval, 300) - rate_col = "btc_rate" if symbol.upper() == "BTC" else "eth_rate" - price_col = "btc_price" if symbol.upper() == "BTC" else "eth_price" + rate_col = "btc_rate" if symbol_upper == "BTC" else "eth_rate" + price_col = "btc_price" if symbol_upper == "BTC" else "eth_price" since = int(time.time()) - bar_secs * limit rows = await async_fetch(