feat期权标的白名单:可固定只显示 ETH 或 BTC。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -28,6 +28,18 @@ def _env_float(key: str, default: float) -> float:
|
||||
return float(default)
|
||||
|
||||
|
||||
def _underly_blocked(underlying: str | None = None, *, inst_id: str | None = None) -> str | None:
|
||||
"""热读白名单;返回拒因或 None."""
|
||||
from lib.options.options_underly_lib import (
|
||||
inst_underly_not_allowed_msg,
|
||||
underly_not_allowed_msg,
|
||||
)
|
||||
|
||||
if inst_id:
|
||||
return inst_underly_not_allowed_msg(inst_id)
|
||||
return underly_not_allowed_msg(underlying or "")
|
||||
|
||||
|
||||
def attach_options_templates(app: Flask, repo_root: str) -> None:
|
||||
tpl_dir = os.path.join(repo_root, "lib", "options", "templates")
|
||||
if not os.path.isdir(tpl_dir):
|
||||
@@ -527,7 +539,12 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
|
||||
ex, err = _require_options_ex(cfg)
|
||||
if ex is None:
|
||||
return jsonify({"ok": False, "msg": err})
|
||||
u = (request.args.get("underlying") or cfg["default_underly"]).upper()
|
||||
from lib.options.options_underly_lib import resolve_default_underly
|
||||
|
||||
u = (request.args.get("underlying") or resolve_default_underly()).upper()
|
||||
blocked = _underly_blocked(u)
|
||||
if blocked:
|
||||
return jsonify({"ok": False, "msg": blocked})
|
||||
# 热更新:链展示天数每次读 env,保存后刷新链即可
|
||||
chain_max_dte = _env_float("OKX_OPTIONS_CHAIN_MAX_DTE_DAYS", float(cfg.get("chain_max_dte_days") or 14))
|
||||
try:
|
||||
@@ -594,6 +611,9 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
|
||||
inst_id = (request.args.get("inst_id") or "").strip()
|
||||
if not inst_id:
|
||||
return jsonify({"ok": False, "msg": "缺少 inst_id"})
|
||||
blocked = _underly_blocked(inst_id=inst_id)
|
||||
if blocked:
|
||||
return jsonify({"ok": False, "msg": blocked, "can_open": False})
|
||||
q = cfg["quote_option_contract"](ex, inst_id)
|
||||
if not q.get("ok"):
|
||||
return jsonify(q)
|
||||
@@ -817,6 +837,9 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
|
||||
profit_exit_mult = normalize_profit_exit_mult(data.get("profit_exit_mult"), default=1.0)
|
||||
if not inst_id:
|
||||
return jsonify({"ok": False, "msg": "缺少 inst_id"})
|
||||
blocked = _underly_blocked(inst_id=inst_id)
|
||||
if blocked:
|
||||
return jsonify({"ok": False, "msg": blocked, "can_open": False})
|
||||
try:
|
||||
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
|
||||
@@ -1006,6 +1029,9 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
|
||||
|
||||
raw_eth = bal.get("trading_eth_avail") or bal.get("trading_eth")
|
||||
raw_btc = bal.get("trading_btc_avail") or bal.get("trading_btc")
|
||||
from lib.options.options_underly_lib import underly_cfg_snapshot
|
||||
|
||||
_uly_snap = underly_cfg_snapshot()
|
||||
spot_sell_hint = {
|
||||
"bridge_status": str(bridge.get("status") or "") if bridge else None,
|
||||
"bridge_underlying": str(bridge.get("underlying") or "").upper() if bridge else None,
|
||||
@@ -1014,7 +1040,8 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
|
||||
"trading_btc": display_sellable_coin(ex, "BTC", raw_btc),
|
||||
"min_sz_eth": spot_min_sell_sz(ex, "ETH"),
|
||||
"min_sz_btc": spot_min_sell_sz(ex, "BTC"),
|
||||
"default_underly": (cfg.get("default_underly") or "ETH").strip().upper(),
|
||||
"default_underly": _uly_snap["default_underly"],
|
||||
"allowed_underlys": _uly_snap["allowed_underlys"],
|
||||
}
|
||||
finally:
|
||||
conn_b.close()
|
||||
|
||||
Reference in New Issue
Block a user