Skip to main content
Glama

cancel_order

Cancel open trading orders on the Alpaca platform using order ID. This MonteWalk MCP server tool helps manage active positions by removing pending trades.

Instructions

Cancels a specific open order.

Args:
    order_id: The Alpaca order ID to cancel
    
Returns:
    Confirmation message

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
order_idYes

Implementation Reference

  • Main MCP tool handler: cancels order via broker and returns user-friendly status message.
    def cancel_order(order_id: str) -> str:
        """
        Cancels a specific open order.
        
        Args:
            order_id: The Alpaca order ID to cancel
            
        Returns:
            Confirmation message
        """
        if broker is None:
            return "ERROR: Alpaca broker not initialized."
        
        try:
            logger.info(f"Cancelling order: {order_id}")
            broker.cancel_order(order_id)
            logger.info(f"Order {order_id} cancelled successfully")
            return f"✅ Order {order_id} cancelled successfully"
        except Exception as e:
            logger.error(f"Cancel order failed: {e}", exc_info=True)
            return f"ERROR: Failed to cancel order - {str(e)}"
  • Broker class method that performs the actual API call to cancel_order_by_id on Alpaca TradingClient.
    def cancel_order(self, order_id: str) -> bool:
        """
        Cancel a pending order.
        
        Args:
            order_id: Order ID to cancel
            
        Returns:
            True if successful
        """
        try:
            self.trading_client.cancel_order_by_id(order_id)
            logger.info(f"Order {order_id} cancelled")
            return True
        except Exception as e:
            logger.error(f"Failed to cancel order {order_id}: {e}")
            raise
  • server.py:375-378 (registration)
    Registration of cancel_order (and related execution tools) as MCP tools via register_tools helper.
    register_tools(
        [place_order, cancel_order, get_positions, flatten, get_order_history],
        "Execution"
    )
  • app.py:288-288 (registration)
    Tool grouping/listing in Gradio app's tools_map for UI toolbox (MCP server also enabled).
    "Execution": [place_order, cancel_order, get_positions, flatten, get_order_history],

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/N-lia/MonteWalk'

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