IB Analytics
Interactive Brokers portfolio analytics library with AI-powered investment analysis and development automation.
๐ฏ What This Does
For Investors (Mode 1 & 3):
โก 95% faster investment strategy generation (6-8 hours โ 15-20 minutes)
๐ Parallel market analysis of all holdings simultaneously
๐ฏ Consolidated multi-account view with accurate portfolio metrics
๐ Professional options strategies with specific strikes, Greeks, and Max Pain
๐ฐ Tax-optimized execution plans across multiple accounts
๐ Multi-timeframe technical analysis with entry/exit signals
For Developers (Mode 3):
๐ค 90% faster issue resolution (80 minutes โ 8 minutes via
/resolve-gh-issue)โ Automated quality gates (black, ruff, mypy, pytest)
๐ Complete TDD workflow (tests โ code โ PR automation)
๐ Auto-generated PR descriptions with comprehensive context
Time Savings Summary:
Task | Manual | Automated | Savings |
Investment Strategy | 6-8 hours | 15-20 min | 95% |
Stock Analysis | 1-2 hours | 2-3 min | 97% |
Options Strategy | 45-60 min | 3-5 min | 93% |
Portfolio Analysis | 3-4 hours | 5 min | 95% |
GitHub Issue โ PR | 80 min | 8 min | 90% |
โจ Key Features
Investment Analysis:
๐ Multi-Account Support: Consolidated analysis across all IB accounts
๐ Market Analysis: Multi-timeframe technicals, options Greeks, IV metrics, Max Pain
๐ฐ Tax Optimization: Cross-account tax harvesting and loss optimization
๐ฏ Options Strategies: Professional-grade recommendations with specific strikes
๐ Technical Analysis: Support/resistance, RSI, MACD, volume analysis
Portfolio Management:
๐ Flex Query API Integration: Automated data fetching via IB Flex Query API v3
๐ Comprehensive Analysis: Performance, tax, cost, risk, and bond analytics
๐ Position History: SQLite time-series tracking for historical analysis
๐ฏ Type-Safe: Built with Pydantic v2 for robust data validation
โก Async Support: Parallel data fetching for multiple accounts
๐ Rich Reports: Console, HTML, and optional PDF reporting
Development Automation (Mode 3):
๐ค 10 Specialized AI Agents: strategy-coordinator, market-analyst, data-analyzer, + 7 dev agents
๐ 15 Slash Commands: Automated workflows for analysis and development
โ Quality Gates: Automated black, ruff, mypy, pytest enforcement
๐ GitHub Integration: Issue โ Branch โ Tests โ Code โ PR workflow
Installation
Quick Start
1. Configuration
Create a .env file with your IB Flex Query credentials:
Note: To analyze multiple accounts, configure them in your IB Flex Query settings. A single query can return data for multiple accounts.
2. Fetch Data
3. Run Analysis
4. Generate Reports
Docker Usage
Quick Start with Docker
Docker Compose
Create .env file:
Run:
Docker Security Features
Non-root user: Runs as
mcpuser(UID 1000)Read-only filesystem: Root filesystem is read-only
Resource limits: CPU (2 cores) and memory (2GB) limits
No new privileges: Prevents privilege escalation
Data persistence: Data stored in mounted volume
Programmatic Usage
Project Structure
Available Analyzers
PerformanceAnalyzer: Overall trading performance metrics
TaxAnalyzer: Tax liability calculations (OID, capital gains)
CostAnalyzer: Commission and cost efficiency analysis
RiskAnalyzer: Interest rate and market risk scenarios
BondAnalyzer: Bond-specific analytics (YTM, duration, etc.)
Investment Analysis Tools (MCP)
IB Analytics provides advanced investment analysis tools through the MCP server. These tools integrate Yahoo Finance data for comprehensive market analysis.
Stock & Fund Analysis
get_stock_info - Comprehensive Stock Information
Get detailed information about stocks, ETFs, and funds including fundamental metrics.
Features:
Real-time price data (current, open, high, low, volume)
Valuation metrics (P/E, P/B, P/S, PEG, EV/EBITDA, EV/Revenue)
Profitability metrics (profit margin, ROE, ROA, operating margin, EPS)
Financial health (total cash, debt, debt-to-equity, current/quick ratios, FCF)
Growth metrics (revenue growth, earnings growth)
Dividend information (yield, ex-date, payment date)
Trading information (52-week high/low, market cap, volume)
Example Usage:
get_current_price - Quick Price Check
Get current price and key metrics for quick market checks.
Example Usage:
get_stock_data - Historical Price Data with Technical Indicators
Fetch OHLCV data with optional technical indicators (SMA, EMA, RSI, MACD, Bollinger Bands).
Example Usage:
Comparative Analysis
compare_with_benchmark - Performance vs Benchmark
Compare stock/fund performance against a benchmark (default: SPY).
Features:
Return comparison (total return, annualized return)
Volatility analysis (standard deviation comparison)
Risk metrics (beta, alpha, correlation)
Risk-adjusted returns (Sharpe ratio comparison)
Interpretation and insights
Example Usage:
get_analyst_consensus - Analyst Ratings & Target Prices
Get analyst recommendations, target prices, and earnings estimates.
Features:
Rating distribution (strong buy/buy/hold/sell/strong sell)
Consensus rating derived from distribution
Target prices (mean, median, high, low)
Upside potential percentage
Earnings estimates (date, EPS range, revenue estimates)
Example Usage:
Portfolio-Level Analysis
calculate_portfolio_metrics - Advanced Portfolio Metrics
Calculate comprehensive risk-adjusted performance metrics for your portfolio.
Features:
Return metrics: Total return, annualized return, volatility
Risk-adjusted ratios:
Sharpe Ratio: Risk-adjusted return (excess return / total risk)
Sortino Ratio: Downside risk-adjusted return
Calmar Ratio: Return / maximum drawdown
Treynor Ratio: Excess return / systematic risk (beta)
Information Ratio: Excess return / tracking error
Risk metrics:
Maximum drawdown (largest peak-to-trough decline)
Downside deviation (volatility of negative returns)
Beta (systematic risk vs benchmark)
Tracking error (deviation from benchmark)
Alpha (excess return vs expected return)
Parameters:
csv_path: Path to IB Flex Query CSV filebenchmark: Benchmark symbol (default: "SPY")risk_free_rate: Annual risk-free rate (default: 0.05 = 5%)period: Time period for analysis (1mo, 3mo, 6mo, 1y, 2y, 5y)
Example Usage:
Limitations:
โ ๏ธ Requires Yahoo Finance data for portfolio positions
โ ๏ธ Will not work for bond-only portfolios (STRIPS bonds have no Yahoo Finance data)
โ Works well for stock and ETF portfolios
analyze_portfolio_correlation - Diversification Analysis
Analyze correlation between portfolio positions to assess diversification.
Features:
Correlation matrix between all positions
High correlation pairs identification (|r| > 0.7)
Portfolio beta vs benchmark (default: SPY)
Diversification score (0-100)
Position weights in portfolio
Interpretation and recommendations
Parameters:
csv_path: Path to IB Flex Query CSV fileperiod: Time period for correlation analysis (1mo, 3mo, 6mo, 1y, 2y, 5y)
Example Usage:
Limitations:
โ ๏ธ Requires Yahoo Finance data for portfolio positions
โ ๏ธ Will not work for bond-only portfolios
โ Best for analyzing stock/ETF portfolio diversification
Options Analysis
get_options_chain - Options Data
Get calls and puts data for a stock including strike prices, volume, open interest, and implied volatility.
calculate_put_call_ratio - Market Sentiment
Calculate put/call ratio based on open interest or volume to gauge market sentiment.
Example Usage:
News & Market Intelligence
get_stock_news - Latest News Articles
Get the latest news articles for any stock symbol from Yahoo Finance.
Features:
Latest news articles (up to 50)
Article metadata (title, publisher, publish time, summary)
Direct links to full articles
Thumbnail images for visual context
Related ticker symbols
Multiple content types (stories, videos, press releases)
Parameters:
symbol: Stock ticker symbol (e.g., "AAPL", "TSLA", "QQQ")limit: Number of articles to return (default: 10, max: 50)
Example Usage:
Response Includes:
Title: Article headline
Publisher: News source (e.g., Yahoo Finance, Bloomberg, Reuters)
Link: Direct URL to full article
Publish Time: When the article was published (ISO 8601 format)
Summary: Brief article summary or description
Type: Content type (STORY, VIDEO, etc.)
Thumbnail: Image URL for articles with visuals
Related Tickers: Other stocks mentioned in the article
Use Cases:
Investment Research: Stay updated on company news and developments
Market Sentiment: Gauge market sentiment from news coverage
Due Diligence: Research companies before making investment decisions
Portfolio Monitoring: Track news for holdings in your portfolio
Event-Driven Trading: Identify market-moving events quickly
Example Natural Language Queries:
Market Sentiment Analysis
analyze_market_sentiment - Multi-Source Sentiment Analysis
Get comprehensive market sentiment from multiple sources: news articles, options market, and technical indicators.
Features:
News Sentiment: Sentiment analysis from recent news articles and headlines
Options Market Sentiment: Derived from Put/Call ratios, IV Rank, and Max Pain
Technical Sentiment: Based on RSI, MACD, trend analysis, and support/resistance
Composite Sentiment: Weighted aggregation of all sources with configurable weights
Confidence Scoring: Each sentiment source provides confidence level
Key Themes: Identified sentiment drivers (e.g., "bullish_momentum", "oversold_rsi")
Risk Factors: Highlighted concerns (e.g., "overbought_rsi", "near_resistance")
Parameters:
symbol: Stock ticker symbol (e.g., "AAPL", "SPY", "QQQ")sources: Comma-separated sentiment sources (default: "composite")"news": News article sentiment only"options": Options market sentiment only"technical": Technical indicator sentiment only"composite": All sources combined (recommended)
Sentiment Score Range: -1.0 (very bearish) to +1.0 (very bullish)
Example Usage:
Composite Sentiment Weights (default):
News Sentiment: 40%
Options Market Sentiment: 30%
Technical Sentiment: 30%
Response Includes:
Overall Score: Composite sentiment score (-1.0 to +1.0)
Confidence: Aggregated confidence level (0.0 to 1.0)
Individual Sources: Breakdown by news, options, technical with individual scores
Key Themes: Positive sentiment drivers identified across sources
Risk Factors: Warning signs and bearish indicators
Reasoning: Detailed explanation of sentiment calculation
Recommendation: Suggested action (bullish/neutral/bearish stance)
Sentiment Interpretation Guide:
Score Range | Sentiment | Interpretation | Trading Bias |
0.5 to 1.0 | Very Bullish | Strong positive signals across sources | Strong Buy bias |
0.2 to 0.5 | Bullish | Positive sentiment with good conviction | Buy bias |
-0.2 to 0.2 | Neutral | Mixed signals, no clear direction | Hold, wait for clarity |
-0.5 to -0.2 | Bearish | Negative sentiment with moderate conviction | Sell bias |
-1.0 to -0.5 | Very Bearish | Strong negative signals across sources | Strong Sell bias |
Confidence Interpretation:
High (0.7-1.0): Multiple sources agree, strong signal reliability
Medium (0.4-0.7): Some agreement, moderate signal reliability
Low (0.0-0.4): Sources disagree, weak signal reliability
Key Themes Examples:
bullish_momentum: Strong upward price movementoversold_rsi: RSI below 30, potential reversalbullish_options_flow: Low Put/Call ratio, bullish positioningpositive_news_sentiment: Positive news coveragehigh_iv_environment: Elevated volatility, favorable for option sellers
Risk Factors Examples:
overbought_rsi: RSI above 70, potential pullbacknear_resistance: Price approaching resistance levelbearish_macd_cross: MACD bearish crossoverhigh_put_call_ratio: Bearish options positioningnegative_news_sentiment: Negative news coverage
Use Cases:
Entry Timing: Identify optimal entry points with sentiment confirmation
Exit Strategy: Detect sentiment shifts for position management
Risk Assessment: Gauge market mood before major positions
Contrarian Signals: Identify extreme sentiment for reversal trades
Confirmation: Validate technical/fundamental analysis with sentiment
Options Strategy: Choose premium-selling vs premium-buying based on IV environment
Example Natural Language Queries:
Integration with Symbol Analysis:
The sentiment analysis is automatically included when using /analyze-symbol command:
This provides:
Multi-timeframe technical analysis
Current price and fundamentals
Options market analysis
Comprehensive sentiment analysis (news + options + technical)
Trading recommendation with sentiment-based conviction
Sentiment Components Breakdown:
News Sentiment (40% weight):
Analyzes recent news articles and headlines
Natural language processing for sentiment extraction
Publisher credibility weighting
Time decay for article recency
Options Market Sentiment (30% weight):
Put/Call Ratio: <0.7 bullish, 0.7-1.3 neutral, >1.3 bearish
IV Rank: Low IV (buy premium), High IV (sell premium)
Max Pain: Price gravitation toward max pain strike
Technical Sentiment (30% weight):
RSI: <30 oversold (bullish), >70 overbought (bearish)
MACD: Bullish/bearish crossovers and divergences
Trend Analysis: Short/medium/long term trend alignment
Support/Resistance: Price proximity to key levels
Performance Notes:
Composite sentiment calculation: ~2-3 seconds
Individual source queries: ~1-2 seconds each
Cached results valid for 5 minutes (real-time market data)
Concurrent analysis supported for multiple symbols
Code Examples:
See examples/sentiment_analysis_example.py for complete programmatic usage examples including:
Composite sentiment analysis
Individual source queries (technical, options, news)
Natural language query examples
Integration with
/analyze-symbolcommandSentiment interpretation guidelines
Usage Examples in Claude Desktop
Once you've set up the MCP server in Claude Desktop, you can use natural language:
Technical Notes
Data Sources:
Portfolio data: Interactive Brokers Flex Query (CSV/XML)
Market data: Yahoo Finance via yfinance library
Real-time quotes: Yahoo Finance delayed quotes (15-20 minutes)
Performance Metrics Definitions:
Sharpe Ratio: (Return - Risk-free rate) / Volatility. Higher is better. >1 is good, >2 is excellent.
Sortino Ratio: Like Sharpe but only penalizes downside volatility. Better for asymmetric returns.
Calmar Ratio: Annualized return / Maximum drawdown. Measures return per unit of downside risk.
Treynor Ratio: (Return - Risk-free rate) / Beta. Measures return per unit of systematic risk.
Information Ratio: (Portfolio return - Benchmark return) / Tracking error. Measures active management skill.
Beta: Systematic risk relative to benchmark. 1.0 = same risk as benchmark, >1.0 = more volatile.
Alpha: Excess return vs expected return (CAPM). Positive alpha = outperformance after risk adjustment.
Maximum Drawdown: Largest peak-to-trough decline. Key risk metric for understanding worst-case scenarios.
Correlation Interpretation:
|r| > 0.7: High correlation (limited diversification benefit)
0.3 < |r| < 0.7: Moderate correlation (some diversification)
|r| < 0.3: Low correlation (good diversification)
Negative correlation: Positions move in opposite directions (excellent diversification)
Usage Modes
IB Analytics supports three distinct usage modes for different user types and workflows:
1. Claude Desktop (Conversational Analysis) ๐ฌ
Target Users: Investors, portfolio managers, financial analysts
Use Case: Natural language portfolio analysis and investment research
Setup: Install MCP server in Claude Desktop configuration
What You Can Do:
Portfolio Analysis: "What's my portfolio performance this quarter?"
Investment Research: "Should I buy Apple stock right now?"
Tax Planning: "Show me tax-loss harvesting opportunities"
Market Analysis: "Analyze SPY with options strategies"
Investment Strategy: "Create a comprehensive investment plan"
Key Benefits:
โ Zero coding required - just ask questions in natural language
โ Automated data fetching from Interactive Brokers
โ Complete analysis from a single question
โ Real-time market data integrated with your portfolio
Example Workflow:
Time Savings: 2-3 hours of manual analysis โ 2 minutes
2. Claude Code + MCP (Custom Analysis) ๐ง
Target Users: Data scientists, quantitative analysts, developers
Use Case: Flexible data analysis with composable MCP tools
Setup: Use Claude Code with MCP server enabled
What You Can Do:
Custom Metrics: Calculate any combination of performance metrics
Fine-grained Data: Access trades, positions, account data directly
Period Comparisons: Compare performance across any date ranges
Advanced Analysis: Build custom strategies and backtests
Key Benefits:
โ Composable tools - mix and match for custom analysis
โ Fine-grained control - filter by symbol, asset class, date range
โ Programmatic access - integrate into your own workflows
โ Strategy resources - tax context, rebalancing guides, risk analysis
Example Workflow:
Time Savings: 4-5 hours of data extraction and analysis โ 15 minutes
3. Claude Code + Repository (Development Automation) ๐
Target Users: Developers, power users, automation engineers
Use Case: Complete development workflow automation with specialized AI agents
Setup: Clone repository and use Claude Code in project directory
What You Can Do:
๐ Portfolio & Investment Analysis (Slash Commands)
/investment-strategy- Master command: Complete investment strategy with portfolio + market analysisParallel market analysis: Analyzes all holdings simultaneously (80-90% time reduction)
Consolidated multi-account view: True portfolio-level analysis across ALL accounts
2-year chart context for every position with entry/exit scenarios
Options strategies with specific strikes and premiums
Tax-optimized execution plans per account
Actionable priorities: Urgent (this week) โ High (this month) โ Medium (this quarter)
/analyze-symbol SYMBOL- Comprehensive symbol analysis (stocks, ETFs, crypto, forex) with multi-timeframe technicalsDaily/weekly/monthly trend analysis with confluence scoring
Support/resistance levels with entry/exit signals
Options market analysis (IV Rank, Greeks, Max Pain) when applicable
News sentiment and catalysts
Buy/Sell/Hold rating with conviction level (1-10)
/options-strategy SYMBOL- Detailed options analysisIV environment assessment (buy vs sell premium)
Greeks analysis with risk assessment
2-3 specific strategy recommendations with exact strikes
Max profit/loss, breakeven, probability of profit
Risk/reward comparison with best strategy selection
/optimize-portfolio- Deep portfolio analysis and recommendations/tax-report --save- Tax planning with optimization strategies/compare-periods START END START END- Period-over-period performance comparison
Time Savings:
Investment strategy: 6-8 hours manual research โ 15-20 minutes (95% time reduction)
Stock analysis: 1-2 hours research โ 2-3 minutes (97% time reduction)
Options strategy: 45-60 minutes โ 3-5 minutes (93% time reduction)
๐ค AI-Powered Development (7 Specialized Sub-Agents)
Investment Analysis Agents:
data-analyzer ๐: Portfolio analysis specialist
Consolidated multi-account analysis
Performance, tax, cost, risk, bond analytics
Time-series position tracking
market-analyst ๐: Stock and options market specialist (NEW!)
Multi-timeframe technical analysis
Options Greeks, IV metrics, Max Pain calculations
Entry/exit timing with scenarios
Parallel execution: Analyzes 5-10 stocks simultaneously
strategy-coordinator ๐ฏ: Investment strategy orchestrator (NEW!)
Integrates portfolio + market analysis
Coordinates data-analyzer + market-analyst subagents
Parallel market analysis: 80-90% time reduction
Generates actionable, prioritized recommendations
Development Agents:
test-runner ๐งช: Testing and quality assurance
code-implementer ๐ป: Feature implementation with TDD
code-reviewer ๐: Code quality enforcement
performance-optimizer โก: Profiling and optimization
api-debugger ๐ง: IB API troubleshooting
issue-analyzer ๐: GitHub issue analysis
Time Savings:
Portfolio analysis: 3-4 hours โ 5 minutes (95% reduction)
GitHub issue resolution: 80 minutes โ 8 minutes (90% reduction)
Quality checks: 15 minutes โ 2 minutes (87% reduction)
๐ Complete Development Workflow Automation
GitHub Integration:
Quality Automation:
Expected Impact:
Time Savings: 90% reduction in routine tasks
Quality Improvement: Automated enforcement of best practices
Consistency: Standardized workflows across team
Documentation: Auto-generated PR descriptions and test reports
See .claude/README.md for complete documentation.
Feature Comparison
Feature | Mode 1: Desktop | Mode 2: MCP | Mode 3: Repository |
Investment Analysis | โ Natural language | โ Composable tools | โ Advanced automation |
Multi-Account Support | โ Automatic | โ Manual selection | โ Consolidated analysis |
Market Analysis | โ Basic | โ Detailed | โ Parallel + Advanced |
Options Strategies | โ Basic | โ Detailed | โ Professional-grade |
Tax Optimization | โ Recommendations | โ Custom analysis | โ Multi-account optimization |
Development Tools | โ | โ | โ 7 AI specialists |
GitHub Integration | โ | โ | โ Issue โ PR automation |
Quality Gates | โ | โ | โ Automated enforcement |
Time to Analysis | 2 minutes | 15 minutes | 15-20 minutes (comprehensive) |
Time to Implementation | N/A | N/A | 8 minutes (vs 80 manual) |
Learning Curve | None | Low | Medium |
Customization | Low | High | Very High |
Recommendation:
Start with Mode 1 if you're an investor looking for quick insights
Use Mode 2 if you need custom analysis or programmatic access
Adopt Mode 3 if you're developing features or need advanced automation
Position History & Time-Series Analysis
IB Analytics automatically stores daily position snapshots in SQLite for historical analysis and time-series tracking.
Features
Automatic Sync: Positions are automatically saved to SQLite when fetching data via
fetch_ib_dataHistorical Tracking: Query position history over any date range
Portfolio Evolution: Compare portfolio snapshots between two dates
Statistical Analysis: Calculate min/max/average metrics for positions over time
Multi-Account Support: Store and query positions from multiple IB accounts
Storage Location
Position data is stored in data/processed/positions.db (SQLite database).
Usage
Automatic Sync (Recommended)
Position snapshots are automatically saved when fetching data:
Manual Sync
Sync existing XML files to SQLite:
Historical Queries (MCP Tools)
get_position_history - Time Series for a Symbol
Get position history for a specific symbol over a date range:
Returns: Daily snapshots including quantity, price, value, and P&L for each date.
get_portfolio_snapshot - Single-Day Portfolio
Get all positions for an account on a specific date:
Returns: All positions on that date with values, quantities, and P&L.
compare_portfolio_snapshots - Portfolio Changes
Compare portfolio composition between two dates:
Returns:
Positions added/removed
Value changes for continuing positions
Total portfolio value change
Percentage changes
get_position_statistics - Statistical Summary
Get min/max/average statistics for a position over time:
Returns: Min/max/average for price, value, and unrealized P&L.
get_available_snapshot_dates - Available Dates
List all dates with position snapshots for an account:
Use Cases
Performance Tracking: Monitor how positions perform over time
Rebalancing Analysis: Identify portfolio drift from target allocations
Tax Planning: Analyze holding periods and gain/loss trends
Portfolio Evolution: Visualize how your portfolio composition changes
Risk Management: Track concentration risk and diversification over time
Historical Analysis: Backtest strategies against actual position history
Database Schema
position_snapshots: Daily position data per account
Composite key: (account_id, snapshot_date, symbol)
Fields: quantity, price, value, cost basis, P&L, bond-specific fields
Indexes: account+date, symbol+date, date, asset_class
snapshot_metadata: Snapshot-level statistics
Tracks total positions, portfolio value, cash balance per snapshot
Links to source XML files for audit trail
Data Integrity
Deduplication: Automatic deduplication via UNIQUE constraints
Decimal Precision: TEXT storage preserves financial calculation precision
Transaction Safety: ACID compliance for data consistency
Indexed Queries: Fast queries via strategic indexes
Audit Trail: Source XML file tracking for each snapshot
MCP Server Integration
IB Analytics provides a Model Context Protocol (MCP) server for integration with Claude Desktop and other MCP clients.
Quick Start
Features
22 Tools:
IB Portfolio: Fetch data, performance/cost/bond/tax/risk analysis, portfolio summary
Position History: Position history, portfolio snapshots, snapshot comparison, statistics, available dates
Stock Analysis: Stock info, current price, historical data, options chain, put/call ratio, news, market sentiment
Investment Analysis: Benchmark comparison, portfolio metrics, correlation analysis, analyst consensus
6 Resources: Access portfolio data, account info, trades, and positions via URI patterns
5 Prompts: Pre-configured analysis templates for common workflows
Claude Desktop Setup
Add to ~/Library/Application Support/Claude/claude_desktop_config.json:
See .claude/CLAUDE.md for detailed MCP documentation and usage patterns.
Development
Requirements
Python 3.9+
Interactive Brokers account with Flex Query access
Dependencies
requests (2.32.5+): HTTP client for API calls
pandas (2.2.3+): Data analysis and manipulation
pydantic (2.10.0+): Data validation and settings management
httpx (0.27.0+): Async HTTP client for parallel requests
rich (13.7.0+): Beautiful console output
typer (0.12.0+): CLI framework
yfinance (0.2.40+): Yahoo Finance data integration
fastmcp (2.0.0+): Model Context Protocol server framework
Security
MCP Server Security
The IB Analytics MCP server implements security best practices:
Error Masking: Internal error details are masked from clients (configurable with
IB_DEBUG=1)Input Validation: All inputs are validated before processing
File Path Protection: Path traversal attacks are prevented
File Size Limits: Maximum file size: 10MB
Timeout Protection: All operations have timeout limits
Retry Logic: Automatic retry for transient errors (max 3 attempts)
Debug Mode
Enable debug mode for detailed error information (development only):
Warning: Never enable debug mode in production as it exposes internal error details.
Credentials Security
Never commit
.envfiles to version controlStore credentials in environment variables or secure secret management systems
Use separate credentials for development and production
Regularly rotate API tokens
Troubleshooting
Common Issues
1. "Configuration error: Failed to load credentials"
Problem: QUERY_ID or TOKEN not found in environment
Solution:
2. "Validation error for 'start_date': Invalid date format"
Problem: Date format is incorrect
Solution: Use YYYY-MM-DD format
3. "IB API error: Statement not yet ready"
Problem: IB Flex Query is still processing
Solution: The server automatically retries (up to 3 times). If it still fails, wait a few minutes and try again.
4. "Yahoo Finance API error: No data found for SYMBOL"
Problem: Invalid stock symbol or no data available
Solution:
Verify the ticker symbol is correct
Check if the symbol is traded on supported exchanges
Try a different period or interval
5. "Timeout: IB API call timed out after 60 seconds"
Problem: API call took too long
Solution:
Check your internet connection
Reduce the date range
Try again during off-peak hours
Testing
Run tests to verify your installation:
MCP Server Testing
Test the MCP server connection:
Performance Optimization
If experiencing slow performance:
Reduce date ranges: Fetch smaller time periods
Use file caching: Reuse previously fetched data
Limit technical indicators: Only request needed indicators
Parallel processing: Use async operations where possible
License
MIT
Author
Kenichiro Nishioka
Support
For issues and questions, please check the IB Flex Query documentation.