cancelOrder
Cancel an existing cryptocurrency trading order on supported exchanges using account credentials, order ID, and trading symbol.
Instructions
Cancel an existing order using a configured account
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accountName | Yes | Account name defined in the configuration file (e.g., 'bybit_main') | |
| id | Yes | Order ID to cancel | |
| symbol | Yes | Trading symbol (e.g., 'BTC/USDT') | |
| params | No | Additional exchange-specific parameters |
Implementation Reference
- src/tools/order-tools.ts:118-147 (handler)The core handler function that executes the cancelOrder tool. Retrieves the CCXT exchange instance for the given accountName and invokes exchange.cancelOrder(id, symbol, params). Handles errors and returns formatted content.
async ({ accountName, id, symbol, params }) => { try { const exchange = ccxtServer.getExchangeInstance(accountName); // getExchangeInstance가 성공하면 인증은 보장됨 const result = await exchange.cancelOrder(id, symbol, params); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error canceling order for account '${accountName}': ${ (error as Error).message }`, }, ], isError: true, }; } }, - src/tools/order-tools.ts:105-117 (schema)Zod input schema defining parameters for the cancelOrder tool: accountName (string), id (string), symbol (string), optional params (record).
{ accountName: z .string() .describe( "Account name defined in the configuration file (e.g., 'bybit_main')" ), id: z.string().describe("Order ID to cancel"), symbol: z.string().describe("Trading symbol (e.g., 'BTC/USDT')"), params: z .record(z.any()) .optional() .describe("Additional exchange-specific parameters"), }, - src/tools/order-tools.ts:102-148 (registration)Direct registration of the 'cancelOrder' tool on the MCP server via server.tool(), including name, description, input schema, and handler function.
server.tool( "cancelOrder", "Cancel an existing order using a configured account", { accountName: z .string() .describe( "Account name defined in the configuration file (e.g., 'bybit_main')" ), id: z.string().describe("Order ID to cancel"), symbol: z.string().describe("Trading symbol (e.g., 'BTC/USDT')"), params: z .record(z.any()) .optional() .describe("Additional exchange-specific parameters"), }, async ({ accountName, id, symbol, params }) => { try { const exchange = ccxtServer.getExchangeInstance(accountName); // getExchangeInstance가 성공하면 인증은 보장됨 const result = await exchange.cancelOrder(id, symbol, params); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error canceling order for account '${accountName}': ${ (error as Error).message }`, }, ], isError: true, }; } }, ); - src/server.ts:373-373 (registration)Invocation of registerOrderTools(server, ccxtServer) in CcxtMcpServer.registerTools(), which registers the cancelOrder tool among other order tools.
registerOrderTools(this.server, this); - src/server.ts:291-303 (helper)Helper method used by the cancelOrder handler to retrieve the pre-authenticated CCXT Exchange instance for the specified accountName from loaded configuration.
getExchangeInstance(accountName: string): Exchange { const instance = this.exchangeInstances[accountName]; if (!instance) { console.error( `No pre-loaded exchange instance found for account name: ${accountName}`, ); // Consider listing available account names: Object.keys(this.exchangeInstances).join(', ') throw new Error( `Account configuration not found or failed to load for: ${accountName}`, ); } return instance; }