An open API service indexing awesome lists of open source software.

https://github.com/jongan69/trading-api

A Rust Market Data API
https://github.com/jongan69/trading-api

Last synced: 10 months ago
JSON representation

A Rust Market Data API

Awesome Lists containing this project

README

          

# Trading API MCP Server

A comprehensive **Model Context Protocol (MCP) server** that exposes powerful market research tools to AI agents. Built on top of a robust Rust trading API that aggregates data from multiple financial sources including traditional markets, cryptocurrencies, DeFi protocols, Solana ecosystem, and meme tokens.

## ๐ŸŒŸ Features

- **40+ Market Research Tools** for AI agents via MCP
- **Multi-Source Data Aggregation**: Stocks, crypto, DeFi, NFTs, meme tokens, news, sentiment, options
- **Real-Time Market Data** from 15+ sources including Reddit, Finviz, CoinGecko, Kraken, Yahoo Finance, Hyperliquid, Pump.fun, Helius
- **Comprehensive Analysis** combining traditional and DeFi markets
- **Solana Ecosystem Integration** with NFT and token analytics
- **DeFi Protocol Support** including Hyperliquid derivatives
- **Meme Token Analysis** via Pump.fun integration
- **Production-Ready** with error handling, caching, rate limiting, and comprehensive documentation
- **Trading Capabilities** for Kraken and Alpaca (paper trading)

## ๐Ÿš€ Quick Start

```bash
# 1. Setup (one time)
./setup_mcp.sh

# 2. Start services
cargo run # Terminal 1: Rust API
source venv/bin/activate # Terminal 2: Python env
python mcp_server.py # Terminal 2: MCP server

# 3. Test everything works
python test_mcp.py
```

## ๐Ÿ› ๏ธ MCP Tools Available

### Core Market Analysis Tools
| Tool | Description | Use Case |
|------|-------------|----------|
| `get_comprehensive_market_analysis` | Complete market overview across all sources | Overall market research |
| `get_trending_stocks` | Hot stocks from Reddit, Finviz, and other sources | Trend identification |
| `get_trending_crypto` | Trending cryptocurrencies from multiple sources | Crypto market analysis |
| `get_market_news` | Aggregated financial news from multiple sources | Sentiment analysis |
| `get_reddit_trending_stocks` | Reddit sentiment analysis with social indicators | Social media trends |
| `search_market_data` | Search across all data sources | Targeted research |

### Traditional Finance Tools
| Tool | Description | Use Case |
|------|-------------|----------|
| `get_yahoo_metrics` | Stock metrics, ratios, and financial data | Fundamental analysis |
| `get_finviz_data` | Forex, futures, insider trading data | Traditional markets |
| `get_high_open_interest` | Options contracts with high open interest | Institutional sentiment |

### Cryptocurrency Exchange Tools
| Tool | Description | Use Case |
|------|-------------|----------|
| `get_coingecko_data` | Comprehensive crypto data and market overview | Detailed crypto research |
| `get_coingecko_market_context` | AI-powered market insights from CoinGecko | Market intelligence |
| `get_coingecko_trending_symbols` | Trending crypto symbols | Opportunity identification |
| `get_coingecko_gainers_losers` | Top crypto gainers and losers | Momentum analysis |
| `get_kraken_ticker` | Real-time crypto prices from Kraken | Live market data |
| `get_kraken_orderbook` | Kraken orderbook depth analysis | Liquidity analysis |
| `get_kraken_ohlc` | OHLC candlestick data for technical analysis | Price action analysis |
| `get_kraken_recent_trades` | Recent trading activity | Market momentum |
| `get_kraken_assets` | Available Kraken trading assets | Asset discovery |

### DeFi Protocol Tools
| Tool | Description | Use Case |
|------|-------------|----------|
| `get_hyperliquid_markets` | All Hyperliquid perpetual markets | DeFi derivatives analysis |
| `get_hyperliquid_trending` | Trending DeFi assets on Hyperliquid | Hot DeFi opportunities |
| `get_hyperliquid_top_volume` | Highest volume Hyperliquid markets | Activity analysis |
| `get_hyperliquid_movers` | Top DeFi gainers and losers | Momentum tracking |
| `get_hyperliquid_funding` | Perpetual funding rates | Market sentiment |
| `get_hyperliquid_market_data` | Specific asset market data | Deep asset analysis |
| `get_hyperliquid_overview` | Complete Hyperliquid market overview | DeFi market intelligence |

