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
| Name | Required | Description | Default |
|---|---|---|---|
| exchange | Yes | Exchange to query. Supported: mexc, gateio, bitget, kraken | |
| symbol | Yes | Trading pair symbol (e.g., BTC/USDT, INDY/USDT) |
Implementation Reference
- src/tools/trading.ts:86-117 (handler)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 ), }, ], }; } ); - src/utils/validators.ts:3-7 (schema)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)'); - src/utils/validators.ts:23-32 (helper)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; } - src/tools/strategy.ts:166-201 (handler)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}`); } }