Skip to main content
Glama

trade_execute

Execute market or limit orders for perpetual futures trading on supported exchanges after user confirmation.

Instructions

Execute a trade. IMPORTANT: Always call trade_preview first and get explicit user confirmation before calling this tool. Supports market and limit orders.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
exchangeYesExchange: pacifica, hyperliquid, or lighter
symbolYesTrading symbol (e.g., BTC, ETH, SOL)
sideYesOrder side
sizeYesOrder size (base currency units)
orderTypeNoOrder typemarket
priceNoLimit price (required for limit orders)
reduceOnlyNoReduce-only order (close position only)

Implementation Reference

  • The trade_execute tool implementation in the MCP server, which interacts with exchange adapters to place market or limit orders.
      "trade_execute",
      "Execute a trade. IMPORTANT: Always call trade_preview first and get explicit user confirmation before calling this tool. Supports market and limit orders.",
      {
        exchange: z.string().describe("Exchange: pacifica, hyperliquid, or lighter"),
        symbol: z.string().describe("Trading symbol (e.g., BTC, ETH, SOL)"),
        side: z.enum(["buy", "sell"]).describe("Order side"),
        size: z.string().describe("Order size (base currency units)"),
        orderType: z.enum(["market", "limit"]).default("market").describe("Order type"),
        price: z.string().optional().describe("Limit price (required for limit orders)"),
        reduceOnly: z.boolean().default(false).describe("Reduce-only order (close position only)"),
      },
      async ({ exchange, symbol, side, size, orderType, price, reduceOnly }) => {
        try {
          const adapter = await getOrCreateAdapter(exchange);
          let result: unknown;
    
          if (orderType === "limit") {
            if (!price) throw new Error("Price is required for limit orders");
            result = await adapter.limitOrder(symbol, side, price, size, { reduceOnly });
          } else {
            result = await adapter.marketOrder(symbol, side, size);
          }
    
          // Fetch updated position
          const positions = await adapter.getPositions();
          const pos = positions.find(p => p.symbol.toUpperCase().includes(symbol.toUpperCase()));
    
          return {
            content: [{
              type: "text",
              text: ok({
                executed: true,
                order: { exchange, symbol, side, size, orderType, price },
                result,
                currentPosition: pos ?? null,
              }, { exchange, type: "execution" }),
            }],
          };
        } catch (e) {
          return { content: [{ type: "text", text: err(e instanceof Error ? e.message : String(e)) }], isError: true };
        }
      },
    );

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