place_order
Execute trades by submitting buy or sell orders with customizable parameters like order type, quantity, and pricing for financial instruments.
Instructions
Place a new order.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| contract_type | Yes | ||
| symbol | Yes | ||
| exchange | No | SMART | |
| currency | No | USD | |
| action | Yes | BUY or SELL | |
| quantity | Yes | Order quantity | |
| order_type | Yes | Order type: market, limit, stop, stop_limit | |
| limit_price | No | Limit price (for limit orders) | |
| stop_price | No | Stop price (for stop orders) |
Implementation Reference
- src/ib_async_mcp/server.py:622-652 (handler)The handler for the 'place_order' tool, which constructs the appropriate order type (Market, Limit, etc.) and uses the ib_async library to place the order.
if name == "place_order": contract = create_contract( args["contract_type"], symbol=args["symbol"], exchange=args.get("exchange", "SMART"), currency=args.get("currency", "USD"), ) await ib.qualifyContractsAsync(contract) order_type = args["order_type"].lower() action = args["action"].upper() quantity = args["quantity"] if order_type == "market": order = MarketOrder(action, quantity) elif order_type == "limit": order = LimitOrder(action, quantity, args["limit_price"]) elif order_type == "stop": order = StopOrder(action, quantity, args["stop_price"]) elif order_type == "stop_limit": order = StopLimitOrder(action, quantity, args["limit_price"], args["stop_price"]) else: raise ValueError(f"Unknown order type: {order_type}") trade = ib.placeOrder(contract, order) return { "order_id": trade.order.orderId, "status": trade.orderStatus.status, "filled": trade.orderStatus.filled, "remaining": trade.orderStatus.remaining, } - src/ib_async_mcp/server.py:253-271 (schema)The schema registration for the 'place_order' tool, defining the required input fields and their types.
Tool( name="place_order", description="Place a new order.", inputSchema={ "type": "object", "properties": { "contract_type": {"type": "string"}, "symbol": {"type": "string"}, "exchange": {"type": "string", "default": "SMART"}, "currency": {"type": "string", "default": "USD"}, "action": {"type": "string", "description": "BUY or SELL"}, "quantity": {"type": "number", "description": "Order quantity"}, "order_type": {"type": "string", "description": "Order type: market, limit, stop, stop_limit"}, "limit_price": {"type": "number", "description": "Limit price (for limit orders)"}, "stop_price": {"type": "number", "description": "Stop price (for stop orders)"}, }, "required": ["contract_type", "symbol", "action", "quantity", "order_type"], }, ),