CCXT MCP Server

by doggybee
Verified
MIT License
127
4
  • Apple

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

Integrations

  • Provides access to market data, trading capabilities, and account information on Binance. Enables retrieving ticker information, order books, candlestick data, and placing market orders with proper API credentials.

  • Enables interaction with Coinbase exchange, allowing users to fetch market data, view order books, check account balances, and execute trades when configured with appropriate API keys.

  • Provides tools for accessing KuCoin exchange data and trading functionality, including market information, ticker data, order books, and trading capabilities when configured with API credentials.

CCXT MCP 服务器

使用 MCP(模型上下文协议)和 CCXT 实现高性能加密货币交换集成。

特征

  • 🚀交易所支持:连接 20 多个加密货币交易所
  • 🔃市场类型:支持现货、期货、掉期市场等
  • 🔧代理配置:通过代理访问交易所的选项
  • 📊快速可靠:优化缓存和速率限制
  • 🌐 MCP 标准:通过 MCP 与 Claude 和 GPT 等 LLM 兼容

CCXT MCP 服务器集成架构

CCXT MCP 服务器通过模型上下文协议 (MCP) 将语言模型连接到加密货币交易所。它充当桥梁,允许 LLM 通过统一的 API 访问实时市场数据并跨多个交易所执行交易操作。

该架构包括:

  • 发送请求的 LLM 客户端(Claude 和其他 MCP 兼容模型)
  • 标准化通信的模型上下文协议 (MCP)
  • 处理请求和管理交换交互的 CCXT MCP 服务器
  • CCXT 库提供对交易所 API 的统一访问
  • 连接到多个加密货币交易所

CCXT MCP 服务器代码架构

为了更好的可维护性和可扩展性,服务器分为三个主要模块:

  • Exchange :管理交换实例、凭证和符号验证
  • Utils :提供缓存、速率限制和日志记录功能
  • 工具:实现MCP工具和资源的交流互动

快速入门

通过 Smithery 安装

要通过Smithery自动为 Claude Desktop 安装 mcp-server-ccxt:

npx -y @smithery/cli install @doggybee/mcp-server-ccxt --client claude

NPM 包(推荐)

您可以从 npm 安装 CCXT MCP 服务器:

# Install globally npm install -g @mcpfun/mcp-server-ccxt # Start the server mcp-server-ccxt

或者直接运行:

npx @mcpfun/mcp-server-ccxt

手动安装

或者,您可以克隆并构建存储库:

# Clone the repository git clone https://github.com/doggybee/mcp-server-ccxt.git cd mcp-server-ccxt # Install dependencies npm install # Build the server npm run build # Start the server npm start

配置

  1. 创建环境文件
    cp .env.example .env
  2. 编辑.env文件以添加您的交换 API 密钥
    # Default exchange (optional) DEFAULT_EXCHANGE=binance # Default market type (optional) DEFAULT_MARKET_TYPE=spot # API credentials (optional) BINANCE_API_KEY=your_api_key BINANCE_SECRET=your_api_secret # Proxy configuration (optional) USE_PROXY=false PROXY_URL=http://username:password@your-proxy-server:port # Legacy format (still supported but recommended to use the integrated URL format above) # PROXY_USERNAME= # PROXY_PASSWORD=

用法

注意:如果您遇到任何 MCP 通信问题,请参阅故障排除指南以寻求解决方案。

运行服务器

启动服务器:

# If installed globally via npm mcp-server-ccxt # If installed manually npm start

与 Claude for Desktop 一起使用

  1. 将服务器添加到您的claude_desktop_config.json

如果通过 npm 安装(全局):

{ "mcpServers": { "ccxt": { "command": "mcp-server-ccxt" } } }

如果手动安装:

{ "mcpServers": { "ccxt": { "command": "node", "args": [ "/path/to/mcp-server-ccxt/build/index.js" ] } } }
  1. 重启 Claude 桌面版

在另一个项目中用作模块

您还可以将此包用作您自己的 Node.js 项目中的模块:

// Import the CCXT MCP Server import '@mcpfun/mcp-server-ccxt'; // The server starts automatically when imported // You can configure it through environment variables

