fix(hub): 修复币安行情区 unexpected base 价格精度

normalize_price_tick 对齐 tick 为 10^-n;chart.js 使用整数 base 并在 applyOptions 失败时回退安全 priceFormat。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-03 17:36:51 +08:00
parent c56326734e
commit 2d8f65bf1d
3 changed files with 75 additions and 33 deletions
+21 -1
View File
@@ -139,6 +139,26 @@ def price_tick_from_market(exchange, exchange_symbol: str) -> Optional[float]:
return None
def normalize_price_tick(tick: Optional[float]) -> Optional[float]:
"""将 tick 对齐为 10^-n,避免浮点噪声导致前端 lightweight-charts unexpected base。"""
if tick is None:
return None
try:
t = float(tick)
except (TypeError, ValueError):
return None
if t <= 0:
return None
if t >= 1:
return t
try:
exp = int(round(-math.log10(t)))
except (ValueError, OverflowError):
return None
exp = max(0, min(12, exp))
return 10 ** (-exp)
def _decimals_from_tick(tick: float) -> int:
if tick >= 1:
return 0
@@ -413,7 +433,7 @@ def fetch_ohlcv_for_hub(
if not merged:
return {"ok": False, "msg": "交易所未返回 K 线"}
tick = price_tick_from_market(exchange, ex_sym)
tick = normalize_price_tick(price_tick_from_market(exchange, ex_sym))
return {
"ok": True,