TradingView Chart Image Scraper

by ertugrul59

Not rated
GitHub

About

Fetches TradingView chart images for a given ticker and interval.

Details

Author
ertugrul59
Categories
Web Scraping, Other, Finance

Setup

Install TradingView Chart Image Scraper in your MCP client (Claude Desktop, Cursor, Windsurf, and others).

Repository: https://github.com/ertugrul59/tradingview-chart-mcp

Follow the installation instructions in the repository README, then restart your MCP client.

MCP Server - TradingView Chart Image Scraper

πŸš€ Now with Browser Pooling Optimization for 70-80% Better Concurrent Performance!

This MCP server provides tools to fetch TradingView chart images based on ticker and interval with advanced browser pooling for maximum concurrent performance.

- Production Version: Usesmain_optimized.pywith browser pooling for maximum concurrent performance
- Performance Improvement: 70-80% faster for concurrent requests
- Concurrent Handling: Supports up to 4 simultaneous requests with pre-initialized browser instances
- Expected Performance:

- 1 request: ~6-8s (baseline)
- 2 concurrent: ~3-4s each (60-70% faster)
- 3 concurrent: ~2.5-3.5s each (70-80% faster)

- main_optimized.py(Production): Browser pooling, concurrent optimization, performance tracking
- main.py(Legacy): Simple single-browser approach, kept for debugging/fallback

- πŸš€ Optimized Chart Image Tool:Fetches direct chart images with browser pooling for maximum concurrent performance
- πŸ“Š Performance Statistics:Built-in performance monitoring and statistics
- πŸ”„ Browser Pool Management:Pre-initialized browser instances for zero-overhead concurrent requests
- 🎯 Natural Language Prompts:Easy chart requests with interval mapping
- βš™οΈ Environment Configuration:Fully configurable via environment variables
- πŸ” TradingView Authentication:Secure session-based authentication
- πŸ’Ύ Clipboard Capture:Direct base64 image capture for faster performance

Description:Fetches the direct image URL for a TradingView chart snapshot with optimized concurrent performance.

Performance:This optimized version achieves 70-80% better performance for concurrent requests using browser pooling technology.

- ticker(str): The TradingView ticker symbol (e.g., "BYBIT:BTCUSDT.P", "NASDAQ:AAPL").Required.
- interval(str): The chart time interval (e.g., '1', '5', '15', '60', '240', 'D', 'W').Required.

- (str): The direct TradingView snapshot image URL (e.g.,data:image/png;base64,...orhttps://s3.tradingview.com/snapshots/...).

- Error(MCP type): If the scraper encounters an error. Error codes:

- 400: Input error (invalid ticker/interval format)
- 503: Scraper error (failure during the scraping process)
- 500: Unexpected internal server error

Description:Get performance statistics for the optimized TradingView MCP server.

- Detailed metrics about request performance, improvement over baseline, and browser pool status

πŸš€ OPTIMIZED TRADINGVIEW MCP SERVER PERFORMANCE STATS β€’ Total Requests: 12 β€’ Average Time: 3.30s β€’ Performance Improvement: 70.8% β€’ Browsers in Pool: 4 β€’ Max Concurrent: 4

- Get the {interval} chart for {ticker}

- Maps common timeframe names (e.g., "1 minute", "5 minute", "1 hour", "daily") to TradingView codes

- Specifically requests the daily ('D') chart

- Comprehensive prompt with timeframe mapping

# Navigate to the project directory cd tradingview-chart-mcp # Create the venv (use python3 if python is not linked) python3 -m venv .venv

Your terminal prompt should now indicate you are in the(.venv).

Configure Environment (for Local Testing):

Ensure ChromeDriver:Make surechromedriveris installed and accessible in your system's PATH, or configure thetview-scraper.pyaccordingly if it allows specifying a path.

# HTTP transport with custom port python main_optimized.py --transport streamable-http --port 8003 # Enable authentication (default for TradingView) python main_optimized.py --auth # Adjust concurrency python main_optimized.py --max-concurrent 6 # Disable browser pooling (fallback to traditional) python main_optimized.py --disable-pooling

Test the server using the same approach as the production agent:

cd tests/ # Sequential performance test python test_mcp_agent_style.py --runs 5 --ticker BYBIT:BTCUSDT.P --interval 240 # Concurrent performance test python test_mcp_agent_style.py --concurrent 3 --ticker BYBIT:BTCUSDT.P --interval 240 # Test different symbols and timeframes python test_mcp_agent_style.py --concurrent 4 --ticker NASDAQ:AAPL --interval 15 python test_mcp_agent_style.py --concurrent 2 --ticker BYBIT:ETHUSDT.P --interval D

- Sequential: ~6-8s per request (baseline)
- Concurrent (3x): ~2.5-3.5s per request (70-80% improvement)
- Success Rate: 100% reliability under load
- Throughput: Up to 4 concurrent requests efficiently handled

- Pre-initialized Browsers: 4 browser instances ready for immediate use
- Thread-Safe Pool: Concurrent access with proper locking
- Async Semaphore: Optimal request limiting
- Performance Tracking: Real-time statistics and monitoring
- Graceful Cleanup: Proper browser lifecycle management

TheMCP_SCRAPER_USE_SAVE_SHORTCUTfeature allows you to capture chart images directly to the clipboard as base64 data URLs:

- Faster Performance: No HTTP requests needed
- More Reliable: No dependency on TradingView's CDN
- Offline Capability: Works once chart is loaded
- Direct Integration: Base64 data URLs for immediate use

# Enable clipboard image capture (DEFAULT) MCP_SCRAPER_USE_SAVE_SHORTCUT=True # Disable and use traditional screenshot links MCP_SCRAPER_USE_SAVE_SHORTCUT=False

- get_tradingview_chart_image(ticker: str, interval: str): Optimized chart fetching with browser pooling

- "Get the 15 minute chart for NASDAQ:AAPL"
- "Show me the daily chart for BYBIT:BTCUSDT.P"
- "Fetch TradingView chart image for COINBASE:ETHUSD on the 60 timeframe"

If you encounter issues with the optimized version:

python main_optimized.py --disable-pooling
python main_optimized.py --log-level DEBUG

The optimized server includes built-in performance monitoring:

- Request success rates
- Average response times
- Performance improvement metrics
- Browser pool utilization
- Concurrent request handling statistics

Access these metrics via theget_performance_statstool or through the server logs.

No reviews yet β€” be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.