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' },
      });
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action ('cancel') which implies a destructive mutation, but doesn't disclose critical traits like whether cancellation is reversible, what permissions or authentication are required, potential rate limits, error conditions (e.g., if order doesn't exist), or what happens upon success (e.g., order status change). This leaves significant gaps for a mutation tool.

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?

The description is a single, efficient sentence that front-loads the core action ('cancel a specific order') and includes essential context ('by ID on a supported exchange'). There is no wasted verbiage, repetition, or unnecessary details, making it highly concise and well-structured for quick understanding.

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

Completeness2/5

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

Given the tool's complexity (a destructive mutation with 3 parameters) and the lack of annotations and output schema, the description is incomplete. It doesn't cover behavioral aspects like side effects, error handling, or return values, which are crucial for safe and effective use. The description alone is insufficient for an agent to fully understand how to invoke and interpret results from this tool.

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?

The input schema has 100% description coverage, with all three parameters ('exchange', 'symbol', 'orderId') well-documented in the schema itself. The description adds no additional parameter semantics beyond what the schema provides (e.g., it doesn't clarify parameter relationships or usage examples). According to the rules, with high schema coverage (>80%), the baseline is 3 even without param info in the description.

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

Purpose4/5

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

The description clearly states the action ('cancel') and resource ('a specific order by ID on a supported exchange'), making the purpose immediately understandable. It distinguishes from siblings like 'cancel_all_orders' by specifying 'specific order by ID', though it doesn't explicitly mention all alternatives like 'list_orders' for checking order status. The description avoids tautology by not just repeating the tool name.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing an existing order ID from 'list_orders' or 'create_order'), when not to use it (e.g., for non-cancelable orders), or how it differs from 'cancel_all_orders'. Usage is implied by the action but lacks explicit context for selection among sibling tools.

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

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