Skip to main content
Glama

create_order

Place limit or market orders on supported cryptocurrency exchanges like MEXC, Gate.io, Bitget, and Kraken for trading pairs such as BTC/USDT.

Instructions

Create a new order (limit or market) on a supported exchange

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
exchangeYesExchange to query. Supported: mexc, gateio, bitget, kraken
symbolYesTrading pair symbol (e.g., BTC/USDT, INDY/USDT)
typeYesOrder type: limit or market
sideYesOrder side: buy or sell
amountYesOrder amount in base currency
priceNoOrder price (required for limit orders, ignored for market orders)

Implementation Reference

  • The main handler function that executes the create_order tool logic. It validates inputs, gets the exchange connector, calls connector.createOrder(), and returns the order result as JSON.
    async ({ exchange, symbol, type, side, amount, price }) => {
      const validExchange = validateExchange(exchange);
      const validSymbol = validateSymbol(symbol);
    
      if (type === 'limit' && price === undefined) {
        throw new Error('Price is required for limit orders');
      }
    
      const connector = await getConnectorSafe(exchange);
      const order = await connector.createOrder(validSymbol, type, side, amount, price);
    
      return {
        content: [
          {
            type: 'text' as const,
            text: JSON.stringify(
              {
                order,
                exchange: validExchange,
              },
              null,
              2
            ),
          },
        ],
      };
    }
  • The input validation schema for create_order using zod. Defines exchange, symbol, type (limit/market), side (buy/sell), amount, and optional price parameters.
    {
      exchange: ExchangeParam,
      symbol: SymbolParam,
      type: z.enum(['limit', 'market']).describe('Order type: limit or market'),
      side: z.enum(['buy', 'sell']).describe('Order side: buy or sell'),
      amount: z.number().positive().describe('Order amount in base currency'),
      price: z
        .number()
        .positive()
        .optional()
        .describe('Order price (required for limit orders, ignored for market orders)'),
    },
  • The tool registration call using server.tool() that registers create_order with the MCP server, including the tool name, description, schema, and handler function.
    server.tool(
      'create_order',
      'Create a new order (limit or market) on a supported exchange',
      {
        exchange: ExchangeParam,
        symbol: SymbolParam,
        type: z.enum(['limit', 'market']).describe('Order type: limit or market'),
        side: z.enum(['buy', 'sell']).describe('Order side: buy or sell'),
        amount: z.number().positive().describe('Order amount in base currency'),
        price: z
          .number()
          .positive()
          .optional()
          .describe('Order price (required for limit orders, ignored for market orders)'),
      },
      async ({ exchange, symbol, type, side, amount, price }) => {
        const validExchange = validateExchange(exchange);
        const validSymbol = validateSymbol(symbol);
    
        if (type === 'limit' && price === undefined) {
          throw new Error('Price is required for limit orders');
        }
    
        const connector = await getConnectorSafe(exchange);
        const order = await connector.createOrder(validSymbol, type, side, amount, price);
    
        return {
          content: [
            {
              type: 'text' as const,
              text: JSON.stringify(
                {
                  order,
                  exchange: validExchange,
                },
                null,
                2
              ),
            },
          ],
        };
      }
    );
  • Helper schemas used by create_order: ExchangeParam (validates exchange name) and SymbolParam (validates trading pair symbol format).
    export const ExchangeParam = z
      .string()
      .describe('Exchange to query. Supported: mexc, gateio, bitget, kraken');
    
    export const SymbolParam = z.string().describe('Trading pair symbol (e.g., BTC/USDT, INDY/USDT)');
  • The validateSymbol helper function used in the create_order handler to validate and normalize the trading pair symbol (converts to uppercase, checks format).
    export function validateSymbol(symbol: string): string {
      if (!symbol) {
        throw new Error('Symbol is required');
      }
      const upper = symbol.toUpperCase();
      if (!/^[A-Z]+\/[A-Z]+$/.test(upper) && !/^[A-Z]+[A-Z]+$/.test(upper)) {
        throw new Error(`Invalid symbol format: ${symbol}. Expected: BTC/USDT or BTCUSDT`);
      }
      return upper;
    }

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/QBT-Labs/openmm-mcp'

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