Skip to main content
Glama

cancel_order

Cancel an open Alpaca order by providing its order ID to manage trading positions and adjust strategies.

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

  • The primary handler function for the 'cancel_order' MCP tool. It takes an order_id, uses the Alpaca broker to cancel the order, and returns a success or error 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)}"
  • server.py:375-378 (registration)
    Registers the cancel_order function (imported from tools.execution) as an MCP tool using FastMCP's mcp.tool() decorator via the register_tools helper.
    register_tools( [place_order, cancel_order, get_positions, flatten, get_order_history], "Execution" )
  • Supporting method in the AlpacaBroker class that performs the actual API call to cancel an order by ID. Called by the execution handler.
    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

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