Skip to main content
Glama

CCXT MCP 服务器

npm version npm downloads GitHub stars License: MIT

한국어 버전(Korean version)

CCXT MCP 服务器是一个允许 AI 模型通过 模型上下文协议 (MCP) 与加密货币交易所 API 进行交互的服务器。该服务器使用 CCXT 库 提供对 100 多家加密货币交易所及其交易功能的访问。

🚀 快速开始

# Install the package globally
npm install -g @lazydino/ccxt-mcp

# Run with default settings
ccxt-mcp

# or run without installation
npx @lazydino/ccxt-mcp

Related MCP server: EVM MCP Server

安装与使用

全局安装

# Install the package globally
npm install -g @lazydino/ccxt-mcp

使用 npx 运行

您可以直接运行它而无需安装:

# Using default settings
npx @lazydino/ccxt-mcp

# Using custom configuration file
npx @lazydino/ccxt-mcp --config /path/to/config.json

查看帮助:

npx @lazydino/ccxt-mcp --help

配置

在 Claude Desktop 中注册 MCP 服务器

  1. 打开 Claude Desktop 设置

    • 进入 Claude Desktop 应用的设置菜单

    • 找到“MCP Servers”部分

  2. 添加新的 MCP 服务器

    • 点击“Add Server”按钮

    • 服务器名称:ccxt-mcp

    • 命令:npx @lazydino/ccxt-mcp

    • 附加参数(可选):--config /path/to/config.json

  3. 保存并测试服务器

    • 保存设置

    • 使用“Test Connection”按钮测试连接

配置方法 - 两种选项

选项 1:直接在 Claude Desktop 设置中包含账户信息(基础方法)

此方法将 CCXT 账户信息直接包含在 Claude Desktop 配置文件 (claude_desktop_config.json) 中:

{
  "mcpServers": {
    "ccxt-mcp": {
      "command": "npx",
      "args": ["-y", "@lazydino/ccxt-mcp"],
      "mcpBearerToken": "YOUR_MCP_TOKEN",
      "accounts": [
        {
          "name": "bybit_main",
          "exchangeId": "bybit",
          "apiKey": "YOUR_API_KEY",
          "secret": "YOUR_SECRET_KEY",
          "defaultType": "spot"
        },
        {
          "name": "bybit_futures",
          "exchangeId": "bybit",
          "apiKey": "YOUR_API_KEY",
          "secret": "YOUR_SECRET_KEY",
          "defaultType": "swap"
        }
      ]
    }
  }
}

使用此方法,您不需要单独的配置文件。所有设置都集成在 Claude Desktop 配置文件中。

选项 2:使用单独的配置文件(高级方法)

要将账户信息分离到单独的配置文件中,请按如下方式设置:

  1. 创建单独的配置文件(例如 ccxt-config.json):

{
  "mcpBearerToken": "YOUR_MCP_TOKEN",
  "accounts": [
    {
      "name": "bybit_main",
      "exchangeId": "bybit",
      "apiKey": "YOUR_API_KEY",
      "secret": "YOUR_SECRET_KEY",
      "defaultType": "spot"
    },
    {
      "name": "bybit_futures",
      "exchangeId": "bybit",
      "apiKey": "YOUR_API_KEY",
      "secret": "YOUR_SECRET_KEY",
      "defaultType": "swap"
    }
  ]
}

重要:配置文件必须在根级别包含一个 accounts 数组,如上所示。

重要:如果您以 HTTP+SSE 模式 (--sse) 运行服务器,请在同一个配置文件中设置 mcpBearerToken。客户端在请求时必须发送 Authorization: Bearer <mcpBearerToken>

  1. 在 Claude Desktop 设置中指定配置文件路径

{
  "mcpServers": {
    "ccxt-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "@lazydino/ccxt-mcp",
        "--config",
        "/path/to/ccxt-config.json"
      ]
    }
  }
}

注意:当使用带有 --config 选项的单独配置文件时,服务器将直接在 JSON 文件的根目录中查找 accounts 数组,而不是在 mcpServers.ccxt-mcp.accounts 路径中查找。

  1. 从命令行运行外部配置文件

# Using custom configuration file
npx @lazydino/ccxt-mcp --config /path/to/ccxt-config.json

您可以在存储库的 config/ccxt-config.example.json 中找到示例配置文件。

使用单独配置文件的原因

  • 防止递归引用问题

  • 分离 API 密钥等敏感信息

  • 更易于多环境配置(开发、测试、生产)

  • 改进了配置文件的版本控制

主要功能

  • 市场信息检索

    • 列出交易所

    • 按交易所查看市场信息

    • 获取特定交易对的价格信息

    • 查看特定交易对的订单簿信息

    • 搜索历史 OHLCV 数据

  • 交易功能

    • 创建市价/限价订单

    • 取消订单并检查状态

    • 查看账户余额

    • 检查交易历史

  • 交易分析

    • 日/周/月绩效分析

    • 胜率计算(过去 7 天、30 天、所有时间)

    • 平均盈亏比 (R-multiple)

    • 最大连续亏损/盈利序列分析

    • 资产变动跟踪

    • 综合绩效指标

    • 交易模式识别

    • 基于周期的收益计算

  • 仓位管理

    • 资本比例交易(例如,以账户资本的 5% 进入)

    • 合约市场杠杆设置 (1-100x)

    • 动态仓位调整(基于波动率)

    • 分批买入/卖出策略实施

  • 风险管理

    • 基于技术指标的止损设置(例如,5 分钟图上 10 根 K 线中的最低点)

    • 基于波动率的止损/止盈 (ATR 倍数)

    • 最大允许亏损限制(日/周)

    • 动态止盈设置(追踪止盈)

