what_if_order
Analyze margin requirements before executing trades to assess financial impact and manage risk effectively.
Instructions
Check margin impact without placing order.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| contract_type | Yes | ||
| symbol | Yes | ||
| exchange | No | SMART | |
| currency | No | USD | |
| action | Yes | ||
| quantity | Yes | ||
| order_type | No | market | |
| limit_price | No |
Implementation Reference
- src/ib_async_mcp/server.py:699-715 (handler)The implementation of the what_if_order tool logic. It processes the input arguments, creates a contract and order, and calls ib.whatIfOrderAsync to retrieve the result.
if name == "what_if_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.get("order_type", "market").lower() if order_type == "limit": order = LimitOrder(args["action"], args["quantity"], args["limit_price"]) else: order = MarketOrder(args["action"], args["quantity"]) state = await ib.whatIfOrderAsync(contract, order) return serialize_object(state) - src/ib_async_mcp/server.py:308-322 (schema)The registration of the what_if_order tool with its schema definition, defining input parameters like contract_type, symbol, action, and quantity.
Tool( name="what_if_order", description="Check margin impact without placing 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"}, "quantity": {"type": "number"}, "order_type": {"type": "string", "default": "market"}, "limit_price": {"type": "number"}, },