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:
@@ -214,6 +214,45 @@ class TestHedgePoMode(unittest.TestCase):
|
||||
)
|
||||
self.assertAlmostEqual(px, 2476.0)
|
||||
|
||||
def test_settle_coin_option_returns_coin_units(self):
|
||||
from lib.hedge_plan.hedge_plan_settle_lib import settle_option_leg_at_spot
|
||||
|
||||
# BTC put ITM: K=90000 S=80000 → 币内在 (90000-80000)/80000=0.125; 1张×0.01=0.00125币
|
||||
# 权利金 0.01 币 → 净利 0.00125-0.01 = -0.00875 币(非 ×8万的美元差)
|
||||
pnl = settle_option_leg_at_spot(
|
||||
{
|
||||
"inst_id": "BTC-USD-261018-90000-P",
|
||||
"opt_type": "P",
|
||||
"strike": 90000,
|
||||
"size": 1,
|
||||
"ct_mult": 0.01,
|
||||
"premium": 0.01,
|
||||
},
|
||||
80000.0,
|
||||
)
|
||||
self.assertAlmostEqual(pnl, 0.00125 - 0.01, places=6)
|
||||
|
||||
def test_size_from_premium_preview_needs_dual_index(self):
|
||||
# 无双指数 → 同币路径;有双指数 → 跨币张数
|
||||
same = size_from_premium(
|
||||
premium_budget=1000,
|
||||
ask=0.01,
|
||||
ct_mult=0.01,
|
||||
ratio=2,
|
||||
contract_size=0.01,
|
||||
)
|
||||
cross = size_from_premium(
|
||||
premium_budget=1000,
|
||||
ask=0.01,
|
||||
ct_mult=0.01,
|
||||
ratio=2,
|
||||
contract_size=0.01,
|
||||
option_index=100_000,
|
||||
perp_index=2_500,
|
||||
)
|
||||
self.assertTrue(same["ok"] and cross["ok"])
|
||||
self.assertGreater(float(cross["contracts"]), float(same["contracts"]))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user