Fix OKX spot swap tgtCcy and show options trading USDT in header.

OKX requires quote_ccy/base_ccy for market orders; include trading_usdt in balance display and total funds.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-12 08:42:33 +08:00
parent 04fd84757c
commit 551c86264a
8 changed files with 70 additions and 11 deletions
+5 -4
View File
@@ -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"}
@@ -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
@@ -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);
+3 -2
View File
@@ -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);
@@ -39,7 +39,7 @@
</div>
<div class="stat-strip-item">
<div class="label">期权交易账户</div>
<div class="value" id="options-trading-usdc" data-funds-field="options-trading-usdc">{% if options_trading_usdc is not none %}{{ funds_fmt(options_trading_usdc) }} USDC{% else %}—{% endif %}</div>
<div class="value" id="options-trading-usdc" data-funds-field="options-trading-usdc">{{ options_funding_label(options_trading_usdc, options_trading_usdt) }}</div>
</div>
{% endif %}
<div class="stat-strip-item stat-strip-item--pnl">