Skip to main content
Glama
nadavgb-atom

ib-async-mcp

by nadavgb-atom

get_historical_data

Retrieve historical market data for financial instruments by specifying contract details, time periods, and bar sizes to analyze past performance.

Instructions

Get historical bar data.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contract_typeYes
symbolYes
exchangeNoSMART
currencyNoUSD
durationNoDuration (e.g., '1 D', '1 W', '1 M', '1 Y')1 D
bar_sizeNoBar size (e.g., '1 min', '5 mins', '1 hour', '1 day')1 hour
what_to_showNoData type: TRADES, MIDPOINT, BID, ASKTRADES
use_rthNoRegular trading hours only

Implementation Reference

  • The handler implementation for the "get_historical_data" tool, which creates a contract, qualifies it, and requests historical bar data from the IB gateway.
    if name == "get_historical_data":
        contract = create_contract(
            args["contract_type"],
            symbol=args["symbol"],
            exchange=args.get("exchange", "SMART"),
            currency=args.get("currency", "USD"),
        )
        await ib.qualifyContractsAsync(contract)
        bars = await ib.reqHistoricalDataAsync(
            contract,
            endDateTime="",
            durationStr=args.get("duration", "1 D"),
            barSizeSetting=args.get("bar_size", "1 hour"),
            whatToShow=args.get("what_to_show", "TRADES"),
            useRTH=args.get("use_rth", True),
        )
        return [{
            "date": b.date.isoformat() if hasattr(b.date, 'isoformat') else str(b.date),
            "open": b.open,
            "high": b.high,
            "low": b.low,
            "close": b.close,
            "volume": b.volume,
        } for b in bars]
  • Registration of the "get_historical_data" tool in the list_tools() function.
        name="get_historical_data",
        description="Get historical bar data.",
        inputSchema={
            "type": "object",
            "properties": {
                "contract_type": {"type": "string"},
                "symbol": {"type": "string"},
                "exchange": {"type": "string", "default": "SMART"},
                "currency": {"type": "string", "default": "USD"},
                "duration": {"type": "string", "default": "1 D", "description": "Duration (e.g., '1 D', '1 W', '1 M', '1 Y')"},
                "bar_size": {"type": "string", "default": "1 hour", "description": "Bar size (e.g., '1 min', '5 mins', '1 hour', '1 day')"},
                "what_to_show": {"type": "string", "default": "TRADES", "description": "Data type: TRADES, MIDPOINT, BID, ASK"},
                "use_rth": {"type": "boolean", "default": True, "description": "Regular trading hours only"},
            },
            "required": ["contract_type", "symbol"],
        },
    ),

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