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
| Name | Required | Description | Default |
|---|---|---|---|
| order_id | Yes |
Implementation Reference
- tools/execution.py:140-160 (handler)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)}"
- tools/alpaca_broker.py:259-275 (helper)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],