Fix BTC option prices losing trailing zeros in display.
Integer tick formatting was stripping zeros (1370 -> 137), so hedge-plan quotes looked wrong versus the options list. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user