加密货币数据服务

一个基于FastMCP和CCXT的实时和历史加密货币市场数据服务,为AI代理和MCP兼容客户端提供数据支持。

  • by Chinmay48
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 Chinmay48/crypto-mcp-server

使用说明

🚀 加密MCP服务器

实时和历史加密货币数据MCP服务器(Python+FastMCP+CXT)

这个项目是 模型上下文协议(MCP) 提供以下功能的服务器 实时的 和 历史加密货币市场数据 对于AI代理,例如 克劳德桌面, MCP-CLI或任何MCP兼容客户端。

服务器是使用以下方式构建的:

  • FastMCP → 轻松创建MCP工具/插件
  • 仓储管理系统 → 来自主要交易所的可靠加密货币市场数据
  • 派丹蒂克 → 严格的数据验证
  • TTCache → 减少API负载的智能缓存
  • 紫外线 → 快速Python运行器
  • pytest → 单元测试

🧠 这个MCP服务器做什么?

此服务器公开了四个MCP工具:

1. realtime_price

获取 实时加密货币市场价格 来自任何支持CCXT的交换机。

2. historical_data

获取 OHLCV蜡烛历史 (打开-高-低-关闭-音量)。

3. supported_markets

列出交易所中所有可用的交易对。

4. health_check

返回服务器运行状况/状态。

这些工具允许Claude(或任何MCP客户端)实时执行真正的加密市场分析。


📸 演示截图


🏗️ 架构概述

main.py                     # MCP entrypoint
   |
   → src/server.py          # FastMCP server + tool definitions
           |
           ├── src/exchanges/ccxt_wrapper.py    # Crypto data fetch logic (CCXT)
           ├── src/schemas/market.py            # Pydantic response models
           └── tests/                           # Unit test suite (pytest)

🔄 数据流图

Claude Desktop
      |
      |  (MCP Tool Call)
      v
FastMCP Server (server.py)
      |
      | calls
      v
CCXT Wrapper (ccxt_wrapper.py)
      |
      | fetches
      v
Exchange APIs (Binance, Kraken, Coinbase, etc.)
      |
      | returns data
      v
FastMCP → Claude Desktop → User Display


📁 文件夹结构

crypto-mcp-server/
│
├── main.py
│
├── src/
│   ├── server.py                  # MCP tool definitions
│   ├── exchanges/
│   │   └── ccxt_wrapper.py        # CCXT integration + caching
│   ├── schemas/
│   │   └── market.py              # Pydantic response models
│
├── tests/
│   ├── test_realtime.py           # realtime_price tests
│   ├── test_historical.py         # historical_data tests
│
├── requirements.txt
└── README.md

🚀 使用的技术

技术 目的
FastMCP 公开MCP工具+管理服务器运行时
仓储管理系统 访问实时+历史加密数据
派丹蒂克 严格的模式验证
TTCache 缓存响应以提高性能
紫外线 高性能Python运行器
pytest 单元测试框架

⚙️ 安装和运行MCP服务器

1.️⃣ 克隆存储库

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

2.️⃣ 创建虚拟环境

python -m venv .venv

激活它:

.venv\Scripts\activate

3.️⃣ 再进行

紫外线:

uv sync

使用pip:

pip install -r requirements.txt


4.️⃣ 手动运行服务器(用于调试)

uv run main.py

在Claude Desktop中使用MCP服务器

uv run mcp install main.py

🔍 MCP工具(API)文档

下面是加密MCP服务器公开的所有可用MCP工具,以及Claude如何与它们交互的示例。


🟦 1.实时价格工具

工具名称: realtime_price
获取 实时市场价格 任何加密货币交易对。

参数

名称 类型 描述 示例
exchange string 从中获取数据的exchange "binance"
symbol string 交易对(基准/报价货币) "BTC/USDT"

返回示例

{
  "exchange": "binance",
  "symbol": "BTC/USDT",
  "price": 68000.2,
  "bid": 67995.1,
  "ask": 68005.4,
  "timestamp": 1731342335000
}

🟩 2.历史OHLCV工具

工具名称: historical_data
获取交易对的OHLCV蜡烛(开盘、高、低、收盘、成交量)。

参数

名称 类型 描述 示例
exchange string 要查询的exchange "binance"
symbol string 交易对 "BTC/USDT"
时间帧 字符串 CCXT时间帧(1米、5米、1小时…) "1h"
limit int 要获取的蜡烛数 10

示例提示

从币安获得10支1小时的BTC/USDT蜡烛。

返回格式

以数组列表的形式返回: [时间戳、打开、高、低、关闭、音量]

🟨 3.支持的市场工具

工具名称: supported_markets
返回加密货币交易所上可用的所有可交易市场(交易品种)。

示例提示

列出币安支持的所有市场。

返回示例

[
  "BTC/USDT",
  "ETH/USDT",
  "SOL/USDT",
  "XRP/USDT",
  
]