Skip to main content
Glama
kydlikebtc

MCP Server for Binance Spot Trading

by kydlikebtc

mcp-服务器-cex-bn

铁匠徽章

该MCP服务器与币安的现货和期货交易业务提供全面整合。

中文说明

特征

现货交易操作

  • 执行现货交易操作(限价/市价单)

  • 监控账户余额

  • 跟踪和管理未结订单

  • 取消现有订单

期货交易操作

  • 创建各种类型的期货订单(LIMIT、MARKET、STOP、TAKE_PROFIT 等)

  • 管理杠杆设置(1-125倍)

  • 监控期货仓位和账户信息

  • 追踪融资利率

  • 支持单向和对冲模式仓位

  • 高级订单类型包括追踪止损和仅减少订单

工具

API 配置

configure_api_keys

安全存储您的 Binance 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' });

Related MCP server: Binance MCP Server

期货交易详情

位置模式

  • 单向模式:每个符号单一仓位

    • 默认模式,仓位管理更简单

    • 总仓位规模是所有订单的总和

  • 对冲模式:多空仓位分离

    • 允许同时持有多头和空头头寸

    • 每个仓位都有独立的保证金要求

保证金类型

  • 逐仓保证金:每个仓位固定保证金

    • 风险仅限于分配的保证金

    • 每个仓位都有自己的杠杆设置

  • 全仓保证金:跨仓位共享保证金

    • 更高的资本效率

    • 所有职位共担风险

资金费率

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

  • 正利率:多头支付空头

  • 负利率:空头支付多头

  • 每 8 小时付款一次

安全注意事项

现货交易安全

  • 切勿将 API 密钥提交到版本控制

  • 使用环境变量或安全密钥存储

  • 将 API 密钥权限限制为仅执行必需的操作

  • 定期轮换您的 API 密钥

期货交易安全

  • 根据风险承受能力设定适当的杠杆限制

  • 始终使用止损单来限制潜在损失

  • 仔细监控清算价格

  • 定期检查持仓风险和保证金比率

  • 考虑使用仅减少订单进行风险管理

  • 由于风险共担,对跨保证金需谨慎

速率限制

  • 遵守币安 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 服务器通过 stdio 进行通信,调试起来可能比较困难。我们推荐使用MCP Inspector ,它以包脚本的形式提供:

pnpm inspector

检查器将提供一个 URL 来访问浏览器中的调试工具。

mcp-服务器-bn

-
security - not tested
F
license - not found
-
quality - not tested

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/kydlikebtc/mcp-server-bn'

If you have feedback or need assistance with the MCP directory API, please join our Discord server