cancel_order
Cancel specific trading orders on Bybit by specifying the category, symbol, and optional order ID or link ID. Simplify order management and ensure accurate execution of trading strategies.
Instructions
Cancel order
Args:
category (str): Category (spot, linear, inverse, etc.)
symbol (str): Symbol (e.g., BTCUSDT)
orderId (Optional[str]): Order ID
orderLinkId (Optional[str]): Order link ID
orderFilter (Optional[str]): Order filter
Returns:
Dict: Cancel result
Example:
cancel_order("spot", "BTCUSDT", "123456789")
Reference:
https://bybit-exchange.github.io/docs/v5/order/cancel-order
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | Yes | Category (spot, linear, inverse, etc.) | |
| orderFilter | No | Order filter | |
| orderId | No | Order ID | |
| orderLinkId | No | Order link ID | |
| symbol | Yes | Symbol (e.g., BTCUSDT) |
Implementation Reference
- src/server.py:355-390 (handler)MCP tool handler for 'cancel_order': decorated with @mcp.tool(), defines input schema via Pydantic Fields, executes logic by calling BybitService.cancel_order(), handles errors and logging.@mcp.tool() def cancel_order( category: str = Field(description="Category (spot, linear, inverse, etc.)"), symbol: str = Field(description="Symbol (e.g., BTCUSDT)"), orderId: Optional[str] = Field(default=None, description="Order ID"), orderLinkId: Optional[str] = Field(default=None, description="Order link ID"), orderFilter: Optional[str] = Field(default=None, description="Order filter") ) -> Dict: """ Cancel order Args: category (str): Category (spot, linear, inverse, etc.) symbol (str): Symbol (e.g., BTCUSDT) orderId (Optional[str]): Order ID orderLinkId (Optional[str]): Order link ID orderFilter (Optional[str]): Order filter Returns: Dict: Cancel result Example: cancel_order("spot", "BTCUSDT", "123456789") Reference: https://bybit-exchange.github.io/docs/v5/order/cancel-order """ try: result = bybit_service.cancel_order(category, symbol, orderId, orderLinkId, orderFilter) if result.get("retCode") != 0: logger.error(f"Failed to cancel order: {result.get('retMsg')}") return {"error": result.get("retMsg")} return result except Exception as e: logger.error(f"Failed to cancel order: {e}", exc_info=True) return {"error": str(e)}
- src/service.py:322-343 (helper)BybitService helper method wrapping the pybit.unified_trading.HTTP client's cancel_order API call.def cancel_order(self, category: str, symbol: str, orderId: Optional[str] = None, orderLinkId: Optional[str] = None, orderFilter: Optional[str] = None) -> Dict: """ Cancel order Args: category (str): Category (spot, linear, inverse, etc.) symbol (str): Symbol (e.g., BTCUSDT) orderId (Optional[str]): Order ID orderLinkId (Optional[str]): Order link ID orderFilter (Optional[str]): Order filter Returns: Dict: Cancel result """ return self.client.cancel_order( category=category, symbol=symbol, orderId=orderId, orderLinkId=orderLinkId, orderFilter=orderFilter )