### Solana Ecosystem Tools
| Tool | Description | Use Case |
|------|-------------|----------|
| `get_solana_asset` | Detailed Solana asset information | Asset research |
| `get_solana_trending_nfts` | Trending Solana NFT collections | NFT market analysis |
| `get_solana_trending_tokens` | Trending Solana tokens | DeFi token discovery |
| `get_solana_top_collections` | Top NFT collections by metrics | NFT investment research |
| `get_solana_wallet_holdings` | Wallet portfolio analysis | Whale watching |
| `search_solana_assets` | Search assets by various criteria | Targeted Solana research |

### Meme Token & Pump.fun Tools
| Tool | Description | Use Case |
|------|-------------|----------|
| `get_pumpfun_trending` | Trending pump.fun meme tokens | Memecoin analysis |
| `get_pumpfun_token_info` | Detailed token information | Token due diligence |
| `get_pumpfun_market_summary` | Pump.fun market overview | Meme market intelligence |
| `search_pumpfun_tokens` | Search for specific meme tokens | Token discovery |
| `get_pumpfun_new_tokens` | Newly launched tokens | Fresh opportunity identification |
| `get_pumpfun_gainers_losers` | Top meme token movers | Momentum analysis |
| `get_pumpfun_bonding_curve` | Token bonding curve economics | Tokenomics analysis |

### System & Monitoring Tools
| Tool | Description | Use Case |
|------|-------------|----------|
| `get_system_health` | API system health status | Monitoring |
| `get_system_metrics` | Performance metrics | System analysis |

## ๐Ÿค– AI Agent Integration

### Claude Desktop
Add to your MCP configuration:
```json
{
"mcpServers": {
"trading-api": {
"command": "python",
"args": ["/path/to/trading-api/mcp_server.py"],
"transport": "stdio"
}
}
}
```

### Research Agents (LangChain)
```python
from langchain_mcp_adapters.client import MultiServerMCPClient

mcp_config = {
"trading_api": {
"command": "python",
"args": ["/path/to/trading-api/mcp_server.py"],
"transport": "stdio"
}
}

client = MultiServerMCPClient(mcp_config)
tools = await client.get_tools()
```

## ๐Ÿ“Š Example AI Research Queries

### Traditional Markets
- *"Give me a comprehensive analysis of current market conditions"*
- *"What are the top trending stocks and what's driving their movement?"*
- *"Analyze Tesla across all data sources - news, sentiment, technicals"*
- *"What is the options market telling us about institutional positioning?"*
- *"Show me insider trading activity and high open interest options"*

### Cryptocurrency & DeFi
- *"What are the hottest DeFi opportunities on Hyperliquid right now?"*
- *"Compare Bitcoin funding rates across perpetual markets"*
- *"Show me trending Solana tokens with high volume"*
- *"Analyze the correlation between traditional crypto and DeFi markets"*
- *"What's driving the current crypto market sentiment?"*

### Meme Tokens & Emerging Markets
- *"Find newly launched meme tokens on pump.fun with strong momentum"*
- *"Analyze bonding curve economics for trending pump.fun tokens"*
- *"What are the top Solana NFT collections by volume today?"*
- *"Show me whale wallet activity in the Solana ecosystem"*

### Cross-Market Analysis
- *"How are traditional stocks correlating with crypto markets today?"*
- *"Compare meme token performance against traditional crypto"*
- *"Identify arbitrage opportunities between centralized and DeFi markets"*
- *"Analyze market sentiment across Reddit, news, and on-chain data"*

## ๐Ÿ—๏ธ Architecture

