get_positions
Retrieve current open positions showing unrealized profit/loss, leverage levels, and liquidation prices for portfolio management.
Instructions
List all open positions with unrealized PnL, leverage, and liquidation price
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/hyperliquid_mcp/client.py:111-130 (handler)The main handler function that implements get_positions logic. Fetches user state and returns a list of open positions with symbol, size, entry price, mark price, unrealized PnL, leverage, liquidation price, and margin used.
def get_positions(self) -> list[dict[str, Any]]: """List all open positions with PnL.""" if not self.wallet_address: raise ValueError("HYPERLIQUID_WALLET_ADDRESS is required.") state = self.info.user_state(self.wallet_address) positions = [] for pos in state.get("assetPositions", []): p = pos.get("position", {}) if float(p.get("szi", "0")) != 0: positions.append({ "symbol": p.get("coin"), "size": p.get("szi"), "entry_price": p.get("entryPx"), "mark_price": p.get("positionValue"), "unrealized_pnl": p.get("unrealizedPnl"), "leverage": p.get("leverage", {}).get("value"), "liquidation_price": p.get("liquidationPx"), "margin_used": p.get("marginUsed"), }) return positions - src/hyperliquid_mcp/server.py:60-64 (schema)Schema/Tool definition for get_positions. Defines the tool name, description, and input schema (no arguments required).
Tool( name="get_positions", description="List all open positions with unrealized PnL, leverage, and liquidation price", inputSchema={"type": "object", "properties": {}, "required": []}, ), - src/hyperliquid_mcp/server.py:143-144 (registration)Tool dispatch registration in the match/case statement. Routes 'get_positions' tool calls to the client handler.
case "get_positions": return client.get_positions()