coin-mcp-server

coin-mcp-server

Okay, here's a breakdown of how to use Bitget's API to get cryptocurrency information, along with considerations and a basic example. I'll provide both the English explanation and the Chinese translation. **English Explanation** **1. Understanding the Bitget API:** * **REST API:** Bitget primarily uses a RESTful API. This means you'll be making HTTP requests (GET, POST, etc.) to specific URLs (endpoints) to retrieve data or perform actions. * **Authentication:** Some endpoints (especially those dealing with your account or trading) require authentication. This involves using API keys (a public key and a secret key) that you generate on the Bitget platform. Keep your secret key *very* safe. * **Rate Limits:** Bitget, like most exchanges, has rate limits. This restricts the number of requests you can make within a certain time period. Exceeding these limits will result in your requests being temporarily blocked. Check the Bitget API documentation for the specific rate limits. * **Documentation:** The *most important* resource is the official Bitget API documentation. Find it on the Bitget website (usually under "API" or "Developer" sections). The documentation will list all available endpoints, required parameters, response formats, and authentication details. **Always refer to the official documentation first.** **2. Basic Steps:** 1. **Get API Keys (if needed):** If you need to access private data (like your account balance or place orders), create API keys on the Bitget website. Enable the necessary permissions (e.g., "Read," "Trade"). 2. **Choose an Endpoint:** Decide what information you want. Examples: * **Market Data:** Get the current price of Bitcoin (BTC), trading volume, order book, etc. * **Account Information:** Get your account balance, order history, etc. (requires authentication). * **Trading:** Place buy/sell orders (requires authentication). 3. **Construct the Request:** Build the HTTP request to the correct endpoint, including any required parameters. This often involves creating a URL with query parameters. 4. **Send the Request:** Use a programming language (Python, JavaScript, etc.) and an HTTP client library (e.g., `requests` in Python, `axios` in JavaScript) to send the request to the Bitget API. 5. **Parse the Response:** The Bitget API will return a response, usually in JSON format. Parse the JSON to extract the data you need. 6. **Handle Errors:** Check the HTTP status code and the response body for any errors. Implement error handling in your code. **3. Example (Python using `requests` - Market Data - Public Endpoint):** ```python import requests import json # Replace with the actual Bitget API endpoint for ticker information (e.g., BTCUSDT) api_url = "https://api.bitget.com/api/spot/v1/ticker/BTCUSDT_SPBL" #Example endpoint, check documentation try: response = requests.get(api_url) response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx) data = response.json() print(json.dumps(data, indent=4)) # Pretty print the JSON # Example: Extract the last price last_price = data['data']['close'] print(f"Last price of BTCUSDT: {last_price}") except requests.exceptions.RequestException as e: print(f"Error: {e}") except (KeyError, TypeError) as e: print(f"Error parsing JSON: {e}") ``` **Important Notes:** * **Security:** Never hardcode your secret API key directly into your code. Use environment variables or a secure configuration file. * **Error Handling:** Implement robust error handling to catch network errors, API errors, and JSON parsing errors. * **API Versioning:** Bitget may update its API. Pay attention to the API version in the endpoint URL (e.g., `/api/v1/`, `/api/v2/`) and update your code accordingly when necessary. * **Testing:** Thoroughly test your code in a test environment (if Bitget provides one) before using it with real funds. * **Legal:** Be aware of any legal or regulatory requirements related to using cryptocurrency exchange APIs in your jurisdiction. **Chinese Translation** **1. 理解 Bitget API:** * **REST API:** Bitget 主要使用 RESTful API。 这意味着您将向特定的 URL(端点)发出 HTTP 请求(GET、POST 等)以检索数据或执行操作。 * **身份验证:** 某些端点(尤其是处理您的帐户或交易的端点)需要身份验证。 这涉及使用您在 Bitget 平台上生成的 API 密钥(公钥和私钥)。 请 *非常* 安全地保管您的私钥。 * **速率限制:** 像大多数交易所一样,Bitget 具有速率限制。 这限制了您在特定时间段内可以发出的请求数量。 超过这些限制将导致您的请求被暂时阻止。 请查看 Bitget API 文档以获取具体的速率限制。 * **文档:** *最重要* 的资源是官方 Bitget API 文档。 在 Bitget 网站上找到它(通常在“API”或“开发者”部分下)。 该文档将列出所有可用的端点、必需的参数、响应格式和身份验证详细信息。 **始终首先参考官方文档。** **2. 基本步骤:** 1. **获取 API 密钥(如果需要):** 如果您需要访问私有数据(例如您的帐户余额或下订单),请在 Bitget 网站上创建 API 密钥。 启用必要的权限(例如,“读取”、“交易”)。 2. **选择一个端点:** 确定您想要的信息。 例子: * **市场数据:** 获取比特币 (BTC) 的当前价格、交易量、订单簿等。 * **帐户信息:** 获取您的帐户余额、订单历史记录等(需要身份验证)。 * **交易:** 下买入/卖出订单(需要身份验证)。 3. **构建请求:** 构建到正确端点的 HTTP 请求,包括任何必需的参数。 这通常涉及创建带有查询参数的 URL。 4. **发送请求:** 使用编程语言(Python、JavaScript 等)和 HTTP 客户端库(例如 Python 中的 `requests`,JavaScript 中的 `axios`)将请求发送到 Bitget API。 5. **解析响应:** Bitget API 将返回一个响应,通常为 JSON 格式。 解析 JSON 以提取您需要的数据。 6. **处理错误:** 检查 HTTP 状态代码和响应正文是否有任何错误。 在您的代码中实现错误处理。 **3. 示例(Python 使用 `requests` - 市场数据 - 公共端点):** ```python import requests import json # 替换为实际的 Bitget API 端点以获取行情信息(例如,BTCUSDT) api_url = "https://api.bitget.com/api/spot/v1/ticker/BTCUSDT_SPBL" #示例端点,请查阅文档 try: response = requests.get(api_url) response.raise_for_status() # 为错误的状态代码(4xx 或 5xx)引发异常 data = response.json() print(json.dumps(data, indent=4)) # 漂亮地打印 JSON # 示例:提取最新价格 last_price = data['data']['close'] print(f"BTCUSDT 的最新价格:{last_price}") except requests.exceptions.RequestException as e: print(f"错误:{e}") except (KeyError, TypeError) as e: print(f"解析 JSON 时出错:{e}") ``` **重要提示:** * **安全:** 永远不要将您的秘密 API 密钥直接硬编码到您的代码中。 使用环境变量或安全配置文件。 * **错误处理:** 实现强大的错误处理以捕获网络错误、API 错误和 JSON 解析错误。 * **API 版本控制:** Bitget 可能会更新其 API。 注意端点 URL 中的 API 版本(例如,`/api/v1/`、`/api/v2/`),并在必要时相应地更新您的代码。 * **测试:** 在将您的代码用于真实资金之前,请在测试环境中彻底测试您的代码(如果 Bitget 提供)。 * **法律:** 请注意您所在司法管辖区与使用加密货币交易所 API 相关的任何法律或监管要求。 **Key Takeaways:** * **Read the Documentation:** The Bitget API documentation is your bible. * **Start Simple:** Begin with public endpoints (no authentication required) to get familiar with the API. * **Handle Errors:** Robust error handling is crucial. * **Security First:** Protect your API keys. I hope this comprehensive explanation and example are helpful! Remember to consult the official Bitget API documentation for the most up-to-date information. Good luck!

