Add OKX options expiry and close breakeven to hub monitor and dashboard.
Expose bePx-based expiry balance and mark-to-close breakeven on positions so monitor and dashboard can show both labels per contract. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -77,3 +77,80 @@ def test_calc_order_size_too_small():
|
||||
budget_cap=10,
|
||||
)
|
||||
assert r["ok"] is False
|
||||
|
||||
|
||||
def test_expiry_breakeven_from_api():
|
||||
from lib.options.options_pricing_lib import expiry_breakeven_px
|
||||
|
||||
assert expiry_breakeven_px(
|
||||
opt_type="C", strike=3500, avg_px=15.6, be_px_api=3516.2
|
||||
) == 3516.2
|
||||
|
||||
|
||||
def test_expiry_breakeven_call_put():
|
||||
from lib.options.options_pricing_lib import expiry_breakeven_px
|
||||
|
||||
assert expiry_breakeven_px(opt_type="C", strike=3500, avg_px=15.6) == 3515.6
|
||||
assert expiry_breakeven_px(opt_type="P", strike=3500, avg_px=15.6) == 3484.4
|
||||
|
||||
|
||||
def test_close_breakeven_at_mark_equals_avg():
|
||||
from lib.options.options_pricing_lib import close_breakeven_idx
|
||||
|
||||
assert close_breakeven_idx(
|
||||
opt_type="C", idx_px=3480, mark_px=15.6, avg_px=15.6
|
||||
) == 3480.0
|
||||
assert close_breakeven_idx(
|
||||
opt_type="P", idx_px=3480, mark_px=15.6, avg_px=15.6
|
||||
) == 3480.0
|
||||
|
||||
|
||||
def test_close_breakeven_with_delta():
|
||||
from lib.options.options_pricing_lib import close_breakeven_idx
|
||||
|
||||
# mark below avg, delta 0.5 ETH on 0.5 ETH position -> slope 1
|
||||
be = close_breakeven_idx(
|
||||
opt_type="C",
|
||||
idx_px=3480,
|
||||
mark_px=14.6,
|
||||
avg_px=15.6,
|
||||
delta_pa=0.5,
|
||||
pos=50,
|
||||
ct_mult=0.01,
|
||||
)
|
||||
assert be == 3481.0
|
||||
|
||||
|
||||
def test_format_options_breakeven_line():
|
||||
from lib.options.options_pricing_lib import format_options_breakeven_line
|
||||
|
||||
s = format_options_breakeven_line(
|
||||
expiry_be_px=3515.6, close_be_px=3498.0, idx_px=3480.0
|
||||
)
|
||||
assert "到期平衡3516" in s
|
||||
assert "平掉回本3498" in s
|
||||
assert "指数3480" in s
|
||||
|
||||
|
||||
def test_format_position_row_breakeven():
|
||||
from lib.exchange.okx_options_lib import format_position_row
|
||||
|
||||
row = format_position_row(
|
||||
{
|
||||
"instId": "ETH-USD_UM-260703-1800-C",
|
||||
"pos": "50",
|
||||
"avgPx": "15.6",
|
||||
"markPx": "16.2",
|
||||
"idxPx": "3480",
|
||||
"bePx": "3515.6",
|
||||
"optType": "C",
|
||||
"stk": "3500",
|
||||
"deltaPA": "0.45",
|
||||
"upl": "0.3",
|
||||
"uplRatio": "0.02",
|
||||
}
|
||||
)
|
||||
assert row["expiry_be_px"] == 3515.6
|
||||
assert row["idx_px"] == 3480.0
|
||||
assert row["close_be_px"] is not None
|
||||
assert row["dist_expiry_be"] == 35.6
|
||||
|
||||
Reference in New Issue
Block a user