get_positions
Retrieve all open perpetual futures positions on specified exchanges to view size, entry price, PnL, and leverage for portfolio management.
Instructions
Get all open positions on an exchange, including size, entry price, PnL, leverage
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| exchange | Yes | Exchange name: pacifica, hyperliquid, or lighter |
Implementation Reference
- src/exchanges/hyperliquid.ts:341-364 (handler)The getPositions implementation in HyperliquidAdapter, which fetches clearinghouse state and formats it into ExchangePosition objects.
async getPositions(): Promise<ExchangePosition[]> { const state = await this._getClearinghouseState(); const positions = ((state as Record<string, unknown>)?.assetPositions ?? []) as Record<string, unknown>[]; return positions .filter((p: Record<string, unknown>) => { const pos = (p.position ?? p) as Record<string, unknown>; return Number(pos.szi ?? 0) !== 0; }) .map((p: Record<string, unknown>) => { const pos = (p.position ?? p) as Record<string, unknown>; const szi = Number(pos.szi ?? 0); return { symbol: String(pos.coin ?? ""), side: szi > 0 ? ("long" as const) : ("short" as const), size: String(Math.abs(szi)), entryPrice: String(pos.entryPx ?? "0"), markPrice: String(pos.positionValue ? Number(pos.positionValue) / Math.abs(szi) : "0"), liquidationPrice: String(pos.liquidationPx ?? "N/A"), unrealizedPnl: String(pos.unrealizedPnl ?? "0"), leverage: Number((pos.leverage as { value?: number })?.value ?? 1), }; }); }