mcp-crypto-server

meetkavad/mcp-crypto-server

3.1

If you are the rightful owner of mcp-crypto-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.

The MCP Crypto Market Data Server is a Python-based server designed to provide real-time and historical crypto market data through a clean architecture using CCXT.

MCP Crypto Market Data Server

A Python-based MCP-compatible crypto market data server that provides:

  • Real-time ticker data
  • Historical OHLCV data
  • WebSocket streaming updates
  • Exchange + symbol discovery
  • Caching, retry logic, and error handling
  • Clean architecture with CCXT
  • Automated background polling (FastAPI startup loop)
  • Test suite (pytest)

This project is built as an internship assignment for a crypto data platform and follows good backend/API practices.


🚀 Features

1. Real-time Market Data (Ticker)

Fetch live price information from major exchanges using CCXT.

GET /api/fetch/ticker?exchange=binance&symbol=BTC/USDT

Includes:

  • Automatic retries (tenacity)
  • Caching (cachetools TTLCache)
  • Error handling

2. Historical Data (OHLCV)

Retrieve candlestick data:

GET /api/historical?exchange=binance&symbol=BTC/USDT&timeframe=1m

3. WebSocket Real-Time Streaming

Subscribe to live updates:

ws://localhost:8000/ws/ticker/binance/BTC/USDT

A background task polls exchanges and broadcasts updates to connected WS clients.


4. Utility Endpoints

List supported exchanges:

GET /api/exchanges

List supported symbols:

GET /api/symbols?exchange=binance

5. Background Broadcaster

On startup, FastAPI launches an infinite async loop that polls active subscriptions and pushes updates through WebSocket.


📂 Project Structure

mcp-crypto-server/
├── app/
│   ├── main.py
│   ├── api.py
│   ├── ccxt_client.py
│   ├── cache.py
│   ├── broadcaster.py
│   ├── config.py
│   ├── utils.py
│   └── __init__.py
├── tests/
│   ├── test_api.py
│   ├── test_ws.py
│   ├── test_cache.py
│   ├── test_broadcaster.py
│   └── conftest.py
├── .gitignore
├── requirements.txt
├── pytest.ini
└── README.md

🛠 Installation

1. Clone the repository

git clone https://github.com/meetkavad/mcp-crypto-server
cd mcp-crypto-server

2. Create and activate virtual environment

python -m venv env
source env/bin/activate     # macOS/Linux
env\Scripts\activate       # Windows

3. Install dependencies

pip install -r requirements.txt

▶️ Running the Server

Option A — Using Python (recommended)

Create run.py:

import uvicorn
uvicorn.run("app.main:app", host="127.0.0.1", port=8000, reload=True)

Run:

python run.py

📡 API Endpoints

Health Check

GET /

Fetch Ticker

GET /api/fetch/ticker?exchange=binance&symbol=BTC/USDT

Historical OHLCV

GET /api/historical?exchange=binance&symbol=BTC/USDT&timeframe=1m

List Exchanges

GET /api/exchanges

List Symbols

GET /api/symbols?exchange=binance

🔌 WebSocket Streaming

ws://127.0.0.1:8000/ws/ticker/binance/BTC/USDT

You will receive JSON updates at regular intervals.


🧪 Testing

Run:

pytest -q

Tests include:

  • API endpoint tests
  • Caching tests
  • WebSocket tests
  • Background broadcaster tests (mocked)