Category
访问服务器

README

Coin MCP Server 🚀💰

欢迎来到 Coin MCP Server – 您获取最新加密货币价格的一站式商店,速度之快,让您来不及说“冲向月球!”🌙 这个小服务器使用 FastMCP 构建,并用 zod 进行验证,像一个值得信赖的加密货币管家一样,从 Bitget 的 API 获取代币价格。🧑‍💼

中文文档 | English


它的作用是什么? 🤔

该项目启动一个服务器,允许您使用 Bitget 的 API 查询任何加密货币(与 USDT 配对)的当前价格。想知道您最喜欢的代币现在的价值吗?只需提问,价格就是您的了!💸

  • 工具: getTokenPrice

  • 任务: 获取代币的最新价格(例如,BGBBTCETH)。

  • 超能力: 它速度快、简单,并且由 FastMCP 提供支持!⚡

  • 工具: getAnnoucements

  • 任务: 获取公告

  • 工具: getCoinInfo

  • 任务: 获取指定代币的详细信息。

  • 超能力: 提供详细信息,例如代币的可转移性、支持的链列表、链网络状态等。


特点 🌟

  • 🎯 极其简单的 API: 传递一个代币符号,获取一个价格。没有大惊小怪,没有混乱。
  • 🛡️ Zod 验证: 参数检查比金库门还要严格。
  • 📡 Bitget 集成: 直接从 Bitget 的市场行情 API 中提取实时数据。
  • 🧠 错误处理: 像专业人士一样捕捉小故障,并将它们记录下来供您稍后嘲笑。

