Skip to main content
Glama

CCXT MCP Server

by jcwleo

CCXT MCP 服务器

该项目提供了一个模型上下文协议 (MCP) 服务器,它将CCXT库中的各种功能公开为大型语言模型 (LLM) 的工具。

它允许 LLM 以标准化和异步的方式与加密货币交易所进行交互,执行获取余额、市场数据、创建订单等任务。

该服务器使用FastMCP构建,它简化了在 Python 中创建 MCP 服务器的过程。

特征

  • CCXT 集成:包装常见的 CCXT 功能以进行交换交互。
  • 异步:使用asyncioccxt.async_support构建,实现高效的非阻塞操作。
  • 清晰的工具定义:使用typing.Annotatedpydantic.Field进行清晰的参数描述和约束,使 LLM(和开发人员)更容易理解和使用这些工具。
  • 身份验证处理:支持私有端点的 API 密钥、秘密和密码身份验证。
  • 公共和私人工具:为公共市场数据和私人账户操作提供单独的工具。

安装

  1. 克隆存储库(如果还没有):
    git clone https://github.com/jcwleo/ccxt-mcp-server.git cd ccxt-mcp-server
  2. 创建并激活虚拟环境(推荐):
    python -m venv .venv source .venv/bin/activate # On Windows use `.venv\Scripts\activate`
  3. **安装依赖项:**所需的库列在requirements.txt中。您可以使用pipuv安装它们。
    • 使用pip
      pip install -r requirements.txt
    • 使用uv (如果已安装):
      uv pip install -r requirements.txt # Or, if you prefer uv's environment management: # uv sync

运行服务器

安装依赖项后,您可以直接运行 MCP 服务器:

uv run mcp_server.py

您应该看到表明服务器已启动的输出,类似于:

Starting CCXT MCP Server (Async with Annotated Params and Tool Metadata)... # ... (FastMCP server startup logs)

然后,MCP 客户端就可以连接该服务器了(通常在 FastMCP 管理的默认端口上,除非另有配置)。

MCP 服务器配置(适用于 MCP 客户端)

如果您正在使用需要手动服务器配置的 MCP 客户端(如 Claude 桌面应用程序),则需要提供类似于以下 JSON 的配置。

创建一个claude_desktop_config.json文件(或 MCP 客户端的等效文件),其结构如下:

{ "mcpServers": { "ccxt-mcp-server": { "command": "uv", "args": [ "--directory", "/path/to/your/ccxt-mcp-server", "run", "mcp_server.py" ] } } }

重要的:

  • "/path/to/your/ccxt-mcp-server"替换为您克隆或下载此ccxt-mcp-server项目的目录的实际绝对路径(即包含mcp_server.py的目录)。
  • "command""args"取决于你如何运行 Python 项目,以及你使用的是uv还是虚拟环境。上面的示例使用的是uv
    • 如果您直接使用python虚拟环境,则命令可能如下所示:
      { "mcpServers": { "ccxt-mcp-server": { "command": "/path/to/your/.venv/bin/python", // Or `python.exe` on Windows "args": [ "mcp_server.py" ], "workingDirectory": "/path/to/your/ccxt-mcp-server" } } }
      确保command指向虚拟环境中的 Python 可执行文件,并且workingDirectory设置为项目的根目录。

此配置告诉您的 MCP 客户端如何启动并与 CCXT MCP 服务器通信。

可用的 MCP 工具

该服务器公开以下工具,按是否需要 API 身份验证进行分类。

需要 API 身份验证的工具(私有)

  • fetch_account_balance :获取当前账户余额。
  • fetch_deposit_address :获取货币的存款地址。
  • withdraw_cryptocurrency :将加密货币提取到指定地址。
  • fetch_open_positions :获取未平仓头寸(主要用于期货/衍生品)。
  • set_trading_leverage :设置交易符号的杠杆(主要用于期货)。
  • create_spot_limit_order :下达新的现货限价订单。
  • create_spot_market_order :下达新的现货市场订单。
  • create_futures_limit_order :下达新的期货限价订单。
  • create_futures_market_order :下达新的期货市场订单。
  • cancel_order :取消现有的未结订单。
  • fetch_order_history :获取订单历史记录(开仓/平仓)。
  • fetch_my_trade_history :获取用户执行的交易的历史记录。

公共数据工具(无需身份验证)

  • fetch_ohlcv :获取历史 OHLCV(烛台)数据。
  • fetch_funding_rate :获取永续期货合约的资金利率。
  • fetch_long_short_ratio :获取多头/空头比率(需要交易所特定的params )。
  • fetch_option_contract_data :获取期权合约的市场数据。
  • fetch_market_ticker :获取某个符号的最新价格行情数据。
  • fetch_public_market_trades :获取某个符号的近期公开交易。

由于使用了Annotatedpydantic.Field ,每个工具都具有通过 MCP 协议本身提供的详细参数描述。

使用说明

  • 期货/期权:当使用与期货或期权相关的工具(例如, fetch_open_positionscreate_futures_limit_orderfetch_funding_rate )时,请确保通过params参数正确配置 CCXT 客户端,特别是如果交易所需要或不默认为所需的市场类型,则传递{'options': {'defaultType': 'future'}} (或'swap''option' )。
  • fetch_long_short_ratio :这不是 CCXT 统一的标准方法。您必须params参数中提供具体的交易所方法名称及其参数(例如,对于币安合约, params={'method_name': 'fapiPublicGetGlobalLongShortAccountRatio', 'method_params': {'symbol': 'BTCUSDT', 'period': '5m'}} )。
  • 错误处理:如果在 CCXT 调用期间出现问题,工具将返回带有"error"键的字典。
-
security - not tested
A
license - permissive license
-
quality - not tested

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.

模型上下文协议服务器使 LLM 能够通过 CCXT 与加密货币交易所进行交互,从而允许以标准化的方式执行获取余额、市场数据、创建订单和交易操作等任务。

  1. 特征
    1. 安装
      1. 运行服务器
        1. MCP 服务器配置(适用于 MCP 客户端)
          1. 可用的 MCP 工具
            1. 需要 API 身份验证的工具(私有)
            2. 公共数据工具(无需身份验证)
          2. 使用说明

            Related MCP Servers

            • A
              security
              A
              license
              A
              quality
              A Model Context Protocol server that gives LLMs the ability to interact with Ethereum networks, manage wallets, query blockchain data, and execute smart contract operations through a standardized interface.
              Last updated -
              31
              323
              2
              TypeScript
              MIT License
            • -
              security
              F
              license
              -
              quality
              A Model Context Protocol server that enables LLMs to access Binance Smart Chain data, perform blockchain queries, and create Four.meme tokens.
              Last updated -
              TypeScript
              • Linux
              • Apple
            • -
              security
              A
              license
              -
              quality
              A Model Context Protocol server that enables LLMs like Claude to interact with the Alpaca trading API, allowing for trading stocks, checking positions, fetching market data, and managing accounts through natural language.
              Last updated -
              Python
              MIT License
            • -
              security
              A
              license
              -
              quality
              A Model Context Protocol server that exposes Binance cryptocurrency exchange data to LLMs, allowing agents to access real-time prices, order books, and historical market data without requiring API keys.
              Last updated -
              10
              Python
              MIT License

            View all related MCP servers

            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/jcwleo/ccxt-mcp-server'

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