Skip to main content
Glama

cancel_all_orders

Cancel all open orders for a trading pair on supported cryptocurrency exchanges to manage positions and reduce risk.

Instructions

Cancel all open orders for a trading pair 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)

Implementation Reference

  • Main handler implementation for 'cancel_all_orders' tool. Registers the tool with MCP server, validates exchange and symbol parameters, and calls connector.cancelAllOrders() to cancel all open orders for a trading pair.
    server.tool(
      'cancel_all_orders',
      'Cancel all open orders for a trading pair on a supported exchange',
      {
        exchange: ExchangeParam,
        symbol: SymbolParam,
      },
      async ({ exchange, symbol }) => {
        const validExchange = validateExchange(exchange);
        const validSymbol = validateSymbol(symbol);
    
        const connector = await getConnectorSafe(exchange);
        const result = await connector.cancelAllOrders(validSymbol);
    
        return {
          content: [
            {
              type: 'text' as const,
              text: JSON.stringify(
                {
                  cancelled: result,
                  symbol: validSymbol,
                  exchange: validExchange,
                },
                null,
                2
              ),
            },
          ],
        };
      }
    );
  • Schema definitions for ExchangeParam and SymbolParam used by the cancel_all_orders tool. ExchangeParam validates exchange (mexc, gateio, bitget, kraken) and SymbolParam validates trading pair symbols like BTC/USDT.
    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)');
  • Helper function validateSymbol() that normalizes and validates trading pair symbols, converting to uppercase and ensuring correct format (e.g., BTC/USDT).
    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;
    }
  • Related 'stop_strategy' tool that also calls connector.cancelAllOrders() to stop a running grid strategy by cancelling all open orders for a trading pair.
    server.tool(
      'stop_strategy',
      'Cancel all open orders for a trading pair, effectively stopping any running grid strategy',
      {
        exchange: ExchangeParam,
        symbol: SymbolParam,
      },
      async ({ exchange, symbol }) => {
        const validExchange = validateExchange(exchange);
        const validSymbol = validateSymbol(symbol);
    
        const connector = await getConnectorSafe(exchange);
        const openOrders = await connector.getOpenOrders(validSymbol);
        const result = await connector.cancelAllOrders(validSymbol);
    
        return {
          content: [
            {
              type: 'text' as const,
              text: JSON.stringify(
                {
                  status: 'stopped',
                  cancelledOrders: openOrders.length,
                  result,
                  exchange: validExchange,
                  symbol: validSymbol,
                  timestamp: new Date().toISOString(),
                },
                null,
                2
              ),
            },
          ],
        };
      }
    );
  • Helper function getConnectorSafe() that validates exchange and returns a BaseExchangeConnector instance which provides the cancelAllOrders() method used by the tool.
    export async function getConnectorSafe(exchange: string): Promise<BaseExchangeConnector> {
      const validExchange = validateExchange(exchange);
      const { ExchangeFactory } = await import('@3rd-eye-labs/openmm');
      try {
        return await ExchangeFactory.getExchange(validExchange as any);
      } catch (error) {
        const message = error instanceof Error ? error.message : String(error);
        throw new Error(`Failed to connect to ${validExchange}: ${message}`);
      }
    }

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