This commit is contained in:
aaron 2026-03-31 21:38:25 +08:00
parent f45cb3c152
commit 436e94eb9b
3 changed files with 9 additions and 2 deletions

View File

@ -136,7 +136,7 @@ async def get_positions(
"size": abs(size),
"entry_price": pos["entry_price"],
"unrealized_pnl": pos["unrealized_pnl"],
"leverage": pos.get("leverage", {}).get("value", "N/A"),
"leverage": (pos.get("leverage") or {}).get("value", "N/A") if isinstance(pos.get("leverage"), dict) else (pos.get("leverage") or "N/A"),
"liquidation_price": pos.get("liquidation_price"),
"take_profit": tp_sl.get("take_profit"),
"stop_loss": tp_sl.get("stop_loss"),

View File

@ -928,7 +928,11 @@ class CryptoAgent:
# 转换持仓格式
position_list = []
for pos in hl_state["positions"]:
if not isinstance(pos, dict):
continue
position_data = pos.get("position", {})
if not isinstance(position_data, dict):
continue
coin = position_data.get("coin")
size = float(position_data.get("szi", 0))

View File

@ -355,6 +355,9 @@ class HyperliquidTradingService:
continue
order_type = order.get("order_type", {})
# 防御性检查:确保 order_type 是 dict
if not isinstance(order_type, dict):
continue
# 止盈:限价单
if "limit" in order_type and order["price"] > 0:
@ -583,7 +586,7 @@ class HyperliquidTradingService:
"size": size, # 正数=多头,负数=空头
"entry_price": float(position_data.get("entryPx", 0)),
"unrealized_pnl": float(position_data.get("unrealizedPnl", 0)),
"leverage": position_data.get("leverage", {}).get("value"),
"leverage": position_data.get("leverage", {}).get("value") if isinstance(position_data.get("leverage"), dict) else position_data.get("leverage"),
"liquidation_price": position_data.get("liquidationPx"),
"stop_loss": tp_sl_prices.get("stop_loss"),
"take_profit": tp_sl_prices.get("take_profit"),