工作原理

User <--> AI Model(Claude/GPT) <--> MCP Protocol <--> CCXT MCP Server <--> Cryptocurrency Exchange API
  1. 用户:发出如“告诉我比特币价格”或“在我的币安账户上买入以太坊”的请求

  2. AI 模型:理解用户请求并确定使用哪些 MCP 工具/资源

  3. MCP 协议:AI 与 CCXT MCP 服务器之间的标准化通信

  4. CCXT MCP 服务器:使用 CCXT 库与加密货币交易所 API 进行通信

  5. 交易所 API:提供实际数据并执行交易订单

与 AI 模型配合使用

在 Claude Desktop 中注册后,您可以向 AI 模型发出以下类型的请求:

注意事项和推荐提示词

使用 AI 模型时,请考虑以下注意事项,并使用下面的提示词进行有效交易:

Your goal is to execute trades using the ccxt tools as much as possible
Cautions:
- Accurately identify whether it's a futures market or spot market before proceeding with trades
- If there's no instruction about percentage of capital or amount to use, always calculate and execute trades using the entire available capital

注意:

  • AI 模型有时会混淆合约交易和现货交易。

  • 如果没有关于交易资本规模的明确指导,AI 可能会感到困惑。

  • 使用上述提示词有助于清晰地传达您的交易意图。

基础查询示例

Check and compare the current Bitcoin price on binance and coinbase.

高级交易查询示例

仓位管理

Open a long position on BTC/USDT futures market in my Bybit account (bybit_futures) with 5% of capital using 10x leverage.
Enter based on moving average crossover strategy and set stop loss at the lowest point among the 12 most recent 5-minute candles.

绩效分析

Analyze my Binance account (bybit_main) trading records for the last 7 days and show me the win rate, average profit, and maximum consecutive losses.

详细交易分析

Analyze my trading performance on the bybit_futures account for BTC/USDT over the last 30 days. Calculate win rate, profit factor, and identify any patterns in my winning trades.
Show me the monthly returns for my bybit_main account over the past 90 days and identify my best and worst trading months.
Analyze my consecutive wins and losses on my bybit_futures account and tell me if I have any psychological patterns affecting my trading after losses.

开发

从源码构建

# Clone repository
git clone https://github.com/lazy-dinosaur/ccxt-mcp.git

# Navigate to project directory
cd ccxt-mcp

# Install dependencies
npm install

# Build
npm run build

Docker

使用 Docker Compose 构建并运行

  1. 创建配置文件:

cp config/ccxt-config.example.json config/ccxt-config.json

然后在 config/ccxt-config.json 中填入您的真实 API 密钥。 同时在同一个配置文件中设置 mcpBearerToken。 2. 构建镜像:

docker compose build
  1. 在后台启动 MCP 服务器(localhost:2298 上的 SSE 模式):

docker compose up -d
  1. 验证本地健康检查端点:

curl -H "Authorization: Bearer YOUR_MCP_TOKEN" http://127.0.0.1:2298/healthz

此 Compose 设置在 localhost:2298 上通过 HTTP+SSE (/sse + /messages) 运行 MCP,用于反向代理。

远程 MCP 客户端配置

如果您的 MCP 客户端在另一台主机上运行,请在该机器上使用 Nginx 反向代理。

  1. ccxt-mcp.nginx 复制到您的 Nginx 配置位置并更新证书路径:

sudo cp ccxt-mcp.nginx /etc/nginx/conf.d/ccxt-mcp.conf
  1. 编辑 /etc/nginx/conf.d/ccxt-mcp.conf 并设置:

  • ssl_certificate

  • ssl_certificate_key

  • 授权头转发(此文件中已包含)

  1. 重载 Nginx:

sudo nginx -t && sudo systemctl reload nginx
  1. 在您的 MCP 客户端中,将 MCP 服务器 URL 配置为您的 TLS 端点:

  • SSE URL: https://YOUR_HOSTNAME_OR_IP:42299/sse

  • Messages URL: https://YOUR_HOSTNAME_OR_IP:42299/messages

  • Header: Authorization: Bearer YOUR_MCP_TOKEN

您可以使用以下命令生成强令牌:

openssl rand -hex 32

配置示例:

{
  "mcpBearerToken": "YOUR_MCP_TOKEN",
  "accounts": [
    {
      "name": "bybit_main",
      "exchangeId": "bybit",
      "apiKey": "YOUR_API_KEY",
      "secret": "YOUR_SECRET_KEY"
    }
  ]
}

端口说明:

  • 42298 是 HTTP(仅重定向)

  • 42299 是 HTTPS

  • 2298 来自手机键盘上的 CCXT

如果您的 MCP 客户端接受基于命令的 MCP 服务器而不是 URL 配置,请使用以下配置 ccxt-mcp

  • 命令:docker

  • 参数:

[
  "run",
  "--rm",
  "-i",
  "-p",
  "127.0.0.1:2298:2298",
  "-v",
  "/absolute/path/to/ccxt-mcp/config/ccxt-config.json:/config/ccxt-config.json:ro",
  "ccxt-mcp:local",
  "--sse",
  "--host",
  "0.0.0.0",
  "--port",
  "2298",
  "--config",
  "/config/ccxt-config.json"
]

首先使用 docker compose build 构建镜像。

🤝 贡献

欢迎贡献!请随时提交 Pull Request。

📄 许可证

根据 MIT 许可证分发。有关更多信息,请参阅 LICENSE 文件。

❤️ 支持

如果您觉得这个项目有用,请考虑在 GitHub 上给它一个 ⭐️!

Install Server
A
license - permissive license
B
quality
C
maintenance

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/lazy-dinosaur/ccxt-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server