单笔期权默认改为币本位;未配置时按coin处理

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-20 14:05:44 +08:00
parent 6c49c7d51c
commit 4fb3be35ef
14 changed files with 34 additions and 25 deletions
+1 -1
View File
@@ -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", "以期权为主"),
+1 -1
View File
@@ -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",
+1 -1
View File
@@ -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 ""
+1 -1
View File
@@ -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()
@@ -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) {
+2 -2
View File
@@ -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) {
@@ -38,11 +38,11 @@
{% include 'instance_header_stats.html' %}
</div>
<div class="instance-header-phone-strip instance-phone-only" aria-label="手机资金摘要">
{% 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 %}
<span class="inst-phone-chip"{% if not _show_perp %} style="display:none"{% endif %} data-perp-funds="1">
<em>交易</em>
<b data-funds-field="current-capital">{{ trading_account_label(current_capital, options_trading_eth, options_trading_btc, margin_mode=options_margin_mode|default('usdc')) }}</b>
<b data-funds-field="current-capital">{{ trading_account_label(current_capital, options_trading_eth, options_trading_btc, margin_mode=options_margin_mode|default('coin')) }}</b>
</span>
<span class="inst-phone-chip"{% if not _show_perp %} style="display:none"{% endif %} data-perp-funds="1">
<em>资金</em>
@@ -1,5 +1,5 @@
{# 资金与统计条(顶栏 / 系统设置共用,单行展示) #}
{% 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 %}
<div class="instance-header-stats{% if options_enabled %} instance-header-stats--options{% endif %}">
<div class="stat-strip-item stat-strip-item--primary">
@@ -32,7 +32,7 @@
</div>
<div class="stat-strip-item"{% if not _show_perp %} style="display:none"{% endif %} data-perp-funds="1">
<div class="label">交易账户</div>
<div class="value" id="current-capital" data-funds-field="current-capital">{{ trading_account_label(current_capital, options_trading_eth, options_trading_btc, margin_mode=options_margin_mode|default('usdc')) }}</div>
<div class="value" id="current-capital" data-funds-field="current-capital">{{ trading_account_label(current_capital, options_trading_eth, options_trading_btc, margin_mode=options_margin_mode|default('coin')) }}</div>
</div>
{% if options_enabled and not _coin_margin %}
<div class="stat-strip-item" data-options-funds="1">
+8 -3
View File
@@ -24,13 +24,18 @@ def _env_float(name: str, default: float) -> float:
def normalize_options_margin_mode(raw: Any = None) -> str:
"""返回 usdc | coin."""
"""返回 usdc | coin;未配置时默认币本位."""
if raw is None:
raw = os.getenv("OKX_OPTIONS_MARGIN_MODE")
v = str(raw or MODE_USDC).strip().lower()
v = str(raw or MODE_COIN).strip().lower()
if v in ("usdc", "usdc_margin", "usd_margin", "u本位", "u"):
return MODE_USDC
if v in ("coin", "coin_margin", "crypto", "crypto_margin", "币本位"):
return MODE_COIN
return MODE_USDC
# 空串或未知值:默认币本位
if not v:
return MODE_COIN
return MODE_COIN
def is_coin_margin_mode(raw: Any = None) -> bool:
+1 -1
View File
@@ -106,7 +106,7 @@ def _build_cfg(app_module: Any) -> dict[str, Any]:
"compound_full_enabled": _env_bool("OKX_OPTIONS_COMPOUND_FULL_ENABLED", True),
"compound_full_cap_enabled": _env_bool("OKX_OPTIONS_COMPOUND_FULL_CAP_ENABLED", False),
"compound_full_cap_usdc": _env_float("OKX_OPTIONS_COMPOUND_FULL_CAP_USDC", 300.0),
"margin_mode": (os.getenv("OKX_OPTIONS_MARGIN_MODE") or "usdc").strip().lower(),
"margin_mode": (os.getenv("OKX_OPTIONS_MARGIN_MODE") or "coin").strip().lower(),
"default_underly": (os.getenv("OKX_OPTIONS_DEFAULT_UNDERLY") or "ETH").strip().upper(),
"max_dte_days": _env_float("OKX_OPTIONS_MAX_DTE_DAYS", 2.0),
"chain_max_dte_days": _env_float("OKX_OPTIONS_CHAIN_MAX_DTE_DAYS", 14.0),