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
+20 -5
View File
@@ -305,8 +305,21 @@ def resolve_path(path_value):
app = Flask(__name__)
app.secret_key = os.getenv("FLASK_SECRET_KEY", "coinox_2026_secret_key")
from lib.instance.instance_embed_lib import attach_embed_templates, redirect_to_embed_shell_if_enabled
from jinja2 import ChoiceLoader, FileSystemLoader
from lib.paths import strategy_templates_dir
attach_embed_templates(app, _REPO_ROOT)
# 复盘页引用 strategy 模板字段;CoinOX 不装策略交易,仍挂载模板目录
_strategy_tpl = strategy_templates_dir(_REPO_ROOT)
if os.path.isdir(_strategy_tpl):
_existing = app.jinja_loader
_loaders = [FileSystemLoader(_strategy_tpl)]
if _existing is not None:
if isinstance(_existing, ChoiceLoader):
_loaders = list(_existing.loaders) + _loaders
else:
_loaders.insert(0, _existing)
app.jinja_loader = ChoiceLoader(_loaders)
# ====================== 登录配置 ======================
USERNAME = os.getenv("APP_USERNAME", "dekun")
@@ -368,7 +381,8 @@ _promote_legacy_options_api_keys()
OKX_API_KEY = normalize_api_credential(os.getenv("OKX_API_KEY"))
OKX_API_SECRET = normalize_api_credential(os.getenv("OKX_API_SECRET"))
OKX_API_PASSPHRASE = normalize_api_credential(os.getenv("OKX_API_PASSPHRASE"))
OKX_OPTIONS_ENABLED = os.getenv("OKX_OPTIONS_ENABLED", "false").lower() in ("1", "true", "yes", "on")
# CoinOX 默认开启期权;模拟盘可不配 OKX API
OKX_OPTIONS_ENABLED = os.getenv("OKX_OPTIONS_ENABLED", "true").lower() in ("1", "true", "yes", "on")
OKX_OPTIONS_TRADE_BUDGET_USDC = float(os.getenv("OKX_OPTIONS_TRADE_BUDGET_USDC", "10"))
OKX_OPTIONS_DEFAULT_UNDERLY = (os.getenv("OKX_OPTIONS_DEFAULT_UNDERLY") or "ETH").strip().upper()
OKX_TD_MODE = os.getenv("OKX_TD_MODE", "cross")
@@ -9911,11 +9925,12 @@ install_hedge_plan(app, _REPO_ROOT, app_module=sys.modules[__name__])
try:
from lib.sim.hooks import patch_options_cfg
_opt_cfg = app.extensions.get("options_cfg")
if isinstance(_opt_cfg, dict):
patch_options_cfg(_opt_cfg)
for _cfg_key in ("options_cfg", "hedge_plan_cfg"):
_cfg = app.extensions.get(_cfg_key)
if isinstance(_cfg, dict):
patch_options_cfg(_cfg)
except Exception as _sim_patch_err:
print(f"[sim] patch options_cfg: {_sim_patch_err}", flush=True)
print(f"[sim] patch options/hedge cfg: {_sim_patch_err}", flush=True)
_purge_key_monitors_if_full_margin()