Fix btc_eth watching entry, preview sizing, and coin-to-U settlement.
Use dual indices for watch/preview; perp entry uses ETH mark; expiry/close convert coin PnL via option index; align legacy long→Call; omit combo U when index missing. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -35,14 +35,40 @@ def leg_is_expired(leg: dict[str, Any], *, now_ms: Optional[int] = None) -> bool
|
||||
|
||||
|
||||
def settle_option_leg_at_spot(leg: dict[str, Any], spot: float) -> float:
|
||||
"""按到期结算口径估算腿盈亏(USDC)."""
|
||||
"""按到期结算估算腿盈亏(与权利金同单位).
|
||||
|
||||
- 币本位(BTC-USD/ETH-USD):返回 **币** 盈亏(内在价值/币 − 权利金币);调用方须 × 期权指数折 U.
|
||||
- USDC:返回 U 盈亏.
|
||||
"""
|
||||
premium = float(leg.get("premium") or 0)
|
||||
strike = _sf(leg.get("strike"))
|
||||
if strike is None:
|
||||
return -premium
|
||||
sheets = float(leg.get("size") or 1)
|
||||
# ct_mult 未入库时默认 0.01
|
||||
ct = float(leg.get("ct_mult") or 0.01)
|
||||
inst_id = str(leg.get("inst_id") or "")
|
||||
try:
|
||||
from lib.options.options_pricing_lib import _quote_in_coin_from_context, intrinsic_px_per_unit
|
||||
|
||||
coin = _quote_in_coin_from_context(inst_id=inst_id)
|
||||
except Exception:
|
||||
coin = "-USD-" in inst_id.upper() and "USDC" not in inst_id.upper()
|
||||
intrinsic_px_per_unit = None # type: ignore
|
||||
if coin:
|
||||
unit = None
|
||||
if intrinsic_px_per_unit is not None:
|
||||
try:
|
||||
unit = intrinsic_px_per_unit(
|
||||
str(leg.get("opt_type") or "P"),
|
||||
float(strike),
|
||||
float(spot),
|
||||
inst_id=inst_id,
|
||||
)
|
||||
except Exception:
|
||||
unit = None
|
||||
if unit is None:
|
||||
unit = 0.0
|
||||
return float(unit) * sheets * ct - premium
|
||||
return float(
|
||||
option_expiry_pnl(
|
||||
opt_type=str(leg.get("opt_type") or "P"),
|
||||
|
||||
Reference in New Issue
Block a user