fix: H4 - restrict /api/kline to BTC/ETH, return 400 for XRP/SOL
This commit is contained in:
parent
3172300fd0
commit
c645178f7b
@ -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(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user