```
AI Agent <--MCP--> Python MCP Server <--HTTP--> Rust Trading API <--> Data Sources
|
โ”œโ”€โ”€ Traditional Finance
โ”‚ โ”œโ”€โ”€ Yahoo Finance
โ”‚ โ”œโ”€โ”€ Finviz
โ”‚ โ”œโ”€โ”€ Reddit
โ”‚ โ””โ”€โ”€ Alpaca
โ”‚
โ”œโ”€โ”€ Cryptocurrency
โ”‚ โ”œโ”€โ”€ CoinGecko
โ”‚ โ”œโ”€โ”€ Kraken
โ”‚ โ””โ”€โ”€ Helius
โ”‚
โ”œโ”€โ”€ DeFi Protocols
โ”‚ โ””โ”€โ”€ Hyperliquid
โ”‚
โ”œโ”€โ”€ Solana Ecosystem
โ”‚ โ”œโ”€โ”€ Helius API
โ”‚ โ”œโ”€โ”€ Jito
โ”‚ โ””โ”€โ”€ Direct RPC
โ”‚
โ””โ”€โ”€ Meme Tokens
โ””โ”€โ”€ Pump.fun
```

### Components
- **Rust API**: High-performance data aggregation with caching, rate limiting, and error handling
- **Python MCP Server**: Standards-compliant MCP interface with 40+ specialized tools
- **Data Sources**: 15+ integrated sources spanning traditional finance, crypto, DeFi, and emerging markets
- **Trading Integration**: Paper and live trading capabilities via Kraken and Alpaca
- **Caching Layer**: Intelligent caching to optimize API calls and reduce latency
- **Monitoring**: Built-in health checks and performance metrics

## ๐Ÿ“ Repository Structure

```
trading-api/
โ”œโ”€โ”€ src/ # Rust trading API source code
โ”‚ โ”œโ”€โ”€ routes/ # API endpoint handlers
โ”‚ โ”‚ โ”œโ”€โ”€ data.rs # Traditional market data
โ”‚ โ”‚ โ”œโ”€โ”€ coingecko.rs # CoinGecko crypto data
โ”‚ โ”‚ โ”œโ”€โ”€ kraken.rs # Kraken exchange
โ”‚ โ”‚ โ”œโ”€โ”€ hyperliquid.rs # DeFi derivatives
โ”‚ โ”‚ โ”œโ”€โ”€ solana.rs # Solana ecosystem
โ”‚ โ”‚ โ”œโ”€โ”€ pumpfun.rs # Meme token data
โ”‚ โ”‚ โ”œโ”€โ”€ yahoo.rs # Yahoo Finance
โ”‚ โ”‚ โ”œโ”€โ”€ options.rs # Options analysis
โ”‚ โ”‚ โ”œโ”€โ”€ high_open_interest.rs # High OI analysis
โ”‚ โ”‚ โ””โ”€โ”€ system.rs # Health & monitoring
โ”‚ โ”œโ”€โ”€ sources/ # Data source integrations
โ”‚ โ”‚ โ”œโ”€โ”€ finviz_data.rs # Finviz scraping
โ”‚ โ”‚ โ”œโ”€โ”€ reddit_data.rs # Reddit sentiment
โ”‚ โ”‚ โ”œโ”€โ”€ yahoo_data.rs # Yahoo Finance API
โ”‚ โ”‚ โ”œโ”€โ”€ coingecko_data.rs # CoinGecko API
โ”‚ โ”‚ โ”œโ”€โ”€ kraken_data.rs # Kraken API
โ”‚ โ”‚ โ”œโ”€โ”€ hyperliquid_data.rs # Hyperliquid API
โ”‚ โ”‚ โ”œโ”€โ”€ helius_data.rs # Solana data via Helius
โ”‚ โ”‚ โ”œโ”€โ”€ pumpfun_data.rs # Pump.fun integration
โ”‚ โ”‚ โ”œโ”€โ”€ alpaca_data.rs # Options data
โ”‚ โ”‚ โ””โ”€โ”€ jito_data.rs # Jito MEV data
โ”‚ โ”œโ”€โ”€ helpers/ # Analysis and aggregation logic
โ”‚ โ”‚ โ”œโ”€โ”€ trending_stocks.rs # Stock trend analysis
โ”‚ โ”‚ โ”œโ”€โ”€ trending_cryptos.rs # Crypto trend analysis
โ”‚ โ”‚ โ”œโ”€โ”€ news.rs # News aggregation
โ”‚ โ”‚ โ”œโ”€โ”€ metrics.rs # Performance metrics
โ”‚ โ”‚ โ””โ”€โ”€ options.rs # Options analysis
โ”‚ โ”œโ”€โ”€ trading/ # Trading execution modules
โ”‚ โ”‚ โ”œโ”€โ”€ kraken_trading.rs # Kraken trading
โ”‚ โ”‚ โ””โ”€โ”€ alpaca_trading.rs # Alpaca trading
โ”‚ โ”œโ”€โ”€ middleware/ # HTTP middleware
โ”‚ โ”œโ”€โ”€ types.rs # Type definitions
โ”‚ โ”œโ”€โ”€ errors.rs # Error handling
โ”‚ โ”œโ”€โ”€ config.rs # Configuration management
โ”‚ โ”œโ”€โ”€ cache.rs # Caching layer
โ”‚ โ””โ”€โ”€ lib.rs # Main library
โ”œโ”€โ”€ examples/ # Usage examples
โ”‚ โ”œโ”€โ”€ coingecko_example.rs # CoinGecko integration
โ”‚ โ”œโ”€โ”€ kraken_example.rs # Kraken integration
โ”‚ โ”œโ”€โ”€ high_open_interest_example.rs # Options analysis
โ”‚ โ””โ”€โ”€ trending_options_example.rs # Trending analysis
โ”œโ”€โ”€ docs/ # Comprehensive documentation
โ”‚ โ”œโ”€โ”€ API_DOCUMENTATION.md # Complete API reference
โ”‚ โ”œโ”€โ”€ QUICK_START.md # Quick setup guide
โ”‚ โ”œโ”€โ”€ MCP_SERVER_README.md # MCP server details
โ”‚ โ”œโ”€โ”€ PRODUCTION_READINESS.md # Production deployment
โ”‚ โ””โ”€โ”€ TROUBLESHOOTING.md # Common issues
โ”œโ”€โ”€ tests/ # Test suites
โ”‚ โ”œโ”€โ”€ integration_tests.rs # Integration tests
โ”‚ โ””โ”€โ”€ e2e.rs # End-to-end tests
โ”œโ”€โ”€ mcp_server.py # MCP server implementation (40+ tools)
โ”œโ”€โ”€ research_agent_example.py # AI research agent example
โ”œโ”€โ”€ requirements.txt # Python dependencies
โ”œโ”€โ”€ setup_mcp.sh # Automated setup script
โ”œโ”€โ”€ test_mcp.py # MCP server test suite
โ”œโ”€โ”€ Cargo.toml # Rust dependencies
โ””โ”€โ”€ README.md # This comprehensive guide
```

