Make this repo hedge-only: skip standalone options UI by default.

Nav/env only expose 永期/期期; set STANDALONE_OPTIONS_UI=true for emergency opt-in.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-14 18:37:46 +08:00
parent 14cbbc300d
commit 6607d09526
6 changed files with 106 additions and 51 deletions
+47 -19
View File
@@ -1,4 +1,4 @@
"""OKX_TRADE_MODE 三选一."""
"""OKX_TRADE_MODE 对冲二选一(本仓默认无单独期权 UI)."""
import os
import unittest
@@ -14,31 +14,56 @@ from lib.hedge_plan.okx_trade_mode_lib import (
show_options_options,
show_perp_options,
standalone_options_open_allowed,
standalone_options_ui_enabled,
)
class OkxTradeModeTests(unittest.TestCase):
def test_explicit_modes(self):
def test_hedge_modes(self):
for mode, hedge, po, oo in (
(MODE_OPTIONS, False, False, False),
(MODE_PERP, True, True, False),
(MODE_OO, True, False, True),
):
with patch.dict(os.environ, {"OKX_TRADE_MODE": mode}, clear=False):
with patch.dict(
os.environ,
{"OKX_TRADE_MODE": mode, "STANDALONE_OPTIONS_UI": "false"},
clear=False,
):
self.assertEqual(get_okx_trade_mode(), mode)
self.assertEqual(hedge_module_enabled(), hedge)
self.assertEqual(show_perp_options(), po)
self.assertEqual(show_options_options(), oo)
self.assertEqual(standalone_options_open_allowed(), mode == MODE_OPTIONS)
self.assertFalse(standalone_options_open_allowed())
def test_legacy_infer_options(self):
def test_options_mode_coerces_to_perp_without_ui_flag(self):
with patch.dict(
os.environ,
{"HEDGE_PLAN_ENABLED": "false"},
{"OKX_TRADE_MODE": MODE_OPTIONS, "STANDALONE_OPTIONS_UI": "false"},
clear=False,
):
self.assertEqual(get_okx_trade_mode(), MODE_PERP)
self.assertTrue(hedge_module_enabled())
self.assertFalse(standalone_options_open_allowed())
def test_options_mode_with_ui_flag(self):
with patch.dict(
os.environ,
{"OKX_TRADE_MODE": MODE_OPTIONS, "STANDALONE_OPTIONS_UI": "true"},
clear=False,
):
self.assertEqual(get_okx_trade_mode(), MODE_OPTIONS)
self.assertFalse(hedge_module_enabled())
self.assertTrue(standalone_options_ui_enabled())
self.assertTrue(standalone_options_open_allowed())
def test_legacy_infer_defaults_perp(self):
with patch.dict(
os.environ,
{"HEDGE_PLAN_ENABLED": "false", "STANDALONE_OPTIONS_UI": "false"},
clear=False,
):
os.environ.pop("OKX_TRADE_MODE", None)
self.assertEqual(get_okx_trade_mode(), MODE_OPTIONS)
self.assertEqual(get_okx_trade_mode(), MODE_PERP)
def test_legacy_infer_perp(self):
with patch.dict(
@@ -47,28 +72,25 @@ class OkxTradeModeTests(unittest.TestCase):
"HEDGE_PLAN_ENABLED": "true",
"HEDGE_PLAN_SHOW_PERP_OPTIONS": "true",
"HEDGE_PLAN_SHOW_OPTIONS_OPTIONS": "false",
"STANDALONE_OPTIONS_UI": "false",
},
clear=False,
):
os.environ.pop("OKX_TRADE_MODE", None)
self.assertEqual(get_okx_trade_mode(), MODE_PERP)
def test_block_standalone_in_hedge_mode(self):
with patch.dict(os.environ, {"OKX_TRADE_MODE": MODE_OO}):
def test_block_standalone_hedge_only_msg(self):
with patch.dict(
os.environ,
{"OKX_TRADE_MODE": MODE_OO, "STANDALONE_OPTIONS_UI": "false"},
clear=False,
):
msg = block_standalone_open_by_mode_msg()
self.assertIsNotNone(msg)
self.assertIn("期期", msg or "")
self.assertIn("仅对冲", msg or "")
class EnvUiModeSectionsTests(unittest.TestCase):
def test_options_mode_hides_hedge_section(self):
from lib.env.env_ui_manifest import ui_sections_for_exchange
titles = [s["title"] for s in ui_sections_for_exchange("okx", mode="options")]
self.assertIn("期权/对冲模式", titles)
self.assertIn("期权账户", titles)
self.assertTrue(all("对冲" not in t for t in titles if t != "期权/对冲模式"))
def test_perp_mode_shows_po_fields(self):
from lib.env.env_ui_manifest import ui_sections_for_exchange
@@ -90,6 +112,12 @@ class EnvUiModeSectionsTests(unittest.TestCase):
self.assertIn("HEDGE_PLAN_OO_BIAS_RATIO", keys)
self.assertNotIn("HEDGE_PLAN_OPEN_ORDER", keys)
def test_trade_mode_choices_are_hedge_only(self):
from lib.env.env_schema import SELECT_OPTIONS
modes = [k for k, _ in SELECT_OPTIONS["OKX_TRADE_MODE"]]
self.assertEqual(modes, ["perp_options", "options_options"])
if __name__ == "__main__":
unittest.main()