diff --git a/crypto_monitor_okx/app.py b/crypto_monitor_okx/app.py index 224e49d..473ad55 100644 --- a/crypto_monitor_okx/app.py +++ b/crypto_monitor_okx/app.py @@ -6528,6 +6528,7 @@ def render_main_page(page="trade", embed_mode=None): options_trading_usdc = None options_funding_usdc = None options_funding_usdt = None + options_trading_usdt = None if ( OKX_OPTIONS_ENABLED and exchange_options.apiKey @@ -6536,13 +6537,14 @@ def render_main_page(page="trade", embed_mode=None): try: from lib.exchange.okx_options_lib import options_header_balances - options_trading_usdc, options_funding_usdc, options_funding_usdt = options_header_balances( + options_trading_usdc, options_funding_usdc, options_funding_usdt, options_trading_usdt = options_header_balances( exchange_options ) except Exception: options_trading_usdc = None options_funding_usdc = None options_funding_usdt = None + options_trading_usdt = None recommended_capital = get_recommended_capital(current_capital) key_list = ( conn.execute("SELECT * FROM key_monitors").fetchall() if plan.key_list else [] @@ -6675,10 +6677,12 @@ def render_main_page(page="trade", embed_mode=None): options_trading_usdc, options_funding_usdc, options_funding_usdt, + options_trading_usdt, ), options_funding_usdc=options_funding_usdc, options_funding_usdt=options_funding_usdt, options_trading_usdc=options_trading_usdc, + options_trading_usdt=options_trading_usdt, trading_day=trading_day, daily_start_capital=DAILY_START_CAPITAL, current_capital=current_capital, @@ -6887,11 +6891,12 @@ def api_account_snapshot(): options_trading_usdc = None options_funding_usdc = None options_funding_usdt = None + options_trading_usdt = None if OKX_OPTIONS_ENABLED and exchange_options.apiKey: try: from lib.exchange.okx_options_lib import options_header_balances - options_trading_usdc, options_funding_usdc, options_funding_usdt = options_header_balances( + options_trading_usdc, options_funding_usdc, options_funding_usdt, options_trading_usdt = options_header_balances( exchange_options, force=force_refresh, ) @@ -6899,6 +6904,7 @@ def api_account_snapshot(): options_trading_usdc = None options_funding_usdc = None options_funding_usdt = None + options_trading_usdt = None recommended_capital = get_recommended_capital(current_capital) from lib.strategy.strategy_trade_labels import count_position_limit_active_monitors @@ -6954,12 +6960,14 @@ def api_account_snapshot(): "options_funding_usdc": options_funding_usdc, "options_funding_usdt": options_funding_usdt, "options_trading_usdc": options_trading_usdc, + "options_trading_usdt": options_trading_usdt, "total_funds": total_funds_usdt( funding_usdt, current_capital, options_trading_usdc, options_funding_usdc, options_funding_usdt, + options_trading_usdt, ), "available_trading_usdt": round(available_trading_usdt, FUNDS_DECIMALS) if available_trading_usdt is not None else None, "unrealized_pnl": unrealized_pnl, diff --git a/lib/exchange/okx_options_lib.py b/lib/exchange/okx_options_lib.py index 8efc2f8..9445876 100644 --- a/lib/exchange/okx_options_lib.py +++ b/lib/exchange/okx_options_lib.py @@ -446,8 +446,8 @@ def options_header_balances( ex: ccxt.okx, *, force: bool = False, -) -> tuple[float | None, float | None, float | None]: - """顶栏三格:交易 USDC,资金 USDC,资金 USDT(单次拉取 + 缓存).""" +) -> tuple[float | None, float | None, float | None, float | None]: + """顶栏四格:交易 USDC/USDT,资金 USDC/USDT(单次拉取 + 缓存).""" bal = fetch_options_balances(ex, force=force) def _round(v: Any) -> float | None: @@ -462,6 +462,7 @@ def options_header_balances( _round(bal.get("trading_usdc")), _round(bal.get("funding_usdc")), _round(bal.get("funding_usdt")), + _round(bal.get("trading_usdt")), ) @@ -1110,7 +1111,7 @@ def spot_market_swap_usdt_usdc( "side": "buy", "ordType": "market", "sz": str(amount), - "tgtCcy": "quote", + "tgtCcy": "quote_ccy", } elif d == "usdc_to_usdt": body = { @@ -1119,7 +1120,7 @@ def spot_market_swap_usdt_usdc( "side": "sell", "ordType": "market", "sz": str(amount), - "tgtCcy": "base", + "tgtCcy": "base_ccy", } else: return {"ok": False, "msg": "direction 须为 usdt_to_usdc 或 usdc_to_usdt"} diff --git a/lib/instance/instance_embed_context_lib.py b/lib/instance/instance_embed_context_lib.py index 9a19d38..e184a61 100644 --- a/lib/instance/instance_embed_context_lib.py +++ b/lib/instance/instance_embed_context_lib.py @@ -103,6 +103,7 @@ def total_funds_usdt( options_trading_usdc: float | None = None, options_funding_usdc: float | None = None, options_funding_usdt: float | None = None, + options_trading_usdt: float | None = None, ) -> float | None: if funding_usdt is None: return None @@ -114,6 +115,8 @@ def total_funds_usdt( total += float(options_funding_usdt) if options_trading_usdc is not None: total += float(options_trading_usdc) + if options_trading_usdt is not None: + total += float(options_trading_usdt) return round(total, 2) except (TypeError, ValueError): return None diff --git a/lib/instance/templates/embed_boot_scripts.html b/lib/instance/templates/embed_boot_scripts.html index 03645ae..195e934 100644 --- a/lib/instance/templates/embed_boot_scripts.html +++ b/lib/instance/templates/embed_boot_scripts.html @@ -1168,8 +1168,9 @@ function applyAccountSnapshot(data){ const optFunding = formatOptionsFundingLabel(data.options_funding_usdc, data.options_funding_usdt); if(optFunding !== "—") setFundsFieldText("options-funding-usdc", optFunding); } - if(data.options_trading_usdc != null && data.options_trading_usdc !== ""){ - setFundsFieldText("options-trading-usdc", `${Number(data.options_trading_usdc).toFixed(2)} USDC`); + if(data.options_trading_usdc != null || data.options_trading_usdt != null){ + const optTrading = formatOptionsFundingLabel(data.options_trading_usdc, data.options_trading_usdt); + if(optTrading !== "—") setFundsFieldText("options-trading-usdc", optTrading); } if(typeof data.unrealized_pnl !== "undefined"){ updateRealtimePnl(data.unrealized_pnl); diff --git a/lib/instance/templates/index.html b/lib/instance/templates/index.html index 8b29f30..3bfa6da 100644 --- a/lib/instance/templates/index.html +++ b/lib/instance/templates/index.html @@ -1813,8 +1813,9 @@ function applyAccountSnapshot(data){ const optFunding = formatOptionsFundingLabel(data.options_funding_usdc, data.options_funding_usdt); if(optFunding !== "—") setFundsFieldText("options-funding-usdc", optFunding); } - if(data.options_trading_usdc != null && data.options_trading_usdc !== ""){ - setFundsFieldText("options-trading-usdc", `${Number(data.options_trading_usdc).toFixed(2)} USDC`); + if(data.options_trading_usdc != null || data.options_trading_usdt != null){ + const optTrading = formatOptionsFundingLabel(data.options_trading_usdc, data.options_trading_usdt); + if(optTrading !== "—") setFundsFieldText("options-trading-usdc", optTrading); } if(typeof data.unrealized_pnl !== "undefined"){ updateRealtimePnl(data.unrealized_pnl); diff --git a/lib/instance/templates/instance_header_stats.html b/lib/instance/templates/instance_header_stats.html index 32aa2d0..86b3416 100644 --- a/lib/instance/templates/instance_header_stats.html +++ b/lib/instance/templates/instance_header_stats.html @@ -39,7 +39,7 @@