Support LIVE exchange funds and perp margin mode.
Hide sim equity when LIVE is selected; OKX funds bar uses exchange balances; add cross/isolated for perp only (options stay cash). Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -115,9 +115,13 @@ async def funds_summary(_user: Annotated[str, Depends(require_user)]) -> dict[st
|
||||
trading_usdt = bal.get("trading_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
|
||||
r = float(rate) if rate and rate > 0 else 1.0
|
||||
total = round(
|
||||
(funding_usdt or 0.0)
|
||||
+ (trading_usdt or 0.0)
|
||||
+ ((funding_usdc or 0.0) + (trading_usdc or 0.0)) * r,
|
||||
2,
|
||||
)
|
||||
except Exception as e:
|
||||
return {
|
||||
"ok": False,
|
||||
@@ -128,11 +132,13 @@ async def funds_summary(_user: Annotated[str, Depends(require_user)]) -> dict[st
|
||||
finally:
|
||||
client.close()
|
||||
else:
|
||||
# 非 OKX LIVE:回退本地账本
|
||||
led = Ledger(db).snapshot()
|
||||
trading_usdt = float(led["equity"])
|
||||
total = trading_usdt
|
||||
|
||||
# 非 OKX LIVE:暂无统一资金接口,不回退模拟账本(避免实盘显示假资金)
|
||||
return {
|
||||
"ok": False,
|
||||
"mode": mode,
|
||||
"exchange": exchange,
|
||||
"detail": f"{exchange} 实盘资金摘要暂未接入,请用 OKX 或交易所 App 查看",
|
||||
}
|
||||
return {
|
||||
"ok": True,
|
||||
"mode": mode,
|
||||
|
||||
@@ -37,6 +37,7 @@ KEYS = (
|
||||
"skip_weekends",
|
||||
"initial_equity",
|
||||
"leverage",
|
||||
"perp_margin_mode",
|
||||
"min_option_hours",
|
||||
"min_option_leverage",
|
||||
"atm_open_offset_enabled",
|
||||
@@ -61,6 +62,7 @@ class StrategySettingsBody(BaseModel):
|
||||
skip_weekends: bool | None = None
|
||||
initial_equity: float | None = Field(default=None, ge=1000, le=10_000_000)
|
||||
leverage: float | None = Field(default=None, ge=1, le=125)
|
||||
perp_margin_mode: str | None = Field(default=None, pattern="^(cross|isolated)$")
|
||||
min_option_hours: float | None = Field(default=None, ge=1, le=720)
|
||||
min_option_leverage: float | None = Field(default=None, ge=1, le=10000)
|
||||
atm_open_offset_enabled: bool | None = None
|
||||
@@ -117,6 +119,20 @@ def _read_settings() -> dict:
|
||||
db.get_setting("initial_equity", str(s.initial_equity)) or s.initial_equity
|
||||
),
|
||||
"leverage": float(db.get_setting("leverage", str(s.leverage)) or s.leverage),
|
||||
"perp_margin_mode": (
|
||||
mm
|
||||
if (
|
||||
mm := str(
|
||||
db.get_setting("perp_margin_mode", s.perp_margin_mode)
|
||||
or s.perp_margin_mode
|
||||
or "cross"
|
||||
)
|
||||
.strip()
|
||||
.lower()
|
||||
)
|
||||
in ("cross", "isolated")
|
||||
else "cross"
|
||||
),
|
||||
"min_option_hours": float(
|
||||
db.get_setting("min_option_hours", str(s.min_option_hours))
|
||||
or s.min_option_hours
|
||||
|
||||
Reference in New Issue
Block a user