## ๐Ÿ”ง Installation & Setup

### Prerequisites
- Rust 1.70+
- Python 3.8+
- pip and virtual environment support

### Automated Setup
```bash
# Clone and setup everything
git clone
cd trading-api
./setup_mcp.sh
```

### Manual Setup
```bash
# Rust dependencies
cargo build

# Python environment
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```

## ๐Ÿงช Testing

```bash
# Test Rust API
cargo test

# Test MCP server integration
python test_mcp.py

# Test with sample research queries
python research_agent_example.py
```

## ๐Ÿ“ Environment Variables

Create a `.env` file:
```bash
# API Keys (optional, for enhanced data)
REDDIT_CLIENT_ID=your_reddit_client_id
REDDIT_CLIENT_SECRET=your_reddit_client_secret
ALPHAVANTAGE_API_KEY=your_alphavantage_key

# Server Configuration
SERVER_HOST=localhost
SERVER_PORT=3000

# For research agent example
OPENAI_API_KEY=your_openai_key
ANTHROPIC_API_KEY=your_anthropic_key
```

## ๐Ÿšฆ API Endpoints (Rust Server)

The Rust API provides comprehensive endpoints organized by category:

### System & Health
- `GET /health` - System health check
- `GET /metrics` - Performance metrics
- `GET /docs` - Interactive API documentation (Swagger UI)

