Skip to main content
Glama

trade_close

Close perpetual futures positions on supported DEXs by executing trades to exit existing market exposure after confirming impact preview.

Instructions

Close an existing position. IMPORTANT: Call trade_preview first with the opposite side to show impact, then get user confirmation.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
exchangeYesExchange: pacifica, hyperliquid, or lighter
symbolYesSymbol to close (e.g., BTC, ETH)

Implementation Reference

  • The `trade_close` MCP tool handler, which identifies the open position and executes a market order to close it.
      "trade_close",
      "Close an existing position. IMPORTANT: Call trade_preview first with the opposite side to show impact, then get user confirmation.",
      {
        exchange: z.string().describe("Exchange: pacifica, hyperliquid, or lighter"),
        symbol: z.string().describe("Symbol to close (e.g., BTC, ETH)"),
      },
      async ({ exchange, symbol }) => {
        try {
          const adapter = await getOrCreateAdapter(exchange);
          const positions = await adapter.getPositions();
          const pos = positions.find(p => p.symbol.toUpperCase().includes(symbol.toUpperCase()));
          if (!pos || Number(pos.size) === 0) {
            return { content: [{ type: "text", text: err(`No open position for ${symbol} on ${exchange}`) }], isError: true };
          }
    
          const closeSide = pos.side === "long" ? "sell" : "buy";
          const result = await adapter.marketOrder(symbol, closeSide, pos.size);
    
          return {
            content: [{
              type: "text",
              text: ok({
                closed: true,
                symbol,
                exchange,
                closedPosition: { side: pos.side, size: pos.size, entryPrice: pos.entryPrice, unrealizedPnl: pos.unrealizedPnl },
                result,
              }, { exchange, type: "close" }),
            }],
          };
        } catch (e) {
          return { content: [{ type: "text", text: err(e instanceof Error ? e.message : String(e)) }], isError: true };
        }
      },
    );
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It discloses critical behavioral traits: this is a destructive/mutative operation (closing positions), requires a preview step, and needs user confirmation. However, it doesn't mention potential side effects like fees, slippage, or error conditions.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences with zero waste. The first states the core action, the second provides crucial procedural context. Every word earns its place, and the IMPORTANT flag appropriately front-loads critical information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a destructive tool with no annotations and no output schema, the description provides strong procedural context (preview → confirmation) but lacks details about return values, error handling, or confirmation mechanics. Given the complexity, it's mostly complete but has minor gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters (exchange and symbol). The description adds no additional parameter semantics beyond what's in the schema, meeting the baseline for high coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Close') and resource ('an existing position'), making the purpose specific and actionable. It distinguishes from siblings like trade_execute (general execution) and trade_preview (preview only) by focusing on position closure.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly states when to use this tool: after calling trade_preview with the opposite side and getting user confirmation. It also implies when not to use it (e.g., for opening positions or without preview/confirmation), providing clear procedural guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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