"""对冲拆除后的冒烟:交易模式锁定单独期权;hedge_plan 包已移除.""" from __future__ import annotations import importlib import unittest class RemoveHedgeSmokeTests(unittest.TestCase): def test_trade_mode_always_options(self): from lib.options.okx_trade_mode_lib import ( get_okx_trade_mode, hedge_module_enabled, standalone_options_open_allowed, block_standalone_open_by_mode_msg, normalize_okx_trade_mode, ) self.assertEqual(normalize_okx_trade_mode("options_options"), "options") self.assertEqual(normalize_okx_trade_mode("perp_options"), "options") self.assertEqual(get_okx_trade_mode(), "options") self.assertFalse(hedge_module_enabled()) self.assertTrue(standalone_options_open_allowed()) self.assertIsNone(block_standalone_open_by_mode_msg()) def test_hedge_plan_package_gone(self): with self.assertRaises(ModuleNotFoundError): importlib.import_module("lib.hedge_plan") def test_option_expiry_pnl_available(self): from lib.options.options_pricing_lib import option_expiry_pnl pnl = option_expiry_pnl( opt_type="P", strike=2700, spot=2600, sheets=10, ct_mult=0.01, premium_paid=1.0, ) # intrinsic = 100 * 10 * 0.01 = 10; pnl = 10 - 1 = 9 self.assertAlmostEqual(pnl, 9.0, places=6) def test_profit_exit_no_hedge_import(self): import inspect from lib.options import options_profit_exit_lib as m src = inspect.getsource(m) self.assertNotIn("hedge_plan", src) def test_nav_display_meta_no_hedge(self): from lib.instance.instance_display_prefs_lib import display_meta_for_ui, tab_allowed from lib.instance.instance_embed_lib import EMBED_TABS labels = [e["label"] for g in display_meta_for_ui() for e in g["entries"]] self.assertNotIn("对冲计划", labels) self.assertFalse(tab_allowed("hedge_plan")) self.assertNotIn("hedge_plan", EMBED_TABS) def test_positions_api_still_builds_target_maps(self): """删对冲时勿再漏掉 tgt_map / profit_exit_map 赋值,否则有仓时接口 500、前端暂无持仓.""" import inspect from lib.options import options_register src = inspect.getsource(options_register.register_options_routes) self.assertIn("tgt_map = targets_by_inst(conn)", src) self.assertIn("profit_exit_map = profit_exit_by_inst(conn)", src) self.assertNotIn("hedge_target_map", src) self.assertNotIn("hedge_plan_target", src) def test_env_ui_no_hedge_mode_section(self): from lib.env.env_ui_manifest import ui_sections_for_exchange from lib.env.env_schema import select_options_for titles = [s["title"] for s in ui_sections_for_exchange("okx")] self.assertNotIn("期权/对冲模式", titles) self.assertTrue(any("对冲" not in t for t in titles)) for t in titles: self.assertNotIn("对冲", t) labels = [f[1] for s in ui_sections_for_exchange("okx") for f in s["fields"]] for lab in labels: self.assertNotIn("对冲", lab) mode_opts = [o["value"] for o in select_options_for("OKX_TRADE_MODE")] self.assertEqual(mode_opts, ["options"]) if __name__ == "__main__": unittest.main()