### Traditional Markets
- `GET /trending/stocks` - Trending stocks from multiple sources
- `GET /reddit/stocks` - Reddit sentiment analysis
- `GET /news` - Aggregated financial news
- `GET /yahoo/metrics` - Yahoo Finance stock metrics
- `GET /forex` - Forex market data (Finviz)
- `GET /insider` - Insider trading activity
- `GET /high-open-interest` - High open interest options

### Cryptocurrency Exchanges
- `GET /trending/crypto` - Trending cryptocurrencies
- `GET /coingecko/top` - Top cryptocurrencies (CoinGecko)
- `GET /coingecko/trending` - Trending crypto symbols
- `GET /coingecko/gainers` - Top crypto gainers
- `GET /coingecko/losers` - Top crypto losers
- `GET /coingecko/market-context` - AI-powered market insights
- `GET /kraken/ticker` - Kraken ticker data
- `GET /kraken/orderbook/{pair}` - Orderbook depth
- `GET /kraken/ohlc/{pair}` - OHLC candlestick data
- `GET /kraken/trades/{pair}` - Recent trades
- `GET /kraken/assets` - Available trading assets

### DeFi Protocols
- `GET /hyperliquid/markets` - All Hyperliquid markets
- `GET /hyperliquid/trending` - Trending DeFi assets
- `GET /hyperliquid/volume/top` - Highest volume markets
- `GET /hyperliquid/movers` - Top gainers/losers
- `GET /hyperliquid/funding` - Funding rates
- `GET /hyperliquid/market/{coin}` - Specific market data
- `GET /hyperliquid/stats/overview` - Market overview

### Solana Ecosystem
- `GET /solana/asset/{asset_id}` - Asset details
- `GET /solana/nfts/trending` - Trending NFT collections
- `GET /solana/tokens/trending` - Trending tokens
- `GET /solana/collections/top` - Top NFT collections
- `GET /solana/wallet/{address}/holdings` - Wallet analysis
- `GET /solana/assets/search` - Asset search

### Meme Tokens (Pump.fun)
- `GET /pumpfun/trending` - Trending meme tokens
- `GET /pumpfun/token/{mint}` - Token details
- `GET /pumpfun/market-summary` - Market overview
- `GET /pumpfun/search/{query}` - Token search
- `GET /pumpfun/new-tokens` - Newly launched tokens
- `GET /pumpfun/top-gainers` - Top gaining tokens
- `GET /pumpfun/top-losers` - Top losing tokens
- `GET /pumpfun/bonding-curve/{mint}` - Bonding curve data

**๐Ÿ“– Complete Documentation:** Available at `http://localhost:3000/docs` when running the server.
**๐Ÿ” OpenAPI Spec:** Available at `http://localhost:3000/openapi.json`

## ๐Ÿ” Data Sources

### Traditional Finance
| Source | Data Type | Update Frequency | Features |
|--------|-----------|------------------|----------|
| **Yahoo Finance** | Stock prices, metrics, financial ratios | Real-time/Daily | Comprehensive stock analysis |
| **Finviz** | Stocks, forex, futures, insider trading | Real-time | Market screening, insider activity |
| **Reddit** | Social sentiment, trending discussions | Real-time | Social sentiment analysis |
| **Alpaca** | Options data, high open interest | Real-time | Options market intelligence |

### Cryptocurrency Exchanges
| Source | Data Type | Update Frequency | Features |
|--------|-----------|------------------|----------|
| **CoinGecko** | Crypto prices, market data, trending | Real-time | Comprehensive crypto analytics |
| **Kraken** | Exchange data, orderbooks, trades | Real-time | Professional trading data |

### DeFi Protocols
| Source | Data Type | Update Frequency | Features |
|--------|-----------|------------------|----------|
| **Hyperliquid** | Perpetual markets, funding rates | Real-time | DeFi derivatives intelligence |

### Solana Ecosystem
| Source | Data Type | Update Frequency | Features |
|--------|-----------|------------------|----------|
| **Helius** | NFTs, tokens, wallet analysis | Real-time | Comprehensive Solana data |
| **Jito** | MEV data, block analysis | Real-time | MEV and validator insights |
| **Direct RPC** | On-chain data, program accounts | Real-time | Raw blockchain data |

### Meme Tokens & Emerging Markets
| Source | Data Type | Update Frequency | Features |
|--------|-----------|------------------|----------|
| **Pump.fun** | Meme tokens, bonding curves | Real-time | Complete meme token ecosystem |

