Binance Spot Trading MCP server

Integrates with Binance spot trading API to enable automated cryptocurrency trading strategies using SQLite for data storage and secure credential management.
Back to servers
Provider
kydlikebtc
Release date
Jan 07, 2025
Language
TypeScript
Stats
14 stars

This MCP Server provides comprehensive integration with Binance's spot and futures trading operations, allowing you to execute trades, monitor account balances, manage orders, and access various futures trading features through a simple API interface.

Installation

Installing via Smithery

The easiest way to install the Binance Trading Server for Claude Desktop is via Smithery:

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

Manual Installation

If you prefer to install manually:

  1. Clone the repository
  2. Install dependencies:
pnpm install
  1. Configure your Binance API credentials in a .env file
  2. Build and start the server:
pnpm build
pnpm start

Configuration

API Key Setup

Before using the server, you need to securely store your Binance API credentials:

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

Spot Trading Features

Creating Spot Orders

You can create LIMIT or MARKET orders:

// 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'
});

Canceling Orders

To cancel an existing order:

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

Checking Balances

View your account balances:

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

Viewing Open Orders

List all your open orders:

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

Futures Trading Features

Creating Futures Orders

Create various types of futures orders:

// 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
});

Setting Leverage

Adjust leverage for a trading pair:

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

Viewing Positions and Account Information

Get all open futures positions:

const positions = await getFuturesPositions();

Get detailed futures account information:

const account = await getFuturesAccount();

Getting Funding Rate

Check the funding rate for a futures symbol:

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

Canceling Futures Orders

Cancel an existing futures order:

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

Understanding Futures Trading

Position Modes

The server supports two position modes:

  • One-way Mode: Simpler position management with a single position per symbol
  • Hedge Mode: Allows holding both long and short positions simultaneously

Margin Types

You can choose between:

  • Isolated Margin: Fixed margin per position with limited risk
  • Cross Margin: Shared margin across positions for higher capital efficiency

Funding Rate

Perpetual futures contracts use funding rates to keep futures prices aligned with spot prices:

  • Positive rate: Longs pay shorts
  • Negative rate: Shorts pay longs
  • Payments occur every 8 hours

Security Best Practices

API Key Security

  • Never commit API keys to version control
  • Use environment variables or secure key storage
  • Restrict API key permissions to only required operations
  • Regularly rotate your API keys

Futures Trading Security

  • Set appropriate leverage limits based on risk tolerance
  • Always use stop-loss orders to limit potential losses
  • Monitor liquidation prices carefully
  • Regularly check position risks and margin ratios
  • Consider using reduce-only orders for risk management
  • Be cautious with cross-margin due to shared risk

Error Handling

It's important to implement proper error handling:

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');
  }
}

Rate Limits

Be aware of Binance's API rate limits:

  • 1200 requests per minute for order operations
  • 100 requests per second for market data

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later