对齐币本位期权:现货缓冲开仓、页头 ETH/BTC 余额与默认 coin 模式。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-20 15:01:19 +08:00
parent 432adfb602
commit c8688a11ae
26 changed files with 6218 additions and 3758 deletions
+55 -11
View File
@@ -5041,6 +5041,7 @@ def render_main_page(page="options", embed_mode=None):
show_perp_funds_enabled,
total_funds_usdt,
trade_records_summary,
trading_account_label,
)
plan = embed_render_plan(page, embed_mode)
@@ -5054,6 +5055,11 @@ def render_main_page(page="options", embed_mode=None):
options_funding_usdc = None
options_funding_usdt = None
options_trading_usdt = None
options_funding_eth = None
options_trading_eth = None
options_trading_btc = None
options_margin_mode = "coin"
options_underly = "ETH"
_sim_mode_for_header = False
_exchange_display_for_header = EXCHANGE_DISPLAY_NAME
try:
@@ -5073,16 +5079,28 @@ def render_main_page(page="options", embed_mode=None):
and (getattr(exchange_options, "apiKey", None) or _sim_mode_for_header)
):
try:
from lib.exchange.okx_options_lib import options_header_balances
from lib.exchange.okx_options_lib import options_header_balance_pack
options_trading_usdc, options_funding_usdc, options_funding_usdt, options_trading_usdt = options_header_balances(
exchange_options
)
_op = options_header_balance_pack(exchange_options)
options_trading_usdc = _op.get("trading_usdc")
options_funding_usdc = _op.get("funding_usdc")
options_funding_usdt = _op.get("funding_usdt")
options_trading_usdt = _op.get("trading_usdt")
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 "coin"
options_underly = _op.get("options_underly") or "ETH"
except Exception:
options_trading_usdc = None
options_funding_usdc = None
options_funding_usdt = None
options_trading_usdt = None
options_funding_eth = None
options_trading_eth = None
options_trading_btc = None
options_margin_mode = "coin"
options_underly = "ETH"
recommended_capital = get_recommended_capital(current_capital)
key_list = (
conn.execute("SELECT * FROM key_monitors").fetchall() if plan.key_list else []
@@ -5205,7 +5223,7 @@ def render_main_page(page="options", embed_mode=None):
_okx_trade_mode = get_okx_trade_mode()
_hedge_mode_on = _okx_trade_mode in ("perp_options", "options_options")
_show_perp_funds = show_perp_funds_enabled(exchange_key="okx")
_show_perp_funds = show_perp_funds_enabled(exchange_key="okx") or (options_margin_mode == "coin")
template_ctx = dict(
page=page,
key=key_list,
@@ -5228,6 +5246,11 @@ def render_main_page(page="options", embed_mode=None):
options_funding_usdt=options_funding_usdt,
options_trading_usdc=options_trading_usdc,
options_trading_usdt=options_trading_usdt,
options_funding_eth=options_funding_eth,
options_trading_eth=options_trading_eth,
options_trading_btc=options_trading_btc,
options_margin_mode=options_margin_mode,
options_underly=options_underly,
trading_day=trading_day,
daily_start_capital=DAILY_START_CAPITAL,
current_capital=current_capital,
@@ -5472,19 +5495,35 @@ def api_account_snapshot():
options_funding_usdc = None
options_funding_usdt = None
options_trading_usdt = None
options_funding_eth = None
options_trading_eth = None
options_trading_btc = None
options_margin_mode = "coin"
options_underly = "ETH"
if OKX_OPTIONS_ENABLED and exchange_options.apiKey:
try:
from lib.exchange.okx_options_lib import options_header_balances
from lib.exchange.okx_options_lib import options_header_balance_pack
options_trading_usdc, options_funding_usdc, options_funding_usdt, options_trading_usdt = options_header_balances(
exchange_options,
force=force_refresh,
)
_op = options_header_balance_pack(exchange_options, force=force_refresh)
options_trading_usdc = _op.get("trading_usdc")
options_funding_usdc = _op.get("funding_usdc")
options_funding_usdt = _op.get("funding_usdt")
options_trading_usdt = _op.get("trading_usdt")
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 "coin"
options_underly = _op.get("options_underly") or "ETH"
except Exception:
options_trading_usdc = None
options_funding_usdc = None
options_funding_usdt = None
options_trading_usdt = None
options_funding_eth = None
options_trading_eth = None
options_trading_btc = None
options_margin_mode = "coin"
options_underly = "ETH"
recommended_capital = get_recommended_capital(current_capital)
from lib.trade.trade_labels_lib import count_position_limit_active_monitors
@@ -5567,7 +5606,7 @@ def api_account_snapshot():
unrealized_pnl = merge_unrealized_pnl_components(unrealized_pnl, options_unrealized_pnl)
except Exception:
options_unrealized_pnl = None
_show_perp_funds = show_perp_funds_enabled(exchange_key="okx")
_show_perp_funds = show_perp_funds_enabled(exchange_key="okx") or (options_margin_mode == "coin")
try:
from lib.sim.mode_lib import exchange_mode_label as _ex_mode_label
from lib.sim.mode_lib import is_sim_mode as _is_sim
@@ -5584,6 +5623,11 @@ def api_account_snapshot():
"options_funding_usdt": options_funding_usdt,
"options_trading_usdc": options_trading_usdc,
"options_trading_usdt": options_trading_usdt,
"options_funding_eth": options_funding_eth,
"options_trading_eth": options_trading_eth,
"options_trading_btc": options_trading_btc,
"options_margin_mode": options_margin_mode,
"options_underly": options_underly,
"total_funds": total_funds_usdt(
funding_usdt if _show_perp_funds else None,
current_capital if _show_perp_funds else None,