增加K线
This commit is contained in:
@@ -10,6 +10,7 @@ from .config import ROOT_DIR, settings
|
||||
from .funding_store import get_funding_bundle
|
||||
from .kline_store import get_candles, get_daily_candles, sync_daily_klines, sync_klines
|
||||
from .chart_intervals import CHART_INTERVALS, limit_for_interval, validate_interval
|
||||
from .binance import binance_client
|
||||
from .db import get_latest_snapshot, init_db, log_push, save_snapshot
|
||||
from .exceptions import BinanceRateLimitedError
|
||||
from .period_api import get_period_top30
|
||||
@@ -28,6 +29,14 @@ logging.getLogger("httpx").setLevel(logging.WARNING)
|
||||
logging.getLogger("httpcore").setLevel(logging.WARNING)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def _chart_price_meta(sym: str) -> dict:
|
||||
try:
|
||||
return await binance_client.get_symbol_price_meta(sym)
|
||||
except Exception as e:
|
||||
logger.warning("price meta %s fallback: %s", sym, e)
|
||||
return {"tick_size": "0.01", "price_precision": 2}
|
||||
|
||||
WEB_DIR = ROOT_DIR / "web"
|
||||
|
||||
|
||||
@@ -165,6 +174,7 @@ async def api_chart(
|
||||
candles, source = await get_candles(
|
||||
sym, iv, limit or default_limit, force_refresh=refresh
|
||||
)
|
||||
price_meta = await _chart_price_meta(sym)
|
||||
return {
|
||||
"symbol": sym,
|
||||
"interval": iv,
|
||||
@@ -172,6 +182,7 @@ async def api_chart(
|
||||
"candles": candles,
|
||||
"source": source,
|
||||
"intervals": list(CHART_INTERVALS),
|
||||
**price_meta,
|
||||
}
|
||||
except BinanceRateLimitedError as e:
|
||||
raise HTTPException(503, f"币安限流,请 {e.retry_after_sec} 秒后再试") from e
|
||||
@@ -188,6 +199,7 @@ async def api_chart_daily(symbol: str, limit: int | None = None, refresh: bool =
|
||||
raise HTTPException(400, "invalid symbol")
|
||||
try:
|
||||
candles, source = await get_daily_candles(sym, limit, force_refresh=refresh)
|
||||
price_meta = await _chart_price_meta(sym)
|
||||
return {
|
||||
"symbol": sym,
|
||||
"interval": "1d",
|
||||
@@ -195,6 +207,7 @@ async def api_chart_daily(symbol: str, limit: int | None = None, refresh: bool =
|
||||
"candles": candles,
|
||||
"source": source,
|
||||
"intervals": list(CHART_INTERVALS),
|
||||
**price_meta,
|
||||
}
|
||||
except BinanceRateLimitedError as e:
|
||||
raise HTTPException(503, f"币安限流,请 {e.retry_after_sec} 秒后再试") from e
|
||||
|
||||
Reference in New Issue
Block a user