Align funds to OKX funding/trading only; fold rules; match settings width.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -59,8 +59,8 @@ def _live_balances() -> dict[str, float | None]:
|
||||
out: dict[str, float | None] = {
|
||||
"funding_usdt": None,
|
||||
"trading_usdt": None,
|
||||
"options_funding_usdc": None,
|
||||
"options_trading_usdc": None,
|
||||
"funding_usdc": None,
|
||||
"trading_usdc": None,
|
||||
}
|
||||
try:
|
||||
from ..live.okx_funds import OkxFundsClient
|
||||
@@ -80,24 +80,21 @@ def _live_balances() -> dict[str, float | None]:
|
||||
|
||||
|
||||
def _sim_balances(db: Database) -> dict[str, float]:
|
||||
w = SimFundsWallets(db).snapshot()
|
||||
w = SimFundsWallets(db).view()
|
||||
led = Ledger(db).snapshot()
|
||||
avail = float(led.get("available") or 0)
|
||||
funding = float(w.get("funding_usdt") or 0)
|
||||
trading = float(w.get("trading_usdt") or 0)
|
||||
opt_f = float(w.get("options_funding_usdc") or 0)
|
||||
opt_t = float(w.get("options_trading_usdc") or 0)
|
||||
# 钱包未播种时回退账本可用
|
||||
usdt = funding + trading
|
||||
if usdt < 1e-9:
|
||||
usdt = avail
|
||||
usdc = opt_f + opt_t
|
||||
if usdc < 1e-9:
|
||||
# SIM 早期权利金从账本扣;无 USDC 钱包时用可用资金估期权可开
|
||||
usdc = avail
|
||||
trading_usdt = float(w.get("trading_usdt") or 0)
|
||||
trading_usdc = float(w.get("trading_usdc") or 0)
|
||||
# 未划转到交易账户时回退账本可用(兼容旧 SIM)
|
||||
if trading_usdt < 1e-9 and trading_usdc < 1e-9 and avail > 1e-9:
|
||||
return {
|
||||
"perp_usdt": avail,
|
||||
"option_usdc": avail,
|
||||
"ledger_available": avail,
|
||||
}
|
||||
return {
|
||||
"perp_usdt": usdt,
|
||||
"option_usdc": usdc,
|
||||
"perp_usdt": trading_usdt,
|
||||
"option_usdc": trading_usdc,
|
||||
"ledger_available": avail,
|
||||
}
|
||||
|
||||
@@ -130,21 +127,11 @@ def assess_open_capacity(db: Database | None = None) -> dict[str, Any]:
|
||||
have_opt = float(bal["option_usdc"])
|
||||
else:
|
||||
live = _live_balances()
|
||||
# 永续用交易账户;若为空则合并资金账户(提示需划转但仍可显示)
|
||||
t = live.get("trading_usdt")
|
||||
f = live.get("funding_usdt")
|
||||
if t is not None and t > 1e-9:
|
||||
have_perp = float(t)
|
||||
elif t is not None or f is not None:
|
||||
have_perp = float(t or 0) + float(f or 0)
|
||||
else:
|
||||
have_perp = None
|
||||
of_ = live.get("options_funding_usdc")
|
||||
ot_ = live.get("options_trading_usdc")
|
||||
if of_ is None and ot_ is None:
|
||||
have_opt = None
|
||||
else:
|
||||
have_opt = float(of_ or 0) + float(ot_ or 0)
|
||||
# OKX:永续与期权都在交易账户
|
||||
t_usdt = live.get("trading_usdt")
|
||||
t_usdc = live.get("trading_usdc")
|
||||
have_perp = float(t_usdt) if t_usdt is not None else None
|
||||
have_opt = float(t_usdc) if t_usdc is not None else None
|
||||
|
||||
perp_ok: bool | None
|
||||
if margin_need is None or have_perp is None:
|
||||
|
||||
Reference in New Issue
Block a user