此MCP服务器提供了与币安现货和期货交易操作的全面集成。
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'
});

永续期货合约使用资金费率来保持期货价格与现货价格一致:
示例错误处理:
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
在根目录创建.env
文件,并设置您的Binance API凭证:
BINANCE_API_KEY=your_api_key_here BINANCE_API_SECRET=your_secret_key_here
pnpm install
构建服务器:
pnpm build
对于带有自动重建功能的开发:
pnpm watch
要通过Smithery自动为Claude Desktop安装Binance Trading Server:
npx -y @smithery/cli install mcp-server-cex-bn --client claude
pnpm install
.env
中配置您的Binance API凭证pnpm build pnpm start
由于MCP服务器通过标准输入输出通信,调试可能会有挑战。我们推荐使用MCP Inspector,它作为一个包脚本提供:
pnpm inspector
Inspector将提供一个URL,以便您可以在浏览器中访问调试工具。