下线永续监控与 USDC 期权,仅保留币本位期权路径。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-07 12:32:01 +08:00
parent 1a4eb15109
commit 7c5a6e25b2
10 changed files with 1581 additions and 2228 deletions
+1 -1
View File
@@ -116,7 +116,7 @@ OKX_OPTIONS_ENABLED=true
# OKX_OPTIONS_API_PASSPHRASE=
OKX_OPTIONS_ACCOUNT_LABEL=账户·期权
# 固定币本位(USDT买币桥);历史 OKX_OPTIONS_MARGIN_MODE=usdc 会被忽略并视为 coin
# 仅币本位期权(USDT买币桥);USDC 期权已下线,此项恒视为 coin
OKX_OPTIONS_MARGIN_MODE=coin
OKX_OPTIONS_COIN_COMPOUND=true
OKX_OPTIONS_COIN_BUDGET_USDT=10
+6 -22
View File
@@ -5117,23 +5117,9 @@ def force_close_before_reset():
conn.commit()
conn.close()
# 后台线程
# 后台线程(永续已下线:不再跑划转/强平/关键位/委托监控;期权监控见 options_monitor_loop)
def background_task():
while True:
try:
auto_transfer_once_per_day()
# force_close 自带连接,勿套在另一未关闭连接上
force_close_before_reset()
conn = get_db()
try:
reconcile_external_closes(conn)
conn.commit()
finally:
conn.close()
check_key_monitors()
check_order_monitors()
except Exception as e:
print(f"[monitor_loop] {e}", flush=True)
time.sleep(MONITOR_POLL_SECONDS)
@@ -5637,16 +5623,14 @@ def index():
@app.route("/key_monitor")
@login_required
def key_monitor_page():
redir = redirect_to_embed_shell_if_enabled("key_monitor")
if redir is not None:
return redir
return render_main_page("key_monitor")
# 永续关键位监控已下线
return redirect("/options")
@app.route("/trade")
@login_required
def trade_page():
# 实盘下单界面已移除;永续下单仍由对冲计划走 place_exchange_order
# 永续实盘下单已下线
return redirect("/options")
@@ -6303,7 +6287,7 @@ def order_focus():
@login_required
def add_order():
# 实盘下单界面已移除;永续开平仓请走对冲计划(place_exchange_order / close_exchange_order)
flash("实盘下单界面已移除,请使用对冲计划或期权页")
flash("永续实盘下单已下线,请使用期权页")
return redirect("/options")
@@ -7679,5 +7663,5 @@ if __name__ == "__main__":
from lib.common.flask_access_log_lib import silence_werkzeug_access_log
silence_werkzeug_access_log()
threading.Thread(target=background_task, daemon=True).start()
# 永续 background_task 已下线;期权监控由 install_options_trading 启动
app.run(host=HOST, port=PORT, debug=DEBUG, threaded=True)
+8 -24
View File
@@ -415,41 +415,25 @@
function syncOptionsSectionVisibility(body) {
if (!body) return;
var margin = (envFieldValue(body, "OKX_OPTIONS_MARGIN_MODE", "coin") || "coin").toLowerCase();
var isCoin = margin !== "usdc";
// 仅币本位期权:USDC/永续相关 env 始终隐藏
var isCoin = true;
var gateMode = (envFieldValue(body, "OKX_OPTIONS_CLOSE_GATE_MODE", "premium") || "premium").toLowerCase();
var compoundOn = envTruthy(envFieldValue(body, "OKX_OPTIONS_COMPOUND_FULL_ENABLED", "true"));
var coinCompoundOn = envTruthy(envFieldValue(body, "OKX_OPTIONS_COIN_COMPOUND", "true"));
var coinMaxOn = envTruthy(envFieldValue(body, "OKX_OPTIONS_COIN_MAX_USDT_ENABLED", "false"));
var compoundCapOn = envTruthy(envFieldValue(body, "OKX_OPTIONS_COMPOUND_FULL_CAP_ENABLED", "false"));
COIN_ONLY_ENV_KEYS.forEach(function (key) {
setEnvRowHidden(envFieldRowByKey(body, key), !isCoin);
});
USDC_ONLY_ENV_KEYS.forEach(function (key) {
setEnvRowHidden(envFieldRowByKey(body, key), isCoin);
setEnvRowHidden(envFieldRowByKey(body, key), true);
});
setEnvRowHidden(envFieldRowByKey(body, "OKX_OPTIONS_MARGIN_MODE"), true);
setEnvRowHidden(envFieldRowByKey(body, "OKX_SHOW_PERP_FUNDS"), true);
// 门控子项:按模式显隐(仍受本位过滤)
if (isCoin) {
setEnvRowHidden(envFieldRowByKey(body, "OKX_OPTIONS_CLOSE_RECYCLE_MULT_COIN"), gateMode !== "premium");
} else {
setEnvRowHidden(envFieldRowByKey(body, "OKX_OPTIONS_CLOSE_RECYCLE_MULT"), gateMode !== "premium");
}
setEnvRowHidden(envFieldRowByKey(body, "OKX_OPTIONS_CLOSE_RECYCLE_MULT_COIN"), gateMode !== "premium");
setEnvRowHidden(envFieldRowByKey(body, "OKX_OPTIONS_CLOSE_NET_PNL_MIN_USDT"), gateMode !== "net_pnl");
if (!isCoin) {
setEnvRowHidden(envFieldRowByKey(body, "OKX_OPTIONS_TRADE_BUDGET_USDC"), compoundOn);
setEnvRowHidden(envFieldRowByKey(body, "OKX_OPTIONS_COMPOUND_FULL_CAP_ENABLED"), !compoundOn);
setEnvRowHidden(
envFieldRowByKey(body, "OKX_OPTIONS_COMPOUND_FULL_CAP_USDC"),
!(compoundOn && compoundCapOn)
);
}
if (isCoin) {
setEnvRowHidden(envFieldRowByKey(body, "OKX_OPTIONS_COIN_BUDGET_USDT"), coinCompoundOn);
setEnvRowHidden(envFieldRowByKey(body, "OKX_OPTIONS_COIN_MAX_USDT"), !coinMaxOn);
}
setEnvRowHidden(envFieldRowByKey(body, "OKX_OPTIONS_COIN_BUDGET_USDT"), coinCompoundOn);
setEnvRowHidden(envFieldRowByKey(body, "OKX_OPTIONS_COIN_MAX_USDT"), !coinMaxOn);
}
function bindOptionsSectionVisibility(body) {
+13 -2
View File
@@ -313,16 +313,27 @@ def _field_current(fields: list[dict[str, Any]], key: str, default: str = "") ->
def _mark_options_section_hidden(fields: list[dict[str, Any]]) -> list[dict[str, Any]]:
"""按门控模式/复利/单笔上限标记 hidden."""
"""按门控模式/复利/单笔上限标记 hidden;USDC/永续相关项始终隐藏."""
gate_mode = (_field_current(fields, "OKX_OPTIONS_CLOSE_GATE_MODE", "premium") or "premium").lower()
coin_compound_on = _env_truthy(_field_current(fields, "OKX_OPTIONS_COIN_COMPOUND", "true"))
coin_max_on = _env_truthy(_field_current(fields, "OKX_OPTIONS_COIN_MAX_USDT_ENABLED", "false"))
retired = {
"OKX_OPTIONS_MARGIN_MODE",
"OKX_OPTIONS_TRADE_BUDGET_USDC",
"OKX_OPTIONS_COMPOUND_FULL_ENABLED",
"OKX_OPTIONS_COMPOUND_FULL_CAP_ENABLED",
"OKX_OPTIONS_COMPOUND_FULL_CAP_USDC",
"OKX_OPTIONS_CLOSE_RECYCLE_MULT",
"OKX_SHOW_PERP_FUNDS",
}
out: list[dict[str, Any]] = []
for f in fields:
key = str(f.get("key") or "")
hide = False
if key == "OKX_OPTIONS_CLOSE_RECYCLE_MULT_COIN" and gate_mode != "premium":
if key in retired:
hide = True
elif key == "OKX_OPTIONS_CLOSE_RECYCLE_MULT_COIN" and gate_mode != "premium":
hide = True
elif key == "OKX_OPTIONS_CLOSE_NET_PNL_MIN_USDT" and gate_mode != "net_pnl":
hide = True
+1 -1
View File
@@ -814,7 +814,7 @@ def build_option_chain(
family = inst_family_for_underlying(u, margin_mode=margin_mode)
except Exception:
family = f"{u}-USD_UM"
family = f"{u}-USD"
uly = f"{u}-USD"
idx = index_px if index_px is not None else fetch_index_price(ex, uly)
now_ms = time.time() * 1000
+6 -9
View File
@@ -10,8 +10,8 @@ DISPLAY_RUNTIME_PREFIX = "display."
DEFAULT_INSTANCE_DISPLAY: dict[str, bool] = {
"show_nav_dashboard": False,
"show_nav_account_ledger": False,
"show_nav_key_monitor": True,
"show_nav_trade": False, # 实盘下单界面已移除
"show_nav_key_monitor": False, # 永续关键位已下线
"show_nav_trade": False, # 永续实盘下单已下线
"show_nav_strategy": False,
"show_nav_strategy_records": False,
"show_nav_records": False, # 永续交易记录与复盘已移除
@@ -22,10 +22,10 @@ DEFAULT_INSTANCE_DISPLAY: dict[str, bool] = {
"show_nav_env_config": True,
"show_nav_options": True,
"show_nav_options_review": True,
"show_settings_transfer": False, # 永续资金划转默认隐藏
"show_settings_transfer": False, # 永续资金划转已下线
"show_settings_export": True,
"show_settings_password": True,
"show_settings_options_swap": True,
"show_settings_options_swap": False, # USDC 币种兑换已下线
"show_settings_options_transfer": True,
}
@@ -111,8 +111,8 @@ def display_prefs_template_context(get_db: Callable) -> dict[str, Any]:
def tab_allowed(tab: str, display: Optional[dict[str, bool]] = None) -> bool:
prefs = normalize_display_prefs(display or {})
t = (tab or "").strip()
if t in ("trade", "records", "stats", "hedge_plan"):
return False # 实盘下单 / 交易记录复盘 / 统计分析 / 对冲计划 已移除
if t in ("trade", "records", "stats", "hedge_plan", "key_monitor"):
return False # 永续相关页面已下线
key = NAV_TAB_ALLOWED.get(t)
if not key:
return True
@@ -123,7 +123,6 @@ def display_meta_for_ui() -> list[dict[str, Any]]:
nav_keys = [
"show_nav_dashboard",
"show_nav_account_ledger",
"show_nav_key_monitor",
"show_nav_risk_policy",
"show_nav_live_guide",
"show_nav_system_guide",
@@ -132,10 +131,8 @@ def display_meta_for_ui() -> list[dict[str, Any]]:
"show_nav_options_review",
]
settings_keys = [
"show_settings_transfer",
"show_settings_export",
"show_settings_password",
"show_settings_options_swap",
"show_settings_options_transfer",
]
return [
+1 -12
View File
@@ -127,21 +127,10 @@ def build_settings_tabs(display: dict[str, Any] | None, instance_settings: dict[
tabs.append({"key": "sim_funds", "title": "模拟资金"})
if disp.get("show_settings_password", True):
tabs.append({"key": "password", "title": "账户密码"})
if inst.get("show_transfer") and disp.get("show_settings_transfer", False):
tabs.append({"key": "transfer", "title": "永续划转"})
# 永续划转 / USDC 币种兑换已下线
if disp.get("show_settings_export", True):
tabs.append({"key": "export", "title": "数据导出"})
tabs.append({"key": "backup", "title": "备份恢复"})
if inst.get("options_settings_enabled") and disp.get("show_settings_options_swap", True):
_coin = False
try:
from lib.options.options_margin_mode_lib import is_coin_margin_mode
_coin = bool(is_coin_margin_mode())
except Exception:
_coin = False
if not _coin:
tabs.append({"key": "options_swap", "title": "币种兑换"})
if inst.get("options_settings_enabled") and disp.get("show_settings_options_transfer", True):
tabs.append({"key": "options_transfer", "title": "期权划转"})
return tabs
+11 -17
View File
@@ -642,29 +642,23 @@ def _try_open_full(
inst_id: str,
order: dict[str, Any],
) -> dict[str, Any]:
from lib.options.options_margin_mode_lib import is_coin_margin_mode
from lib.options.options_coin_open_lib import open_coin_option_buy_full
note = f"中控条件单:{order.get('hub_order_id')}"
target_index = _safe_float(order.get("target_index"))
pe_en = bool(order.get("profit_exit_enabled"))
pe_mult = float(order.get("profit_exit_mult") or 1.0)
if is_coin_margin_mode():
return open_coin_option_buy_full(
cfg,
ex,
inst_id=inst_id,
signal_note=note,
target_index=target_index,
profit_exit_enabled=pe_en,
profit_exit_mult=pe_mult,
target_sheets=None,
)
return {
"ok": False,
"msg": "条件单开仓当前仅支持币本位客户端规则(买币→开仓)",
"need_depth": False,
}
# USDC 期权开仓已下线,条件单仅走币本位
return open_coin_option_buy_full(
cfg,
ex,
inst_id=inst_id,
signal_note=note,
target_index=target_index,
profit_exit_enabled=pe_en,
profit_exit_mult=pe_mult,
target_sheets=None,
)
def run_cond_orders_tick(
+7 -7
View File
@@ -35,11 +35,10 @@ def is_coin_margin_mode(raw: Any = None) -> bool:
def inst_family_for_underlying(underlying: str, *, margin_mode: str | None = None) -> str:
"""仅币本位期权族 {U}-USD;USD_UM 已下线."""
del margin_mode
u = (underlying or "ETH").strip().upper() or "ETH"
mode = normalize_options_margin_mode(margin_mode)
if mode == MODE_COIN:
return f"{u}-USD"
return f"{u}-USD_UM"
return f"{u}-USD"
def margin_mode_from_inst_id(inst_id: str) -> str:
@@ -55,9 +54,10 @@ def margin_mode_from_inst_id(inst_id: str) -> str:
def premium_ccy_for_mode(margin_mode: str, underlying: str = "ETH") -> str:
if normalize_options_margin_mode(margin_mode) == MODE_COIN:
return (underlying or "ETH").strip().upper() or "ETH"
return "USDC"
"""币本位权利金为标的币;历史 USDC 行(margin_mode=usdc)仍标 USDC."""
if str(margin_mode or "").strip().lower() == MODE_USDC:
return "USDC"
return (underlying or "ETH").strip().upper() or "ETH"
def spot_quote_inst_id(underlying: str) -> str:
File diff suppressed because it is too large Load Diff