CoinGecko Server

CoinGecko Server

site icon
2024.12.31 5
JavaScript加密货币数据服务金融数据分析金融服务
mcp-coingecko-server 是一个基于 Model Context Protocol (MCP) 的服务,专门用于与 CoinGecko Pro API 进行交互。它提供了加密货币数据的查询功能,包括支持的分页加密货币列表、通过名称或符号查找 Coin ID、历史价格、市值和交易量数据、OHLC(开盘价、最高价、最低价、收盘价)蜡烛图数据以及本地硬币缓存刷新功能。
View on GitHub

Overview

基本能力

产品定位

mcp-coingecko-server 是一个专门用于加密货币数据查询和分析的服务,旨在为开发者和数据分析师提供便捷的加密货币市场数据访问接口。

核心功能

  • 分页列出支持的加密货币
  • 通过名称或符号查找 Coin ID
  • 获取历史价格、市值和交易量数据
  • 获取 OHLC 蜡烛图数据
  • 本地硬币缓存刷新功能

适用场景

  • 加密货币市场分析
  • 投资决策支持
  • 金融数据可视化
  • 自动化交易系统

工具列表

  • get-coins: 获取支持的分页硬币列表
  • find-coin-ids: 通过名称/符号查找 CoinGecko IDs
  • get-historical-data: 获取历史价格、市值和交易量数据
  • get-ohlc-data: 获取 OHLC 蜡烛图数据
  • refresh-cache: 刷新本地硬币列表缓存

常见问题解答

使用教程

使用依赖

  1. 安装 Node.js 环境
  2. 获取 CoinGecko Pro API 密钥

安装教程

npm install coingecko-server

环境设置

在项目根目录创建 .env 文件:

COINGECKO_API_KEY=your_api_key_here

调试方式

  1. 确保 API 密钥正确设置
  2. 使用提供的工具函数进行测试调用
  3. 检查返回数据是否符合预期

与 Claude Desktop 集成

  1. 安装 Claude Desktop
  2. 添加配置到 Claude Desktop 配置文件
  3. 重启 Claude Desktop

与 OpenAI 函数调用集成

import { CoinGeckoService } from 'coingecko-server';
import OpenAI from 'openai';

const openai = new OpenAI();
const coinGeckoService = new CoinGeckoService(process.env.COINGECKO_API_KEY);

// 获取函数定义
const functions = CoinGeckoService.getOpenAIFunctionDefinitions();

// 示例:获取历史数据
const response = await openai.chat.completions.create({
  model: "gpt-4-turbo-preview",
  messages: [{ role: "user", content: "Get Bitcoin's price history for the last week" }],
  functions: [functions[2]], // get_historical_data function
  function_call: "auto",
});

if (response.choices[0].message.function_call) {
  const args = JSON.parse(response.choices[0].message.function_call.arguments);
  const history = await coinGeckoService.getHistoricalData(
    args.id,
    args.vs_currency,
    args.from,
    args.to,
    args.interval
  );
}

许可证

该项目遵循 MIT 开源许可条款,请参阅 MIT 了解完整条款。