### Data Quality & Reliability
- **Redundancy**: Multiple sources for critical data points
- **Validation**: Cross-source data validation and consistency checks
- **Fallback**: Graceful degradation when sources are unavailable
- **Rate Limiting**: Intelligent rate limiting to respect API limits
- **Caching**: Smart caching to reduce API calls and improve performance

## ๐Ÿ›ก๏ธ Security & Performance

### Performance Optimizations
- **Intelligent Caching**: Multi-layer caching system with TTL-based invalidation
- **Connection Pooling**: Efficient HTTP connection management
- **Concurrent Processing**: Async/await throughout for maximum throughput
- **Rate Limiting**: Adaptive rate limiting per data source
- **Request Batching**: Batch similar requests to reduce API calls
- **Response Compression**: Gzip compression for API responses

### Security Features
- **Input Validation**: Comprehensive validation of all user inputs
- **Sanitization**: Data sanitization to prevent injection attacks
- **CORS Protection**: Configurable CORS policies
- **Error Handling**: Secure error messages without information leakage
- **API Key Management**: Secure handling of external API credentials
- **Request Logging**: Comprehensive request/response logging for audit trails

### Reliability & Monitoring
- **Health Checks**: Built-in health monitoring for all components
- **Circuit Breakers**: Automatic circuit breakers for failing services
- **Graceful Degradation**: Continue operating with reduced functionality
- **Metrics Collection**: Performance metrics and analytics
- **Error Recovery**: Automatic retry logic with exponential backoff
- **Service Discovery**: Dynamic service endpoint management

## ๐Ÿค Contributing

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## ๐Ÿ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## ๐Ÿ†˜ Support & Troubleshooting

### Common Issues

**"Failed to connect to API"**
- Ensure Rust API is running: `cargo run`
- Check port 3000 is available: `curl http://localhost:3000/health`

**"Tool not found"**
- Verify MCP server is running: `python mcp_server.py`
- Check tool names match exactly

**"Authentication errors"**
- Set API keys in `.env` file
- For research agent example, set `OPENAI_API_KEY` and `ANTHROPIC_API_KEY`

### Getting Help

- ๐Ÿ“– Check the documentation in this README
- ๐Ÿงช Run the test suite: `python test_mcp.py`
- ๐Ÿ” Check server logs for detailed error information
- ๐Ÿ“ Review the example integration: `research_agent_example.py`

## ๐ŸŽฏ What You Get

โœ… **Production-ready MCP server** with 40+ specialized market research tools
โœ… **Comprehensive market coverage** across traditional finance, crypto, DeFi, and emerging markets
โœ… **Multi-source data aggregation** from 15+ major financial platforms
โœ… **Real-time market intelligence** with intelligent caching and rate limiting
โœ… **Solana ecosystem integration** including NFTs, tokens, and wallet analysis
โœ… **DeFi protocol support** with Hyperliquid derivatives and funding rates
โœ… **Meme token analytics** via Pump.fun integration with bonding curve analysis
โœ… **Trading capabilities** for both paper and live trading (Kraken, Alpaca)
โœ… **Easy AI integration** with any MCP-compatible system (Claude, LangChain, etc.)
โœ… **Comprehensive documentation** with examples, troubleshooting, and production guides
โœ… **Automated setup** with testing tools and health monitoring
โœ… **Enterprise-ready** with error handling, logging, metrics, and security features

### ๐Ÿš€ Transform Your AI Agents Into:
- **Sophisticated Market Researchers** with access to traditional and emerging markets
- **DeFi Intelligence Analysts** tracking derivatives and funding rates
- **Meme Token Specialists** analyzing bonding curves and social sentiment
- **Cross-Market Arbitrage Detectors** identifying opportunities across ecosystems
- **Portfolio Analysts** with wallet tracking and whale watching capabilities
- **News & Sentiment Analyzers** combining social media and traditional news sources

**Ready to revolutionize your AI trading and research capabilities?** This comprehensive trading API MCP server provides everything you need to build intelligent, data-driven trading agents that understand both traditional and emerging financial markets.