cancel_order
Cancel active trading orders on Bybit's platform to manage positions or adjust strategies. Specify product category and symbol to remove pending orders from the exchange.
Instructions
Cancel an existing order (⚠️ WARNING: Affects real orders on mainnet)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | Yes | ||
| symbol | Yes | ||
| orderId | No | ||
| orderLinkId | No |
Implementation Reference
- src/server.ts:120-127 (handler)Dispatch handler in handleToolCall method for the 'cancel_order' tool, invoking the BybitClient.cancelOrder method with tool arguments.case 'cancel_order': result = await this.client.cancelOrder( args.category as string, args.symbol as string, args.orderId as string, args.orderLinkId as string ); break;
- src/client.ts:152-168 (handler)Core implementation of the cancel_order tool logic in BybitClient, performing the actual Bybit API call to cancel the order and handling mainnet warnings.async cancelOrder(category: string, symbol: string, orderId?: string, orderLinkId?: string) { try { if (this.config.environment === 'mainnet') { console.error('⚠️ WARNING: Canceling order on MAINNET!'); } const response = await this.client.cancelOrder({ category: category as any, symbol: symbol, orderId: orderId, orderLinkId: orderLinkId }); return response; } catch (error) { throw new Error(`Failed to cancel order: ${error instanceof Error ? error.message : JSON.stringify(error)}`); } }
- src/tools.ts:96-104 (registration)Tool registration entry for 'cancel_order' used in listTools response, defining name, description, and input schema.{ name: 'cancel_order', description: 'Cancel an existing order (⚠️ WARNING: Affects real orders on mainnet)', inputSchema: { type: 'object', properties: CancelOrderSchema.shape, required: ['category', 'symbol'] } },
- src/types.ts:55-60 (schema)Zod schema defining the input parameters for the cancel_order tool.export const CancelOrderSchema = z.object({ category: z.enum(['spot', 'linear', 'inverse', 'option']).describe('Product type'), symbol: z.string().describe('Trading symbol'), orderId: z.string().optional().describe('Order ID'), orderLinkId: z.string().optional().describe('Order link ID') });