diff --git a/lib/common/static/hedge_plan.js b/lib/common/static/hedge_plan.js index a567855..5ca1baa 100644 --- a/lib/common/static/hedge_plan.js +++ b/lib/common/static/hedge_plan.js @@ -45,7 +45,9 @@ let decimals = 0; if (tick < 1) decimals = Math.max(0, -Math.round(Math.log10(tick))); else if (String(tick).indexOf(".") >= 0) decimals = String(tick).split(".")[1].length; - let s = n.toFixed(decimals).replace(/\.?0+$/, ""); + let s = n.toFixed(decimals); + // 仅裁小数尾零;整数 tick(BTC=5)时绝不能把 1370 裁成 137 + if (decimals > 0) s = s.replace(/\.?0+$/, ""); return s || "0"; } diff --git a/lib/common/static/options_panel.js b/lib/common/static/options_panel.js index 9b89753..3737578 100644 --- a/lib/common/static/options_panel.js +++ b/lib/common/static/options_panel.js @@ -48,7 +48,9 @@ let decimals = 0; if (tick < 1) decimals = Math.max(0, -Math.round(Math.log10(tick))); else if (String(tick).indexOf(".") >= 0) decimals = String(tick).split(".")[1].length; - let s = n.toFixed(decimals).replace(/\.?0+$/, ""); + let s = n.toFixed(decimals); + // 仅裁小数尾零;整数 tick(BTC=5)时绝不能把 1370 裁成 137 + if (decimals > 0) s = s.replace(/\.?0+$/, ""); return s || "0"; } diff --git a/lib/common/static/options_position_cards.js b/lib/common/static/options_position_cards.js index 5c164a9..7bba252 100644 --- a/lib/common/static/options_position_cards.js +++ b/lib/common/static/options_position_cards.js @@ -20,7 +20,10 @@ let decimals = 0; if (tick < 1) decimals = Math.max(0, -Math.round(Math.log10(tick))); else if (String(tick).indexOf(".") >= 0) decimals = String(tick).split(".")[1].length; - return n.toFixed(decimals).replace(/\.?0+$/, "") || "0"; + let s = n.toFixed(decimals); + // 仅裁小数尾零;整数 tick(BTC=5)时绝不能把 1370 裁成 137 + if (decimals > 0) s = s.replace(/\.?0+$/, ""); + return s || "0"; } function fmtUsdc(v) { diff --git a/lib/exchange/okx_options_lib.py b/lib/exchange/okx_options_lib.py index 5287260..11f356f 100644 --- a/lib/exchange/okx_options_lib.py +++ b/lib/exchange/okx_options_lib.py @@ -116,10 +116,14 @@ def format_option_px(px: float, tick_sz: Any) -> str: tick = _safe_float(tick_sz) if tick is None or tick <= 0: return str(px) - decimals = max(0, -int(round(math.log10(tick)))) if tick < 1 else 0 - if tick >= 1: - decimals = len(str(tick).split(".")[-1]) if "." in str(tick) else 0 - return f"{px:.{decimals}f}".rstrip("0").rstrip(".") or "0" + if tick < 1: + decimals = max(0, -int(round(math.log10(tick)))) + return f"{px:.{decimals}f}".rstrip("0").rstrip(".") or "0" + # tick>=1(如 BTC 期权 tickSz=5):只按整数展示,禁止 rstrip('0') 把 1370 变成 137 + if "." in str(tick): + decimals = len(str(tick).split(".")[-1]) + return f"{px:.{decimals}f}".rstrip("0").rstrip(".") or "0" + return str(int(round(float(px)))) def format_usdc_amount(v: float | None) -> str | None: diff --git a/tests/test_options_pricing.py b/tests/test_options_pricing.py index ff17f81..d912efa 100644 --- a/tests/test_options_pricing.py +++ b/tests/test_options_pricing.py @@ -17,6 +17,10 @@ def test_round_option_px(): assert round_option_px(14.9184, "0.2", "sell") == 14.8 assert round_option_px(14.81, "0.2", "buy") == 15.0 assert format_option_px(14.8, "0.2") == "14.8" + # BTC 期权 tickSz=5: 整数末尾 0 必须保留 (1370 不能显成 137) + assert format_option_px(1370, "5") == "1370" + assert format_option_px(1160, 5) == "1160" + assert format_option_px(1000, "5") == "1000" def test_premium_per_sheet():