Enable options by default and allow full sim trading without OKX API keys.

Relax hedge start gates in sim, route perp open/close through sim broker, and mount strategy templates for records pages.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-14 09:26:38 +08:00
parent d4b970cfd5
commit b4d62ea0a6
8 changed files with 445 additions and 352 deletions
+6 -3
View File
@@ -716,6 +716,7 @@ def gate_status(
show_options_options: bool = True,
mutual_exclusive: bool = True,
has_standalone_option: bool = False,
sim_mode: bool = False,
) -> dict[str, Any]:
from lib.trade.position_sizing_lib import is_full_margin_mode
@@ -739,7 +740,8 @@ def gate_status(
can_preview = False
can_start = False
reasons.append("期期对冲已隐藏(HEDGE_PLAN_SHOW_OPTIONS_OPTIONS)")
if not live_order:
# 模拟盘用本地钱包撮合,不要求实盘开关 / API
if not sim_mode and not live_order:
can_start = False
reasons.append("未允许对冲真实下单(HEDGE_PLAN_LIVE_ORDER)")
if active_count >= max(1, int(max_active or 1)):
@@ -749,10 +751,10 @@ def gate_status(
can_start = False
reasons.append("存在单独期权持仓,禁止启动对冲计划(互斥门控)")
if pt == "perp_options":
if not full:
if not full and not sim_mode:
can_start = False
reasons.append("永期开仓仅全仓模式可用(当前可测算)")
if not live_trading:
if not sim_mode and not live_trading:
can_start = False
reasons.append("未开启实盘(LIVE_TRADING_ENABLED)")
elif pt == "options_options":
@@ -770,6 +772,7 @@ def gate_status(
"plan_type": pt,
"live_order": live_order,
"live_trading": live_trading,
"sim_mode": bool(sim_mode),
"active_count": active_count,
"max_active": max_active,
"show_perp_options": bool(show_perp_options),
+11 -1
View File
@@ -93,7 +93,7 @@ def _build_cfg(app_module: Any) -> dict[str, Any]:
"alt_leverage": int(getattr(app_module, "ALT_LEVERAGE", 5) or 5),
"full_margin_buffer": float(getattr(app_module, "FULL_MARGIN_BUFFER_RATIO", 0.98) or 0.98),
"funds_decimals": int(getattr(app_module, "FUNDS_DECIMALS", 2) or 2),
"options_enabled": _env_bool("OKX_OPTIONS_ENABLED", False),
"options_enabled": _env_bool("OKX_OPTIONS_ENABLED", True),
"default_underly": (os.getenv("OKX_OPTIONS_DEFAULT_UNDERLY") or "ETH").strip().upper(),
"chain_max_dte": float(os.getenv("OKX_OPTIONS_CHAIN_MAX_DTE_DAYS") or os.getenv("OKX_OPTIONS_MAX_DTE_DAYS") or "14"),
"perp_account_label": (os.getenv("OKX_ACCOUNT_LABEL") or "合约账户").strip(),
@@ -195,6 +195,15 @@ def _gates_dict(cfg: dict[str, Any], plan_type: str) -> dict[str, Any]:
# fail-closed:探测失败视为不可开仓
active = 10**9
has_standalone = True
sim_mode = False
try:
from lib.sim.mode_lib import is_sim_mode
get_db = cfg.get("get_db")
if callable(get_db):
sim_mode = bool(is_sim_mode(get_db))
except Exception:
sim_mode = False
return gate_status(
hedge_enabled=_hedge_enabled(),
sizing_mode=load_position_sizing_mode(),
@@ -208,6 +217,7 @@ def _gates_dict(cfg: dict[str, Any], plan_type: str) -> dict[str, Any]:
show_options_options=_show_options_options(),
mutual_exclusive=mutual,
has_standalone_option=has_standalone,
sim_mode=sim_mode,
)