快速开始 🏁

准备好投入加密货币价格池了吗?以下是如何让这个宝贝运行起来:

前提条件

  • Deno: 您需要安装 Deno,因为我们很时髦和现代。从这里获取它。
  • Bitget API 访问: 不需要 API 密钥 – 我们像冠军一样访问公共端点!但是,如果您有自定义的 BGURL,请将其设置为环境变量。

安装

  1. 克隆这个 repo,就像它很热门一样:
    git clone https://github.com/pwh-pwh/coin-mcp-server.git
    cd coin-mcp-server
    
  2. 安装依赖项(Deno 通过导入自动处理此问题!)。

运行服务器

使用以下命令启动它:

deno run --allow-net --allow-env --allow-read main.ts

或者

deno run --allow-net --allow-env --allow-read https://deno.land/x/coin_mcp_server/main.ts
  • --allow-net: 允许我们与 Bitget 的 API 通信。
  • --allow-env: 如果您已设置,则获取您的 BGURL 环境变量。

服务器将以 stdio 模式启动,准备好像加密货币自动售货机一样提供价格!🍔


配置

config.json

{
  "mcpServers": {
    "coin-mcp": {
      "command": "deno",
      "args": [
        "run",
        "--allow-net",
        "--allow-read",
        "--allow-env",
        "https://deno.land/x/coin_mcp_server/main.ts"
      ]
    }
  }
}

使用示例 🎮

以下是如何调用 getTokenPrice

{
  "tool": "getTokenPrice",
  "parameters": {
    "token": "BGB"
  }
}

响应:

"42.069"  // 最新的 BGB/USDT 价格(不是真实价格,只是感觉!)

如果代币不存在或 API 出现问题,它会抛出一个错误,并附带一个厚脸皮的日志,提醒您它已经尽力了。😅


代码抢先看 👀

这是幕后的魔法:

  • FastMCP: 使用一个很酷的名称和版本启动服务器。
  • Zod: 检查您的 token 参数。
  • Bitget API: 从 https://api.bitget.com/api/v2/spot/market/tickers 获取行情数据。

getBitgetPrice 函数是 MVP,从响应中获取甜蜜的 lastPr(最新价格)。检查日志以获取价格更新或错误喜剧黄金!😂


环境变量 🌍

  • BGURL: 自定义 Bitget API 基本 URL(如果未设置,则默认为 https://api.bitget.com)。像这样设置它:
    export BGURL="https://your-custom-bitget-url.com"
    

故障排除 🛠️

  • “HTTP error! status: 404”: 仔细检查您的代币符号。BGBUSDTBGB 不同!
  • “Network error”: 确保您已连接互联网并具有 Deno 的 --allow-net 标志。
  • 仍然卡住?: 向虚空大喊(或打开一个 issue)。我们将一起解决它!🙌

为什么存在 🎉

因为谁不想实时知道他们的加密货币藏匿处的价格?无论您是交易者、HODLer 还是只是对加密货币感到好奇,此服务器都会为您提供支持。此外,这也是展示一些 Deno 技能和使用 API 的一种有趣方式。😎


贡献 🤝

有想法吗?发现了一个 bug?想要添加像月相价格预测这样的功能吗?Fork 它,调整它,PR 它!让我们使其成为银河系中最酷的 MCP 服务器。🌌


许可证 📜

MIT – 随心所欲地使用它,只是如果您的代币上涨或下跌,请不要怪我!🌑📉


祝您加密货币狩猎愉快,并祝您的包永远是绿色的!💚

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选