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
        )
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. While 'Cancel order' implies a destructive write operation, the description doesn't mention authentication requirements, rate limits, side effects, error conditions, or what 'Cancel result' contains. The example shows basic usage but doesn't explain behavioral implications.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is reasonably structured with sections for Args, Returns, Example, and Reference. However, the core description 'Cancel order' is overly terse and could benefit from more context. The example and reference sections add value but the main description feels underdeveloped.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a destructive financial operation with 5 parameters and no annotations or output schema, the description is inadequate. It doesn't explain what cancellation means in this trading context, what happens to partially filled orders, authentication requirements, error conditions, or what the return value contains. The reference link helps but doesn't compensate for missing behavioral context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters. The description repeats parameter information in the Args section but adds minimal value beyond what's in the schema. The example shows usage but doesn't explain parameter interactions or which identifiers (orderId vs orderLinkId) should be used when.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states the tool's purpose as 'Cancel order', which is a clear verb+resource combination. However, it doesn't differentiate from potential alternatives or provide any context about what types of orders can be canceled or what cancellation entails. It's a basic statement of function without elaboration.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided about when to use this tool versus alternatives. While sibling tools include 'place_order' and 'get_open_orders', the description doesn't mention relationships between these tools or prerequisites for cancellation. There's no mention of when cancellation is possible or what happens to partially filled orders.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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