From 4fb3be35ef98d197154af99abe89d65ee55f8c61 Mon Sep 17 00:00:00 2001 From: dekun Date: Thu, 20 Aug 2026 14:05:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E7=AC=94=E6=9C=9F=E6=9D=83=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=94=B9=E4=B8=BA=E5=B8=81=E6=9C=AC=E4=BD=8D=EF=BC=9B?= =?UTF-8?q?=E6=9C=AA=E9=85=8D=E7=BD=AE=E6=97=B6=E6=8C=89coin=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- crypto_monitor_okx/.env.example | 4 ++-- crypto_monitor_okx/app.py | 12 ++++++------ docs/OKX单笔期权-币本位与USDT桥-开发方案.md | 2 +- lib/env/env_schema.py | 2 +- lib/env/env_ui_manifest.py | 2 +- lib/instance/instance_embed_context_lib.py | 2 +- lib/instance/instance_settings_register.py | 2 +- lib/instance/templates/embed_boot_scripts.html | 4 ++-- lib/instance/templates/index.html | 4 ++-- lib/instance/templates/instance_header_panel.html | 4 ++-- lib/instance/templates/instance_header_stats.html | 4 ++-- lib/options/options_margin_mode_lib.py | 11 ++++++++--- lib/options/options_register.py | 2 +- tests/test_options_margin_mode.py | 4 ++++ 14 files changed, 34 insertions(+), 25 deletions(-) diff --git a/crypto_monitor_okx/.env.example b/crypto_monitor_okx/.env.example index 7ddd848..01162bd 100644 --- a/crypto_monitor_okx/.env.example +++ b/crypto_monitor_okx/.env.example @@ -113,8 +113,8 @@ OKX_OPTIONS_ENABLED=false # OKX_OPTIONS_API_SECRET= # OKX_OPTIONS_API_PASSPHRASE= OKX_OPTIONS_ACCOUNT_LABEL=账户·期权 -# 单笔期权本位: usdc(默认,权利金USDC) | coin(币本位+USDT买币桥;对冲仍仅USDC) -OKX_OPTIONS_MARGIN_MODE=usdc +# 单笔期权本位: coin(默认,币本位+USDT买币桥) | usdc(权利金USDC;对冲仍仅USDC) +OKX_OPTIONS_MARGIN_MODE=coin OKX_OPTIONS_TRADE_BUDGET_USDC=10 OKX_OPTIONS_BUDGET_BUFFER=0.95 # 币本位:按交易户USDT×缓冲复利;上限开关默认关(靠人工转走) diff --git a/crypto_monitor_okx/app.py b/crypto_monitor_okx/app.py index 5aef30f..03f8f31 100644 --- a/crypto_monitor_okx/app.py +++ b/crypto_monitor_okx/app.py @@ -6630,7 +6630,7 @@ def render_main_page(page="trade", embed_mode=None): options_funding_eth = None options_trading_eth = None options_trading_btc = None - options_margin_mode = "usdc" + options_margin_mode = "coin" options_underly = "ETH" if ( OKX_OPTIONS_ENABLED @@ -6648,7 +6648,7 @@ def render_main_page(page="trade", embed_mode=None): options_funding_eth = _op.get("funding_eth") options_trading_eth = _op.get("trading_eth") options_trading_btc = _op.get("trading_btc") - options_margin_mode = _op.get("options_margin_mode") or "usdc" + options_margin_mode = _op.get("options_margin_mode") or "coin" options_underly = _op.get("options_underly") or "ETH" except Exception: options_trading_usdc = None @@ -6658,7 +6658,7 @@ def render_main_page(page="trade", embed_mode=None): options_funding_eth = None options_trading_eth = None options_trading_btc = None - options_margin_mode = "usdc" + options_margin_mode = "coin" options_underly = "ETH" recommended_capital = get_recommended_capital(current_capital) key_list = ( @@ -7077,7 +7077,7 @@ def api_account_snapshot(): options_funding_eth = None options_trading_eth = None options_trading_btc = None - options_margin_mode = "usdc" + options_margin_mode = "coin" options_underly = "ETH" if OKX_OPTIONS_ENABLED and exchange_options.apiKey: try: @@ -7091,7 +7091,7 @@ def api_account_snapshot(): options_funding_eth = _op.get("funding_eth") options_trading_eth = _op.get("trading_eth") options_trading_btc = _op.get("trading_btc") - options_margin_mode = _op.get("options_margin_mode") or "usdc" + options_margin_mode = _op.get("options_margin_mode") or "coin" options_underly = _op.get("options_underly") or "ETH" except Exception: options_trading_usdc = None @@ -7101,7 +7101,7 @@ def api_account_snapshot(): options_funding_eth = None options_trading_eth = None options_trading_btc = None - options_margin_mode = "usdc" + options_margin_mode = "coin" options_underly = "ETH" recommended_capital = get_recommended_capital(current_capital) from lib.strategy.strategy_trade_labels import count_position_limit_active_monitors diff --git a/docs/OKX单笔期权-币本位与USDT桥-开发方案.md b/docs/OKX单笔期权-币本位与USDT桥-开发方案.md index 1001987..4167aa3 100644 --- a/docs/OKX单笔期权-币本位与USDT桥-开发方案.md +++ b/docs/OKX单笔期权-币本位与USDT桥-开发方案.md @@ -50,7 +50,7 @@ | 变量 | 含义 | 默认 | |------|------|------| -| `OKX_OPTIONS_MARGIN_MODE` | `usdc` \| `coin` | `usdc` | +| `OKX_OPTIONS_MARGIN_MODE` | `usdc` \| `coin` | `coin` | | `OKX_OPTIONS_TRADE_BUDGET_USDC` | USDC 模式单笔权利金预算上限(现有) | `10` | | `OKX_OPTIONS_BUDGET_BUFFER` | 预算缓冲(现有,币本位复利亦用) | `0.95` | | `OKX_OPTIONS_COIN_COMPOUND` | 币本位是否按交易户 USDT 复利 | `true`(建议默认开) | diff --git a/lib/env/env_schema.py b/lib/env/env_schema.py index b62525a..0898f42 100644 --- a/lib/env/env_schema.py +++ b/lib/env/env_schema.py @@ -167,8 +167,8 @@ SELECT_OPTIONS: dict[str, tuple[tuple[str, str], ...]] = { ("options_options", "期期对冲"), ), "OKX_OPTIONS_MARGIN_MODE": ( - ("usdc", "USDC(USDⓈ权利金)"), ("coin", "币本位(USDT买币桥)"), + ("usdc", "USDC(USDⓈ权利金)"), ), "HEDGE_PLAN_OPTION_PRIMARY": ( ("true", "以期权为主"), diff --git a/lib/env/env_ui_manifest.py b/lib/env/env_ui_manifest.py index ff09200..f138174 100644 --- a/lib/env/env_ui_manifest.py +++ b/lib/env/env_ui_manifest.py @@ -146,7 +146,7 @@ _OPTIONS_SECTION: dict[str, Any] = { ( "OKX_OPTIONS_MARGIN_MODE", "单笔期权本位", - "usdc=USDⓈ权利金;coin=币本位+USDT买币桥。有持仓/半成品桥时勿切换;改后需重启", + "usdc=USDⓈ权利金;coin=币本位+USDT买币桥(默认)。有持仓/半成品桥时勿切换;改后需重启", ), ( "OKX_OPTIONS_TRADE_BUDGET_USDC", diff --git a/lib/instance/instance_embed_context_lib.py b/lib/instance/instance_embed_context_lib.py index 0d943e7..3103f02 100644 --- a/lib/instance/instance_embed_context_lib.py +++ b/lib/instance/instance_embed_context_lib.py @@ -146,7 +146,7 @@ def trading_account_label( mode = normalize_options_margin_mode(margin_mode) except Exception: - mode = str(margin_mode or "usdc").strip().lower() or "usdc" + mode = str(margin_mode or "coin").strip().lower() or "coin" if mode != "coin": if usdt is None: return "—" diff --git a/lib/instance/instance_settings_register.py b/lib/instance/instance_settings_register.py index 0d0484c..8369887 100644 --- a/lib/instance/instance_settings_register.py +++ b/lib/instance/instance_settings_register.py @@ -112,7 +112,7 @@ def register_instance_settings_routes( from lib.options.options_spot_bridge_lib import mode_switch_block_msg lines = read_env_lines(env_path) - old_mode = normalize_options_margin_mode(env_get(lines, "OKX_OPTIONS_MARGIN_MODE") or "usdc") + old_mode = normalize_options_margin_mode(env_get(lines, "OKX_OPTIONS_MARGIN_MODE") or "coin") new_mode = normalize_options_margin_mode(clean.get("OKX_OPTIONS_MARGIN_MODE")) if old_mode != new_mode: conn_m = get_db() diff --git a/lib/instance/templates/embed_boot_scripts.html b/lib/instance/templates/embed_boot_scripts.html index fa2d2ab..1058e24 100644 --- a/lib/instance/templates/embed_boot_scripts.html +++ b/lib/instance/templates/embed_boot_scripts.html @@ -1143,7 +1143,7 @@ function formatOptionsFundingLabel(usdc, usdt, eth, marginMode, underly) { return `${n.toFixed(2)} USDC`; } function formatTradingAccountLabel(usdt, eth, btc, marginMode) { - const mode = String(marginMode || "usdc").toLowerCase(); + const mode = String(marginMode || "coin").toLowerCase(); if (mode !== "coin") { if (usdt === null || usdt === undefined || usdt === "") return "—"; const n = Number(usdt); @@ -1203,7 +1203,7 @@ function accountSnapshotFundingMissing(data){ let accountSnapshotRetryCount = 0; function applyAccountSnapshot(data){ if(!data || typeof data !== "object") return; - const coinMode = String(data.options_margin_mode || "usdc").toLowerCase() === "coin"; + const coinMode = String(data.options_margin_mode || "coin").toLowerCase() === "coin"; if(typeof data.show_perp_funds !== "undefined"){ applyPerpFundsVisibility(data.show_perp_funds !== false || coinMode); } else if (coinMode) { diff --git a/lib/instance/templates/index.html b/lib/instance/templates/index.html index 166452b..7d9d409 100644 --- a/lib/instance/templates/index.html +++ b/lib/instance/templates/index.html @@ -1624,7 +1624,7 @@ function formatOptionsFundingLabel(usdc, usdt, eth, marginMode, underly) { return `${n.toFixed(2)} USDC`; } function formatTradingAccountLabel(usdt, eth, btc, marginMode) { - const mode = String(marginMode || "usdc").toLowerCase(); + const mode = String(marginMode || "coin").toLowerCase(); if (mode !== "coin") { if (usdt == null || usdt === "") return "—"; const n = Number(usdt); @@ -1684,7 +1684,7 @@ function accountSnapshotFundingMissing(data){ let accountSnapshotRetryCount = 0; function applyAccountSnapshot(data){ if(!data || typeof data !== "object") return; - const coinMode = String(data.options_margin_mode || "usdc").toLowerCase() === "coin"; + const coinMode = String(data.options_margin_mode || "coin").toLowerCase() === "coin"; if(typeof data.show_perp_funds !== "undefined"){ applyPerpFundsVisibility(data.show_perp_funds !== false || coinMode); } else if (coinMode) { diff --git a/lib/instance/templates/instance_header_panel.html b/lib/instance/templates/instance_header_panel.html index aacd106..4f3a675 100644 --- a/lib/instance/templates/instance_header_panel.html +++ b/lib/instance/templates/instance_header_panel.html @@ -38,11 +38,11 @@ {% include 'instance_header_stats.html' %}
- {% set _coin_margin = (options_margin_mode|default('usdc')) == 'coin' %} + {% set _coin_margin = (options_margin_mode|default('coin')) == 'coin' %} {% set _show_perp = (show_perp_funds|default(true)) or _coin_margin %}