首页
学习
活动
专区
圈层
工具
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
首页
学习
活动
专区
圈层
工具
MCP广场
MCP广场 >详情页
mcp-server-bn2025-05-210分享
github
该服务器为Binance现货交易操作提供了一个强大的接口,包括API凭证的安全管理、现货订单的执行与管理以及账户余额和未完成订单的监控。
By kydlikebtc
2025-05-210
github
详情内容

mcp-server-cex-bn

smithery badge

此MCP服务器提供了与币安现货和期货交易操作的全面集成。

中文说明

功能

现货交易操作

  • 执行现货交易操作(限价/市价订单)
  • 监控账户余额
  • 跟踪和管理未完成订单
  • 取消现有订单

期货交易操作

  • 创建多种类型的期货订单(限价、市价、止损、止盈等)
  • 管理杠杆设置(1-125倍)
  • 监控期货持仓和账户信息
  • 跟踪资金费率
  • 支持单向模式和对冲模式持仓
  • 高级订单类型,包括追踪止损和仅减仓订单

工具

API配置

configure_api_keys

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

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

现货交易工具

create_spot_order

创建限价或市价订单:

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

// MARKET order
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();
// Returns: { BTC: '0.1', USDT: '1000', ... }
get_open_orders

列出所有未完成订单:

const orders = await getOpenOrders({
  symbol: 'BTCUSDT' // Optional: specify symbol
});

期货交易工具

create_futures_order

创建多种类型的期货订单:

// LIMIT order
await createFuturesOrder({
  symbol: 'BTCUSDT',
  side: 'BUY',
  type: 'LIMIT',
  quantity: '0.001',
  price: '40000',
  timeInForce: 'GTC'
});

// STOP MARKET order
await createFuturesOrder({
  symbol: 'BTCUSDT',
  side: 'SELL',
  type: 'STOP_MARKET',
  quantity: '0.001',
  stopPrice: '38000'
});

// TRAILING STOP order
await createFuturesOrder({
  symbol: 'BTCUSDT',
  side: 'SELL',
  type: 'TRAILING_STOP_MARKET',
  quantity: '0.001',
  callbackRate: '1.0' // 1% callback rate
});
set_futures_leverage

调整交易对的杠杆:

await setFuturesLeverage({
  symbol: 'BTCUSDT',
  leverage: 10  // 1-125x
});
get_futures_positions

获取所有未平仓的期货持仓:

const positions = await getFuturesPositions();
get_futures_account

获取详细的期货账户信息:

const account = await getFuturesAccount();
get_funding_rate

获取期货符号的资金费率:

const fundingRate = await getFundingRate({
  symbol: 'BTCUSDT'
});
cancel_futures_order

取消现有的期货订单:

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

期货交易详情

持仓模式

  • 单向模式:每个符号一个持仓
    • 默认模式,简单的持仓管理
    • 总持仓量是所有订单的总和
  • 对冲模式:独立的多头和空头持仓
    • 允许同时持有多个多头和空头持仓
    • 每个持仓有独立的保证金要求

保证金类型

  • 隔离保证金:每个持仓固定的保证金
    • 风险限制在分配的保证金内
    • 每个持仓有自己的杠杆设置
  • 跨仓保证金:跨持仓共享保证金
    • 更高的资本效率
    • 所有持仓共担风险

资金费率

永续期货合约使用资金费率来保持期货价格与现货价格一致:

  • 正利率:多头支付给空头
  • 负利率:空头支付给多头
  • 每8小时结算一次

安全注意事项

现货交易安全

  • 切勿将API密钥提交到版本控制系统
  • 使用环境变量或安全密钥存储
  • 限制API密钥权限,仅允许必要的操作
  • 定期更换您的API密钥

期货交易安全

  • 根据风险承受能力设置适当的杠杆限制
  • 始终使用止损单来限制潜在损失
  • 仔细监控清算价格
  • 定期检查仓位风险和保证金比率
  • 考虑使用仅减仓订单进行风险管理
  • 对于交叉保证金要谨慎,因为存在共享风险

速率限制

  • 遵守Binance API的速率限制
  • 默认速率限制:
    • 每分钟1200次请求用于订单操作
    • 每秒100次请求用于市场数据
  • 对于达到速率限制的错误实现适当的错误处理

错误处理

常见错误场景

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

期货特定错误

  • InsufficientMarginError: 保证金不足以执行操作
  • InvalidPositionModeError: 位置模式设置错误
  • OrderValidationError: 无效的期货订单参数

示例错误处理:

try {
  await createFuturesOrder({
    symbol: 'BTCUSDT',
    side: 'BUY',
    type: 'LIMIT',
    quantity: '0.001',
    price: '40000',
    timeInForce: 'GTC'
  });
} catch (error) {
  if (error instanceof InsufficientMarginError) {
    console.error('Insufficient margin available');
  } else if (error instanceof InvalidPositionModeError) {
    console.error('Invalid position mode');
  } else if (error instanceof OrderValidationError) {
    console.error('Invalid order parameters');
  }
}

项目结构

.
├── src/
│   ├── index.ts                 # Server entry point
│   ├── services/
│   │   ├── binance.ts          # Binance API integration
│   │   ├── keystore.ts         # API key management
│   │   └── tools.ts            # Trading tools implementation
│   └── types/
│       ├── binance.ts          # Binance types
│       └── binance-connector.d.ts  # API client types
├── README.md
├── README_CN.md
├── package.json
├── pnpm-lock.yaml
└── tsconfig.json

开发

  1. 设置环境变量:

在根目录创建.env文件,并设置您的Binance API凭证:

BINANCE_API_KEY=your_api_key_here
BINANCE_API_SECRET=your_secret_key_here
  1. 安装依赖项:
pnpm install

构建服务器:

pnpm build

对于带有自动重建功能的开发:

pnpm watch

安装

通过Smithery安装

要通过Smithery自动为Claude Desktop安装Binance Trading Server:

npx -y @smithery/cli install mcp-server-cex-bn --client claude

手动安装

  1. 克隆仓库
  2. 安装依赖项:
pnpm install
  1. .env中配置您的Binance API凭证
  2. 构建并启动服务器:
pnpm build
pnpm start

调试

由于MCP服务器通过标准输入输出通信,调试可能会有挑战。我们推荐使用MCP Inspector,它作为一个包脚本提供:

pnpm inspector

Inspector将提供一个URL,以便您可以在浏览器中访问调试工具。

mcp-server-bn

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档