Align funds to OKX funding/trading only; fold rules; match settings width.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-29 17:59:28 +08:00
parent 80c561bdce
commit 81e51236c0
8 changed files with 198 additions and 178 deletions
+20 -33
View File
@@ -34,12 +34,12 @@ def _pl_ratio(pnls: list[float]) -> float | None:
return round(avg_w / avg_l, 2)
def _fmt_opt(usdc: float | None, usdt: float | None) -> str:
def _fmt_acct(usdt: float | None, usdc: float | None) -> str:
parts: list[str] = []
if usdc is not None:
if usdt is not None:
parts.append(f"{usdt:.2f}U")
if usdc is not None and abs(usdc) > 1e-8:
parts.append(f"{usdc:.2f} USDC")
if usdt is not None and abs(usdt) > 1e-8:
parts.append(f"{usdt:.2f} USDT")
return " + ".join(parts) if parts else ""
@@ -51,8 +51,8 @@ class ConvertBody(BaseModel):
class TransferBody(BaseModel):
ccy: Literal["USDT", "USDC", "usdt", "usdc"] = "USDC"
amount: float = Field(gt=0)
from_account: str
to_account: str
from_account: Literal["funding", "trading"] = "funding"
to_account: Literal["funding", "trading"] = "trading"
@router.get("/summary")
@@ -96,18 +96,16 @@ async def funds_summary(_user: Annotated[str, Depends(require_user)]) -> dict[st
eq = float(Ledger(db).snapshot().get("equity") or 0)
if eq > 0:
w = wallets.reset_from_equity(eq)
funding_usdt = float(w["funding_usdt"])
trading_usdt = float(w["trading_usdt"])
opt_f_usdc = float(w["options_funding_usdc"])
opt_t_usdc = float(w["options_trading_usdc"])
opt_f_usdt = float(w["options_funding_usdt"])
opt_t_usdt = float(w["options_trading_usdt"])
total = wallets.total_usdt_equiv(w)
v = wallets.view()
funding_usdt = float(v["funding_usdt"])
trading_usdt = float(v["trading_usdt"])
funding_usdc = float(v["funding_usdc"])
trading_usdc = float(v["trading_usdc"])
total = wallets.total_usdt_equiv()
rate = usdc_usdt_mid_rate()
else:
rate = usdc_usdt_mid_rate()
funding_usdt = trading_usdt = None
opt_f_usdc = opt_t_usdc = opt_f_usdt = opt_t_usdt = None
funding_usdt = trading_usdt = funding_usdc = trading_usdc = None
total = None
if exchange == "OKX":
client = OkxFundsClient()
@@ -115,18 +113,9 @@ async def funds_summary(_user: Annotated[str, Depends(require_user)]) -> dict[st
bal = client.fetch_balances()
funding_usdt = bal.get("funding_usdt")
trading_usdt = bal.get("trading_usdt")
opt_f_usdc = bal.get("options_funding_usdc")
opt_t_usdc = bal.get("options_trading_usdc")
opt_f_usdt = bal.get("options_funding_usdt")
opt_t_usdt = bal.get("options_trading_usdt")
parts = [
funding_usdt,
trading_usdt,
opt_f_usdc,
opt_t_usdc,
opt_f_usdt,
opt_t_usdt,
]
funding_usdc = bal.get("funding_usdc")
trading_usdc = bal.get("trading_usdc")
parts = [funding_usdt, trading_usdt, funding_usdc, trading_usdc]
vals = [float(x) for x in parts if x is not None]
total = round(sum(vals), 2) if vals else None
except Exception as e:
@@ -155,12 +144,10 @@ async def funds_summary(_user: Annotated[str, Depends(require_user)]) -> dict[st
"total_funds": total,
"funding_usdt": funding_usdt,
"trading_usdt": trading_usdt,
"options_funding_usdc": opt_f_usdc,
"options_trading_usdc": opt_t_usdc,
"options_funding_usdt": opt_f_usdt,
"options_trading_usdt": opt_t_usdt,
"options_funding_label": _fmt_opt(opt_f_usdc, opt_f_usdt),
"options_trading_label": _fmt_opt(opt_t_usdc, opt_t_usdt),
"funding_usdc": funding_usdc,
"trading_usdc": trading_usdc,
"funding_label": _fmt_acct(funding_usdt, funding_usdc),
"trading_label": _fmt_acct(trading_usdt, trading_usdc),
"realtime_pnl": realtime,
"usdc_usdt_rate": rate,
"perp_inst_id": str(