Skip to main content
Glama

cancel_order

Cancel a specific trading order by ID on supported cryptocurrency exchanges to manage active positions and adjust trading strategies.

Instructions

Cancel a specific order by ID 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)
orderIdYesThe order ID to cancel

Implementation Reference

  • Complete registration and handler implementation for cancel_order tool. Defines parameters (exchange, symbol, orderId), validates inputs, gets the exchange connector, calls connector.cancelOrder(), and returns the cancellation result.
    server.tool(
      'cancel_order',
      'Cancel a specific order by ID on a supported exchange',
      {
        exchange: ExchangeParam,
        symbol: SymbolParam,
        orderId: z.string().describe('The order ID to cancel'),
      },
      async ({ exchange, symbol, orderId }) => {
        const validExchange = validateExchange(exchange);
        const validSymbol = validateSymbol(symbol);
    
        const connector = await getConnectorSafe(exchange);
        const result = await connector.cancelOrder(orderId, validSymbol);
    
        return {
          content: [
            {
              type: 'text' as const,
              text: JSON.stringify(
                {
                  cancelled: result,
                  orderId,
                  symbol: validSymbol,
                  exchange: validExchange,
                },
                null,
                2
              ),
            },
          ],
        };
      }
    );
  • Schema definitions for ExchangeParam and SymbolParam used by cancel_order tool parameters. ExchangeParam validates supported exchanges (mexc, gateio, bitget, kraken), SymbolParam validates trading pair symbols.
    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 functions validateExchange() and getConnectorSafe() used by cancel_order handler. Validates exchange is supported and creates the connector instance that implements cancelOrder().
    export function validateExchange(exchange: string): SupportedExchange {
      const lower = exchange.toLowerCase();
      if (!(SUPPORTED_EXCHANGES as readonly string[]).includes(lower)) {
        throw new Error(
          `Unsupported exchange: ${exchange}. Supported: ${SUPPORTED_EXCHANGES.join(', ')}`
        );
      }
      return lower as SupportedExchange;
    }
    
    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}`);
      }
    }
  • Registration of trading tools (including cancel_order) with the MCP server. Imports registerTradingTools and calls it to register all trading-related tools.
    import { registerTradingTools } from './trading.js';
    import { registerCardanoTools } from './cardano.js';
    import { registerStrategyTools } from './strategy.js';
    
    export function registerTools(server: McpServer): void {
      registerMarketDataTools(server);
      registerAccountTools(server);
      registerTradingTools(server);
  • src/worker.ts:18-46 (registration)
    MCP server card definition that lists cancel_order in the tools capabilities section (line 34). This declares the tool's availability in the server's public API metadata.
    if (url.pathname === '/.well-known/mcp/server-card.json' && request.method === 'GET') {
      const card = {
        name: 'openmm-mcp-agent',
        version: '1.0.4',
        description:
          'MCP server for OpenMM — exposes market data, account, trading, and strategy tools to AI agents',
        url: 'https://openmm-mcp.qbtlabs.io/mcp',
        transport: { type: 'streamable-http' },
        capabilities: {
          tools: [
            { name: 'get_ticker' },
            { name: 'get_orderbook' },
            { name: 'get_trades' },
            { name: 'get_balance' },
            { name: 'list_orders' },
            { name: 'create_order' },
            { name: 'cancel_order' },
            { name: 'cancel_all_orders' },
            { name: 'start_grid_strategy' },
            { name: 'stop_strategy' },
            { name: 'get_strategy_status' },
            { name: 'get_cardano_price' },
            { name: 'discover_pools' },
          ],
        },
      };
      return new Response(JSON.stringify(card), {
        headers: { 'Content-Type': 'application/json' },
      });

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