Skip to main content
Glama

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
NameRequiredDescriptionDefault
exchangeYesExchange name: pacifica, hyperliquid, or lighter

Implementation Reference

  • 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),
          };
        });
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/hypurrquant/perp-cli'

If you have feedback or need assistance with the MCP directory API, please join our Discord server