修复 BTC 币本位期权净盈亏被 round4 抹成 0 的精度问题。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -95,6 +95,8 @@ def forget_close_gate_for_inst(inst_id: str) -> None:
|
||||
|
||||
def net_pnl_from_display_row(row: dict[str, Any]) -> float | None:
|
||||
"""与持仓卡「净盈亏」同口径:买一可回收 − 权利金;残档买一则无净值."""
|
||||
from lib.options.options_pricing_lib import PREMIUM_DECIMALS_COIN, round_premium_amount
|
||||
|
||||
preview = row.get("close_preview") if isinstance(row.get("close_preview"), dict) else {}
|
||||
if preview.get("bid_invalid"):
|
||||
return None
|
||||
@@ -112,7 +114,9 @@ def net_pnl_from_display_row(row: dict[str, Any]) -> float | None:
|
||||
recv = _safe_float(preview.get("total_received"))
|
||||
paid = _safe_float(row.get("premium_paid"))
|
||||
if covered > 0 and recv is not None and paid is not None:
|
||||
return round(recv - paid, 4)
|
||||
ccy = str(row.get("premium_ccy") or "").strip().upper()
|
||||
decimals = PREMIUM_DECIMALS_COIN if ccy in ("ETH", "BTC") else None
|
||||
return round_premium_amount(recv - paid, ccy=ccy or None, decimals=decimals)
|
||||
return None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user