示例查询

以下是一些可用于 MCP 服务器的示例查询:

  • “币安上比特币的当前价格是多少?”
  • “向我展示 Coinbase 上 ETH/USDT 的订单簿”
  • 获取币安平台 BTC/USDT 过去 24 根 K 线图的 1 小时 OHLCV 数据
  • “比较不同交易所的 SOL/USDT 价格”
  • “我目前在币安的余额是多少?”(需要 API 密钥)
  • “在 Kraken 上下达 0.1 ETH 的市场买入订单”(需要 API 密钥)

可用工具

公共 API 工具

  • list-exchanges :列出所有可用的加密货币交易所
  • get-ticker :获取交易对的当前股票代码信息
  • batch-get-tickers :一次获取多个交易对的股票代码信息
  • get-orderbook / get-order-book :获取交易对的市场订单簿
  • get-ohlcv :获取交易对的 OHLCV 烛台数据
  • get-trades :获取交易对的近期交易
  • get-markets :获取交易所所有可用的市场
  • get-exchange-info :获取交易所信息和状态
  • get-leverage-tiers :获取期货杠杆等级
  • get-funding-rates :获取当前融资利率
  • get-positions :获取未平仓头寸信息
  • get-open-orders :获取所有未结订单
  • get-order-history :获取订单历史记录

私有 API 工具(需要 API 密钥)

  • account-balance :从加密货币交易所获取您的账户余额
  • place-market-order :在交易所下达市价订单
  • place-limit-order :在交易所下限价订单
  • cancel-order :取消现有订单
  • cancel-all-orders :取消所有未结订单
  • set-leverage :设置期货杠杆
  • set-margin-mode :设置期货的保证金模式
  • place-futures-market-order :下达期货市场订单
  • place-futures-limit-order :下达期货限价订单
  • transfer-funds :账户之间转移资金(例如,现货到期货)

配置和实用工具

  • cache-stats :获取 CCXT 缓存统计信息
  • clear-cache :清除 CCXT 缓存
  • set-log-level :设置日志级别
  • get-proxy-config :获取代理设置
  • set-proxy-config :配置代理设置
  • set-market-type :设置默认市场类型
  • set-default-exchange :更改默认交换
  • system-info :获取系统和环境信息

性能优化

MCP-CCXT 包含多项优化以确保高性能:

  1. LRU缓存系统
    • 不同类型的数据有不同的TTL
    • 股票行情数据:10秒
    • 订单簿数据:5秒
    • 市场数据:1小时
  2. 自适应速率限制
    • 根据交易所响应自动调整请求率
    • 实现错误指数退避
    • 管理每个交易所的并发请求
  3. Exchange 连接管理
    • 高效初始化交易所实例
    • 正确的错误处理和重试

安全最佳实践

API 密钥安全

  1. 创建专用 API 密钥
    • 为不同的应用程序/目的创建单独的 API 密钥
    • 切勿在不同的服务或应用程序之间重复使用 API 密钥
  2. 限制 API 密钥权限
    • 仅启用您需要的权限(例如,市场数据只读)
    • 如果只需要交易功能,请禁用提款权限
    • 使用 IP 白名单(如果可用)来限制对已知 IP 的访问
  3. 安全存储
    • 切勿将 API 密钥提交到版本控制系统
    • 将 API 密钥存储在环境变量或安全保险库中
    • 使用通过.gitignore从 git 中排除的.env文件

风险免责声明

本软件仅供参考。使用此软件与加密货币交易所进行交互存在重大风险:

  • 财务风险:加密货币交易存在损失风险
  • API 安全:确保您的 API 密钥具有适当的权限限制
  • 无投资建议:此工具不提供投资建议
  • 无担保:该软件按“原样”提供,不提供任何形式的担保

执照

该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅LICENSE.txt文件。

版权和归属

该项目使用 CCXT 库( https://github.com/ccxt/ccxt ),它是:

Copyright (c) 2016-2024 CCXT developers

CCXT 根据 MIT 许可证发布,其中包括:

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

如有问题、功能请求或贡献,请访问GitHub 存储库

ID: zrx6mdpyxy