Back to MCP directory
publicPublicdnsLocal runtime

kydlikebtc_mcp-server-bn

MCP Server提供币安现货交易接口,支持API密钥管理、订单创建/取消、余额查询等功能

article

README

🚀 mcp-server-cex-bn

该MCP服务器为币安(Binance)现货交易操作提供了强大的接口,能帮助用户安全、便捷地进行交易操作,如配置API凭证、执行订单、监控余额等。

🚀 快速开始

按照以下步骤,您可以轻松开始使用MCP服务器进行币安现货交易:

  1. 克隆仓库:
git clone [url]
cd mcp-server-cex-bn
  1. 配置API密钥:编辑.env文件并添加您的币安API凭证。
  2. 启动服务器:
npm start

✨ 主要特性

交易操作

  • 配置并安全存储币安API凭证。
  • 执行现货交易操作(限价/市价订单)。
  • 监控账户余额。
  • 跟踪和管理未完成订单。
  • 取消现有订单。

工具

configure_api_keys

安全地存储您的币安API凭证:

await configureBinanceApiKeys({
  apiKey: 'your-api-key',
  apiSecret: 'your-api-secret'
});

create_spot_order

创建限价或市价订单:

// 限价订单
await createSpotOrder({
  symbol: 'BTCUSDT',
  side: 'BUY',
  type: 'LIMIT',
  quantity: '0.001',
  price: '40000'
});

// 市价订单
await createSpotOrder({
  symbol: 'BTCUSDT',
  side: 'BUY',
  type: 'MARKET',
  quantity: '0.001'
});

cancel_order

取消现有订单:

await cancelOrder({
  symbol: 'BTCUSDT',
  orderId: '12345678'
});

get_balances

检查您的账户余额:

const balances = await getBalances();
// 返回:{ BTC: '0.1', USDT: '1000', ... }

get_open_orders

列出所有未完成订单:

const orders = await getOpenOrders({
  symbol: 'BTCUSDT' // 可选:指定符号
});

📚 详细文档

安全注意事项

  • ⚠️ 重要提示
    • 永远不要将API密钥提交到版本控制中。
    • 使用环境变量或安全密钥存储。
    • 限制API密钥权限,仅允许所需操作。
    • 定期轮换您的API密钥。

速率限制

  • 遵守币安API的速率限制。
  • 默认速率限制:
    • 每分钟1200个请求用于订单操作。
    • 每秒100个请求用于市场数据。
  • 实现适当的错误处理以应对速率限制错误。

错误处理

常见错误场景:

  • 无效的API凭证。
  • 余额不足。
  • 无效的订单参数。
  • 速率限制超过。
  • 网络连接问题。

示例错误处理:

try {
  await createSpotOrder({
    symbol: 'BTCUSDT',
    side: 'BUY',
    type: 'LIMIT',
    quantity: '0.001',
    price: '40000'
  });
} catch (error) {
  if (error.code === -2010) {
    console.error('余额不足');
  } else if (error.code === -1021) {
    console.error('速率限制超过');
  }
}

项目结构

.
├── src/
│   ├── index.ts                 # 服务器入口点
│   ├── services/
│   │   ├── binance.ts          # 币安API集成
│   │   ├── keystore.ts         # API密钥管理
│   │   └── spot_order.ts       # 现货订单处理
│   └── README.md               # 项目文档
└── package.json                # 包配置文件

开发

  1. 设置环境变量:
cp .env.example .env
  1. 安装依赖:
npm install
  1. 构建和启动服务器:
npm run build
npm start
  1. 调试工具:使用MCP Inspector进行调试。
help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client