使用说明
加密货币市场数据MCP服务器
Python MCP服务器,用于使用CCXT从多个交易所检索实时和历史加密货币市场数据。
特性
- 6个MCP工具:实时价格、历史数据、订单簿、交易、价格比较和市场摘要
- 多交换支持:币安、Coinbase、海怪、Bitfinex
- 缓存:60秒TTL缓存,以减少API调用
- 错误处理:具有指数回退的自动重试逻辑
- 综合测试:33次测试,覆盖率66%
安装
git clone https://github.com/808JACK/Crypto-Mcp-Server.git
cd Crypto-Mcp-Server
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
用法
启动服务器
python -m src.server
示例
from src.server import CryptoMCPServer
import asyncio
async def main():
server = CryptoMCPServer()
# Get BTC price
ticker = await server._get_ticker('binance', 'BTC/USDT')
print(f"BTC: ${ticker['last']:,.2f}")
# Get historical data
ohlcv = await server._get_ohlcv('binance', 'BTC/USDT', '1d', 7)
print(f"Retrieved {ohlcv['count']} candles")
asyncio.run(main())
测试
# Run all tests
pytest tests/ -v
# Run specific tests
pytest tests/test_cache.py -v
pytest tests/test_utils.py -v
pytest tests/test_server_comprehensive.py -v
# Test with real data
pytest tests/test_live_data.py -v -s
# Coverage report
pytest tests/ --cov=src --cov-report=html
MCP工具
- get_ticker -实时价格、买入价、卖出价、交易量
- get_ohlcv -具有多个时间段的历史OHLCV数据
- 获取订单_预订 -实时订单簿
- get_trades -最近的贸易历史
- 比较价格 -比较各交易所的价格
- get_market_summary -完整的市场概述
项目结构
crypto-mcp-server/
├── src/
│ ├── server.py # MCP server
│ ├── cache.py # Caching
│ └── utils.py # Utilities
├── tests/
│ ├── test_server_comprehensive.py
│ ├── test_cache.py
│ ├── test_utils.py
│ └── test_live_data.py
├── examples/
│ └── example_usage.py
└── requirements.txt
依赖项
- mcp-模型上下文协议SDK
- ccxt-加密货币交换库
- cachetools-缓存实用程序
- pytest-测试框架
许可证
麻省理工学院