单笔期权默认改为币本位;未配置时按coin处理
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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×缓冲复利;上限开关默认关(靠人工转走)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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`(建议默认开) |
|
||||
|
||||
Vendored
+1
-1
@@ -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", "以期权为主"),
|
||||
|
||||
Vendored
+1
-1
@@ -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",
|
||||
|
||||
@@ -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 "—"
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -13,6 +13,10 @@ class TestOptionsMarginMode(unittest.TestCase):
|
||||
self.assertEqual(normalize_options_margin_mode("usdc"), "usdc")
|
||||
self.assertEqual(normalize_options_margin_mode("coin"), "coin")
|
||||
self.assertEqual(normalize_options_margin_mode("币本位"), "coin")
|
||||
with patch.dict(os.environ, {}, clear=False):
|
||||
os.environ.pop("OKX_OPTIONS_MARGIN_MODE", None)
|
||||
self.assertEqual(normalize_options_margin_mode(None), "coin")
|
||||
self.assertEqual(normalize_options_margin_mode(""), "coin")
|
||||
|
||||
def test_inst_family(self):
|
||||
from lib.options.options_margin_mode_lib import inst_family_for_underlying
|
||||
|
||||
Reference in New Issue
Block a user