Skip to main content
Glama
henrysouchien

Interactive Brokers MCP Server

get_ibkr_account

Fetch Interactive Brokers account summary metrics including balances, positions, and performance data to monitor trading portfolios.

Instructions

Fetch IBKR account summary metrics.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
account_idNo

Implementation Reference

  • MCP tool handler for get_ibkr_account - registered with @mcp.tool() decorator, wraps IBKRClient.get_account_summary() call with error handling
    @mcp.tool()
    def get_ibkr_account(account_id: Optional[str] = None) -> dict:
        """Fetch IBKR account summary metrics."""
    
        def _impl() -> dict:
            from .client import IBKRClient
    
            client = IBKRClient()
            summary = client.get_account_summary(account_id=account_id)
            return {"status": "success", "account_summary": summary}
    
        try:
            return _with_stderr_stdout(_impl)
        except Exception as exc:
            return {"status": "error", "error": str(exc)}
  • IBKRClient.get_account_summary - manages connection, resolves account_id with authorization checks, delegates to fetch_account_summary helper
    def get_account_summary(self, account_id: str | None = None) -> dict[str, float]:
        with ibkr_shared_lock:
            ib = self._get_account_ib()
            resolved_account = self._resolve_account_id(ib, account_id)
            return fetch_account_summary(ib, account_id=resolved_account)
  • fetch_account_summary - fetches account values from IBKR API, normalizes tags to snake_case, filters to USD currency only
    def fetch_account_summary(ib, account_id: str | None = None) -> dict[str, float]:
        """Fetch account summary values with USD-only tag normalization."""
        account_values = list(ib.accountValues(account=account_id) or [])
        if not account_values:
            ib.reqAccountUpdates(account=account_id)
            account_values = list(ib.accountValues(account=account_id) or [])
    
        summary: dict[str, float] = {}
        for av in account_values:
            if account_id and getattr(av, "account", None) not in (None, "", account_id):
                continue
            if getattr(av, "currency", None) != "USD":
                continue
            key = _SUMMARY_TAGS.get(getattr(av, "tag", None))
            if key is None:
                continue
            val = _safe_float(getattr(av, "value", None))
            if val is None:
                continue
            summary[key] = val
    
        return summary
  • Schema definition mapping IBKR account summary tags to normalized field names (snake_case) for USD values
    _SUMMARY_TAGS = {
        "NetLiquidation": "net_liquidation",
        "TotalCashValue": "total_cash_value",
        "BuyingPower": "buying_power",
        "GrossPositionValue": "gross_position_value",
        "MaintMarginReq": "maint_margin_req",
        "AvailableFunds": "available_funds",
        "ExcessLiquidity": "excess_liquidity",
        "SMA": "sma",
    }

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/henrysouchien/ibkr-mcp'

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