05586242f0
Co-authored-by: Cursor <cursoragent@cursor.com>
53 lines
1.2 KiB
Python
53 lines
1.2 KiB
Python
"""期权定价单测。"""
|
|
from lib.options.options_pricing_lib import (
|
|
calc_order_size,
|
|
premium_per_sheet,
|
|
sheets_from_eth_amount,
|
|
total_premium,
|
|
)
|
|
from lib.exchange.okx_options_lib import format_option_px, round_option_px
|
|
|
|
|
|
def test_round_option_px():
|
|
assert round_option_px(14.9184, "0.2", "sell") == 14.8
|
|
assert round_option_px(14.81, "0.2", "buy") == 15.0
|
|
assert format_option_px(14.8, "0.2") == "14.8"
|
|
|
|
|
|
def test_premium_per_sheet():
|
|
assert abs(premium_per_sheet(15.6, 0.01) - 0.156) < 1e-9
|
|
|
|
|
|
def test_total_premium_half_eth():
|
|
assert abs(total_premium(15.6, 0.5) - 7.8) < 1e-9
|
|
|
|
|
|
def test_sheets_from_eth():
|
|
assert sheets_from_eth_amount(0.5, 0.01) == 50
|
|
|
|
|
|
def test_calc_order_size_budget():
|
|
r = calc_order_size(
|
|
quote_per_unit=15.6,
|
|
ct_mult=0.01,
|
|
min_sz=1,
|
|
budget_usdc=10,
|
|
budget_buffer=0.95,
|
|
budget_cap=10,
|
|
)
|
|
assert r["ok"] is True
|
|
assert r["sheets"] >= 1
|
|
assert r["total_premium"] <= 10
|
|
|
|
|
|
def test_calc_order_size_too_small():
|
|
r = calc_order_size(
|
|
quote_per_unit=2000.0,
|
|
ct_mult=0.01,
|
|
min_sz=1,
|
|
budget_usdc=10,
|
|
budget_buffer=0.95,
|
|
budget_cap=10,
|
|
)
|
|
assert r["ok"] is False
|