Show both Call and Put legs for OO positions in control.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-07 17:40:45 +08:00
parent 3b5a8c1ff9
commit bd7640e36a
2 changed files with 146 additions and 68 deletions
+30 -2
View File
@@ -169,6 +169,12 @@ async def fleet_status(_tok: Annotated[str, Depends(require_fleet_token)]) -> di
except Exception:
st = {}
pos = st.get("position") if isinstance(st.get("position"), dict) else {}
hedge_mode = str(
pos.get("hedge_mode")
or st.get("hedge_mode")
or ""
).strip().lower()
is_oo = hedge_mode == "option_option" or bool(pos.get("option2_inst_id"))
legs: list[dict] = []
if pos.get("has_position") or str(pos.get("status") or "") in (
"open",
@@ -176,7 +182,8 @@ async def fleet_status(_tok: Annotated[str, Depends(require_fleet_token)]) -> di
"option_closed_perp_pending",
"opening",
):
if pos.get("perp_side") or pos.get("perp_inst_id"):
# 期期无永续腿;有 perp 才展示
if not is_oo and (pos.get("perp_side") or pos.get("perp_inst_id")):
legs.append(
{
"kind": "perp",
@@ -194,7 +201,7 @@ async def fleet_status(_tok: Annotated[str, Depends(require_fleet_token)]) -> di
legs.append(
{
"kind": "option",
"side": pos.get("option_side"),
"side": pos.get("option_side") or ("call" if is_oo else None),
"inst_id": pos.get("option_inst_id"),
"qty": pos.get("option_qty_eth"),
"avg_px": pos.get("option_entry_px"),
@@ -202,6 +209,22 @@ async def fleet_status(_tok: Annotated[str, Depends(require_fleet_token)]) -> di
"upl": pos.get("option_upl"),
"margin": None,
"premium": pos.get("initial_premium"),
"strike": pos.get("strike"),
}
)
if pos.get("option2_inst_id") or pos.get("option2_side"):
legs.append(
{
"kind": "option",
"side": pos.get("option2_side") or "put",
"inst_id": pos.get("option2_inst_id"),
"qty": pos.get("option2_qty_eth"),
"avg_px": pos.get("option2_entry_px"),
"mark_px": pos.get("option2_mark_px"),
"upl": pos.get("option2_upl"),
"margin": None,
"premium": pos.get("initial_premium2"),
"strike": pos.get("strike2"),
}
)
@@ -292,6 +315,7 @@ async def fleet_status(_tok: Annotated[str, Depends(require_fleet_token)]) -> di
if (
hm := str(
st.get("hedge_mode")
or ("option_option" if is_oo else None)
or db.get_setting("hedge_mode", settings.hedge_mode)
or settings.hedge_mode
or "perp_option"
@@ -306,15 +330,19 @@ async def fleet_status(_tok: Annotated[str, Depends(require_fleet_token)]) -> di
"position": {
"status": pos.get("status") or ("open" if pos.get("has_position") else "flat"),
"has_position": bool(pos.get("has_position")),
"hedge_mode": "option_option" if is_oo else "perp_option",
"group_id": pos.get("group_id"),
"open_at_ms": pos.get("open_at_ms"),
"initial_premium": pos.get("initial_premium"),
"initial_premium2": pos.get("initial_premium2"),
"perp_margin": pos.get("perp_margin"),
"exit_target_usdt": pos.get("exit_target_usdt"),
"net_pnl": pos.get("net_pnl"),
"perp_upl": pos.get("perp_upl"),
"option_upl": pos.get("option_upl"),
"option2_upl": pos.get("option2_upl"),
"strike": pos.get("strike"),
"strike2": pos.get("strike2"),
"expiry_ymd": pos.get("expiry_ymd"),
"legs": legs,
},