使用说明
MCP加密服务器
基于Python的MCP服务器,用于从主要交易所获取实时和历史加密货币市场数据(通过 ccxt).包括用于数据获取的MCP工具、用于错误处理和缓存的实用程序以及验证测试。
特性
- MCP工具,用于自动收报机、订单簿和历史OHLCV。
- 通过轮询订阅工具实时更新。
- 强大的错误处理和输入验证。
- 内存内TTL缓存,以减少API负载。
- 对确定性行为进行模拟测试。
设置
使用pip:
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
或者诗歌:
poetry install
poetry shell
运行MCP服务器
服务器注册了MCP兼容客户端可以发现的工具。
python -m mcp_crypto_server.mcp_server
工具
fetch_ticker(symbol: str, exchange: str = "binance")fetch_order_book(symbol: str, exchange: str = "binance", limit: int = 50)fetch_historical(symbol: str, exchange: str = "binance", timeframe: str = "1h", since: int | None = None, until: int | None = None, limit: int = 1000)subscribe_ticker(symbol: str, exchange: str = "binance", interval_seconds: int = 1, duration_seconds: int = 30)
测试
运行测试:
pytest -q
备注
- 历史时间窗口使用毫秒历元。如果
until结果在客户端进行过滤。 - 缓存TTL可以在中配置
config.py.