ASUS-TUFLSR/crypto_mcp_server
3.1
If you are the rightful owner of crypto_mcp_server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
This is a Python-based Market Data Provider (MCP) server for cryptocurrency market data.
Crypto MCP Server
Overview
This is a Python-based Market Data Provider (MCP) server for retrieving real-time and historical cryptocurrency market data from major exchanges using the CCXT library. It provides REST endpoints for data fetching and historical queries, a WebSocket for real-time updates, error handling, and caching for efficiency.
Approach
- Framework: FastAPI for building the API (async, modern, with auto-generated docs).
- Data Source: CCXT (async version) for unified access to exchanges like Binance, Coinbase. Supports public APIs without keys.
- Features:
- REST:
/realtime/{exchange}/{symbol}for current ticker data. - REST:
/historical/{exchange}/{symbol}for OHLCV historical data (query params: timeframe, since, limit). - WebSocket:
/ws/realtime/{exchange}/{symbol}for polled real-time updates (every 5 seconds). - Caching: In-memory TTL cache (10 seconds) for real-time data using cachetools.
- Error Handling: HTTP exceptions for invalid inputs; try-except for API errors.
- Models: Pydantic for structured responses.
- REST:
- Testing: Pytest with unit tests (mocking CCXT) and integration tests (using FastAPI TestClient). Covers endpoints, data fetching, and error cases.
- Best Practices: Modular code, async methods, type hints, logging (basic).
- Tools Used: Developed with assistance from LLMs (e.g., Grok/Claude for code ideas and debugging). No peer collaboration.
Setup
- Clone the repo:
git clone https://github.com/ASUS-TUFLSR/crypto_mcp_server. - Install dependencies:
pip install -r requirements.txt. - Run the server:
uvicorn src.main:app --reload. - Access API docs: http://127.0.0.1:8000/docs.
- Test WebSocket: Use
wscat -c ws://127.0.0.1:8000/ws/realtime/binance/BTC/USDT.
Usage Examples
- Real-time: GET
/realtime/binance/BTC/USDT→ Returns ticker data. - Historical: GET
/historical/binance/BTC/USDT?timeframe=1d&since=1704067200000&limit=10→ Returns OHLCV list. - WebSocket: Connect to
/ws/realtime/binance/BTC/USDT→ Receives ticker JSON every 5s.
Assumptions
- Exchanges/symbols must be valid in CCXT (e.g., 'binance', 'BTC/USDT').
- 'since' is Unix timestamp in milliseconds.
- No rate limiting or auth (public data only).
- Polling for real-time (not full streaming due to complexity).
- Tests mock CCXT to avoid real API calls.
Running Tests
pytestfrom root. Targets ~80% coverage (endpoints, data provider, errors).
Limitations/Future Improvements
- Add Redis for distributed caching.
- Support CoinMarketCap API (requires key).
- Full WebSocket streaming via CCXT's watch methods.
- Rate limiting and API keys support.