使用说明
CCXT MCP服务器
CCXT MCP Server是一个服务器,允许AI模型通过 模型上下文协议(MCP)。此服务器使用 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
安装和使用
全球安装
# 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服务器
-
打开克劳德桌面设置:
- 转到Claude Desktop应用程序中的“设置”菜单
- 查找“MCP服务器”部分
-
添加新的MCP服务器:
- 点击“添加服务器”按钮
- 服务器名称:
ccxt-mcp - 命令:
npx @lazydino/ccxt-mcp - 附加参数(可选):
--config /path/to/config.json
-
保存并测试服务器:
- 保存设置
- 使用“测试连接”按钮测试连接
配置方法-两种选项
选项1:直接在Claude桌面设置中包含帐户信息(基本方法)
此方法将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:使用单独的配置文件(高级方法)
要将帐户信息分离到单独的配置文件中,请按如下方式设置:
- 创建单独的配置文件 (例如。,
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),setmcpBearerToken在同一个配置文件中。客户端必须发送Authorization: Bearer <mcpBearerToken>根据要求。
- 在Claude桌面设置中指定配置文件路径:
{
"mcpServers": {
"ccxt-mcp": {
"command": "npx",
"args": [
"-y",
"@lazydino/ccxt-mcp",
"--config",
"/path/to/ccxt-config.json"
]
}
}
}
备注:使用单独的配置文件时
--config选项,服务器将查找accounts数组直接位于JSON文件的根目录中,而不是mcpServers.ccxt-mcp.accounts路径。
- 从命令行使用外部配置文件运行:
# Using custom configuration file
npx @lazydino/ccxt-mcp --config /path/to/ccxt-config.json
您可以在以下位置找到示例配置文件 config/ccxt-config.example.json 在存储库中。
使用单独配置文件的原因:
- 防止递归引用问题
- 分离敏感信息,如API密钥
- 更简单的多环境配置(开发、测试、生产)
- 改进了配置文件版本控制
主要特点
-
市场信息检索:
- 列出交易所
- 按交易所查看市场信息
- 获取特定商品的价格信息
- 查看特定符号的订单簿信息
- 搜索历史OHLCV数据
-
交易功能:
- 创建市价/限价订单
- 取消订单并检查状态
- 查看账户余额
- 查看交易历史记录
-
交易分析:
- 每日/每周/每月绩效分析
- 胜率计算(过去7天、30天、所有时间)
- 平均损益率(R倍数)
- 最大连续损益序列分析
- 资产变动跟踪
- 综合性能指标
- 贸易模式识别
- 基于周期的回报计算
-
职位管理:
- 资本比率交易(例如,输入账户资本的5%)
- 期货市场杠杆设置(1-100x)
- 动态头寸规模(基于波动性)
- 拆分买卖策略实施
-
风险管理:
- 基于技术指标的止损设置(例如,5分钟图表上10支蜡烛中的最低点)
- 基于波动性的止损/止盈(ATR倍数)
- 最大允许损失限额(日/周)
- 动态止盈设置(跟踪利润)
运作原理
User <--> AI Model(Claude/GPT) <--> MCP Protocol <--> CCXT MCP Server <--> Cryptocurrency Exchange API
- 用户:请求“告诉我比特币价格”或“在我的币安账户上购买以太坊”
- AI模型:了解用户请求并确定使用哪些MCP工具/资源
- MCP协议:AI和CCXT MCP服务器之间的标准化通信
- CCXT MCP服务器:使用CCXT库与加密货币交换API通信
- Exchange 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
笔记:
- 人工智能模型有时会将期货交易与现货交易混淆。
- 如果没有关于交易资本规模的明确指导,人工智能可能会感到困惑。
- 使用上述提示有助于清楚地传达您的交易意图。
基本查询示例
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 Compose构建和运行
- 创建配置文件:
cp config/ccxt-config.example.json config/ccxt-config.json
然后在中填写您真正的API密钥 config/ccxt-config.json.
还设置 mcpBearerToken 在同一个配置文件中。
2.塑造形象:
docker compose build
- 在后台启动MCP服务器(本地主机上的SSE模式:2298):
docker compose up -d
- 验证本地健康端点:
curl -H "Authorization: Bearer YOUR_MCP_TOKEN" http://127.0.0.1:2298/healthz
此Compose设置通过HTTP+SSE运行MCP(/sse + /messages)在本地主机上:2298用于反向代理。
远程MCP客户端配置
如果您的MCP客户端在另一台主机上运行,请在此计算机上使用Nginx反向代理。
- 复制
ccxt-mcp.nginx转到Nginx配置位置并更新证书路径:
sudo cp ccxt-mcp.nginx /etc/nginx/conf.d/ccxt-mcp.conf
- 编辑
/etc/nginx/conf.d/ccxt-mcp.conf并设置:
ssl_certificatessl_certificate_key- 授权标头转发(已包含在此文件中)
- 重新加载Nginx:
sudo nginx -t && sudo systemctl reload nginx
- 在MCP客户端中,将MCP服务器URL配置为TLS端点:
- SSE网址:
https://YOUR_HOSTNAME_OR_IP:42299/sse - 邮件URL:
https://YOUR_HOSTNAME_OR_IP:42299/messages - 头球
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是HTTPS2298来自CCXT在手机键盘上
如果您的MCP客户端接受基于命令的MCP服务器而不是URL配置,请配置 ccxt-mcp 与:
- 命令:
docker - Args:
[
"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.
🤝 贡献
欢迎投稿!请随时提交拉取请求。
📄 许可证
根据MIT许可证分发。有关更多信息,请参阅LICENSE文件。
❤️ 支持
如果你觉得这个项目有用,请考虑给它一个⭐️ 在GitHub上!