Skip to main content
Glama

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
NameRequiredDescriptionDefault
categoryYesCategory (spot, linear, inverse, etc.)
orderFilterNoOrder filter
orderIdNoOrder ID
orderLinkIdNoOrder link ID
symbolYesSymbol (e.g., BTCUSDT)

Implementation Reference

  • 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)}
  • 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 )

Other Tools

Related 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/dlwjdtn535/mcp-bybit-server'

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