fix模拟盘期权手续费按OKX币本位公式计费,并纠正复盘旧单展示。
费率作用在标的币数量上并以权利金7%封顶,不再误用权利金×费率。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+43
-5
@@ -1,4 +1,9 @@
|
||||
"""成交价与手续费: 滑点 = 1×fee_rate."""
|
||||
"""成交价与手续费.
|
||||
|
||||
永续:滑点=1×fee_rate,手续费=名义×fee_rate.
|
||||
期权(币本位):滑点仍按权利金价×fee_rate;手续费对齐 OKX=
|
||||
Min(fee_rate×标的币数量, 权利金×7%).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -57,6 +62,30 @@ def perp_fill(
|
||||
return PriceResult(base_px=base, fill_px=fill, fee=fee, slip=slip, notional=notional)
|
||||
|
||||
|
||||
def option_fee_coin(
|
||||
*,
|
||||
underlying_coin: float,
|
||||
premium_coin: float,
|
||||
fee_rate: float | None = None,
|
||||
premium_fee_cap: float = 0.07,
|
||||
) -> float:
|
||||
"""OKX 币本位期权手续费(权利金币种).
|
||||
|
||||
Min(费率 × 张数对应标的币数量, 权利金×封顶比例).
|
||||
注意:费率作用在标的币面值上,不是权利金名义上.
|
||||
"""
|
||||
f = sim_fee_rate(fee_rate)
|
||||
qty = abs(float(underlying_coin or 0.0))
|
||||
prem = abs(float(premium_coin or 0.0))
|
||||
if qty <= 0 and prem <= 0:
|
||||
return 0.0
|
||||
by_rate = qty * f
|
||||
cap_ratio = abs(float(premium_fee_cap or 0.07))
|
||||
if cap_ratio <= 0 or prem <= 0:
|
||||
return round(by_rate, 8)
|
||||
return round(min(by_rate, prem * cap_ratio), 8)
|
||||
|
||||
|
||||
def option_fill(
|
||||
*,
|
||||
action: str,
|
||||
@@ -65,7 +94,11 @@ def option_fill(
|
||||
qty: float,
|
||||
fee_rate: float,
|
||||
) -> PriceResult:
|
||||
"""开仓买入吃卖一; 平仓卖出吃买一. qty = sheets × ct_mult."""
|
||||
"""开仓买入吃卖一; 平仓卖出吃买一.
|
||||
|
||||
qty = sheets × ct_mult(标的币数量).
|
||||
滑点仍按权利金价×费率;手续费按 OKX 币本位公式(标的币×费率,权利金7%封顶).
|
||||
"""
|
||||
f = float(fee_rate)
|
||||
if action == "open":
|
||||
base = float(ask)
|
||||
@@ -73,9 +106,14 @@ def option_fill(
|
||||
else:
|
||||
base = float(bid)
|
||||
fill = base * (1.0 - f)
|
||||
notional = abs(fill * float(qty))
|
||||
fee = notional * f
|
||||
slip = abs(fill - base) * float(qty)
|
||||
qty_f = abs(float(qty))
|
||||
notional = abs(fill * qty_f)
|
||||
fee = option_fee_coin(
|
||||
underlying_coin=qty_f,
|
||||
premium_coin=notional,
|
||||
fee_rate=f,
|
||||
)
|
||||
slip = abs(fill - base) * qty_f
|
||||
return PriceResult(base_px=base, fill_px=fill, fee=fee, slip=slip, notional=notional)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user