Skip to main content
Glama
nadavgb-atom

ib-async-mcp

by nadavgb-atom

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
NameRequiredDescriptionDefault
contract_typeYes
symbolYes
exchangeNoSMART
currencyNoUSD
actionYesBUY or SELL
quantityYesOrder quantity
order_typeYesOrder type: market, limit, stop, stop_limit
limit_priceNoLimit price (for limit orders)
stop_priceNoStop price (for stop orders)

Implementation Reference

  • 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,
        }
  • 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"],
        },
    ),

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/nadavgb-atom/ib-async-mcp'

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