fix(hub): 修复行情区 K 线 Gate 分页与图表 unexpected base
Gate OHLCV 分页在接近当前时间时停止并容错 from>to;分页失败时用 limit 兜底。chart.js 为 priceFormat 增加整数 base,setData 失败时回退默认精度。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1013,7 +1013,18 @@
|
||||
const minMove =
|
||||
tick != null && Number.isFinite(Number(tick)) && Number(tick) > 0 ? Number(tick) : 0.01;
|
||||
const precision = decimalsFromTick(minMove) ?? 2;
|
||||
return { type: "price", precision: precision, minMove: minMove };
|
||||
const fmt = { type: "price", precision: precision, minMove: minMove };
|
||||
// 避免 minMove 浮点导致 lightweight-charts 报 "unexpected base"
|
||||
if (minMove > 0 && minMove < 1) {
|
||||
const inv = 1 / minMove;
|
||||
if (Number.isFinite(inv) && inv >= 1 && inv <= 1e15) {
|
||||
const base = Math.round(inv);
|
||||
if (base > 0 && Math.abs(inv - base) / Math.max(inv, 1) < 1e-6) {
|
||||
fmt.base = base;
|
||||
}
|
||||
}
|
||||
}
|
||||
return fmt;
|
||||
}
|
||||
|
||||
function applyChartPriceFormat() {
|
||||
@@ -1507,8 +1518,15 @@
|
||||
applyChartPriceFormat();
|
||||
lastCandles = data.candles;
|
||||
indexCandles(lastCandles);
|
||||
candleSeries.setData(lastCandles);
|
||||
volumeSeries.setData(buildVolumeData(lastCandles));
|
||||
try {
|
||||
candleSeries.setData(lastCandles);
|
||||
volumeSeries.setData(buildVolumeData(lastCandles));
|
||||
} catch (setErr) {
|
||||
priceTick = null;
|
||||
applyChartPriceFormat();
|
||||
candleSeries.setData(lastCandles);
|
||||
volumeSeries.setData(buildVolumeData(lastCandles));
|
||||
}
|
||||
applyChartRightGap();
|
||||
if (resetView) {
|
||||
lastViewKey = vKey;
|
||||
|
||||
Reference in New Issue
Block a user