Skip to main content

A Model Context Protocol server for Binance Futures API with comprehensive trading tools including TP/SL management

Project description

Binance MCP Server

A Model Context Protocol (MCP) server that provides comprehensive access to Binance Futures API endpoints. This server implements all major trading, account management, and market data functionality as documented in the Binance Futures API.

๐Ÿ“‹ Table of Contents

๐Ÿš€ Quick Start

  1. Install the package:

    pip install binance_futures_mcp
    
  2. Run the server:

    uvx binance_futures_mcp --binance-api-key "your_key" --binance-secret-key "your_secret"
    
  3. Configure in your MCP client (see Configuration section for detailed setup)

โœจ Features

  • 11 essential trading tools across 2 categories (Account Information and Market Data)
  • Proper authentication handling (rejects unauthenticated requests)
  • Error handling and graceful degradation
  • Real-time market data access
  • Complete order management suite
  • Risk management tools

๐Ÿ“ฆ Installation

Option 1: PyPI Installation (Recommended)

Install the package from PyPI:

pip install binance_futures_mcp

Option 2: Docker Deployment

For containerized deployment:

# Clone the repository
git clone https://github.com/alexcandrabersiva/bin-mcp.git
cd binance-mcp-server

# Build the Docker image
docker build -t binance-mcp-server .

# Run with environment variables
docker run -e BINANCE_API_KEY="your_api_key" -e BINANCE_SECRET_KEY="your_secret_key" \
  binance-mcp-server --binance-api-key "$BINANCE_API_KEY" --binance-secret-key "$BINANCE_SECRET_KEY"

Docker Compose (Optional)

Create a docker-compose.yml:

version: '3.8'
services:
  binance-mcp:
    build: .
    environment:
      - BINANCE_API_KEY=${BINANCE_API_KEY}
      - BINANCE_SECRET_KEY=${BINANCE_SECRET_KEY}
    command: [
      "--binance-api-key", "${BINANCE_API_KEY}",
      "--binance-secret-key", "${BINANCE_SECRET_KEY}"
    ]

Then run:

docker-compose up

Development Installation

For development, you can install from source:

git clone https://github.com/bin-mcp/binance-mcp-server.git
cd binance-mcp-server
pip install -e ".[dev]"

โš™๏ธ Configuration

API Requirements

Your Binance API key needs the following permissions:

  • Futures Trading: For order placement and management
  • Futures Reading: For account and market data access

MCP Client Setup

This server can be integrated with various MCP clients. Here are configuration examples:

VS Code

Add to your VS Code settings.json:

{
  "mcp": {
    "servers": {
      "binance": {
        "command": "uvx",
        "args": ["--from", "binance_futures_mcp", "binance-mcp-server.exe", "--binance-api-key", "your_api_key", "--binance-secret-key", "your_secret_key"]
      }
    }
  }
}

Cursor

Add to your Cursor configuration file (.cursor/mcp.json):

{
  "servers": {
    "binance": {
      "command": "uvx", 
      "args": ["--from", "binance_futures_mcp", "binance-mcp-server.exe", "--binance-api-key", "your_api_key", "--binance-secret-key", "your_secret_key"]
    }
  }
}

Windsurf

Add to your Windsurf configuration (.windsurf/mcp.json):

{
  "mcpServers": {
    "binance": {
      "command": "uvx",
      "args": ["--from", "binance_futures_mcp", "binance-mcp-server.exe", "--binance-api-key", "your_api_key", "--binance-secret-key", "your_secret_key"]
    }
  }
}

Claude Desktop

Add to your Claude Desktop configuration file:

On macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
On Windows: %APPDATA%/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "binance": {
      "command": "uvx",
      "args": ["--from", "binance_futures_mcp", "binance-mcp-server.exe", "--binance-api-key", "your_api_key", "--binance-secret-key", "your_secret_key"]
    }
  }
}

Configuration Notes

  1. No path needed: With PyPI installation, you don't need to specify paths or working directories
  2. Set API credentials: Replace your_api_key and your_secret_key with your actual Binance API credentials
  3. Alternative commands: You can also use uvx binance_futures_mcp or python -m binance_mcp
  4. Security: For production use, consider storing credentials in environment variables

๐Ÿ› ๏ธ Available Tools

The server provides 11 essential tools organized into the following categories:

Account Information

(5 tools)

  • get_account_info - Get account information
  • get_balance - Get account balance
  • get_position_info - Get position information
  • get_position_mode - Get position mode (Hedge vs. One-way)
  • get_commission_rate - Get commission rate

Market Data

(6 tools)

  • get_exchange_info - Get exchange trading rules
  • get_book_ticker - Get best price/qty on the order book
  • get_price_ticker - Get latest price for a symbol
  • get_order_book - Get order book depth
  • get_klines - Get candlestick data
  • get_mark_price - Get mark price and funding rate

๐Ÿ’ก Example Usage

Place a Market Order

{
  "tool": "place_order",
  "arguments": {
    "symbol": "BTCUSDT",
    "side": "BUY",
    "order_type": "MARKET",
    "quantity": 0.001
  }
}

Place a Limit Order

{
  "tool": "place_order",
  "arguments": {
    "symbol": "BTCUSDT",
    "side": "BUY",
    "order_type": "LIMIT",
    "quantity": 0.001,
    "price": 50000.0,
    "time_in_force": "GTC"
  }
}

Get Account Information

{
  "tool": "get_account_info",
  "arguments": {}
}

Get Market Data

{
  "tool": "get_klines",
  "arguments": {
    "symbol": "BTCUSDT",
    "interval": "1h",
    "limit": 100
  }
}

Get 24hr Price Statistics

{
  "tool": "get_24hr_ticker",
  "arguments": {
    "symbol": "BTCUSDT"
  }
}

Get Taker Buy/Sell Volume Ratio

{
  "tool": "get_taker_buy_sell_volume",
  "arguments": {
    "symbol": "BTCUSDT"
  }
}

๐Ÿ”’ Security

API Key Security

๐Ÿ” Your Binance API key and secret remain completely local to your computer. The MCP server runs entirely on your machine; neither the package author nor any third-party remote service can access your credentials.

Key Security Points:

  • โœ… Store credentials in environment variables (recommended) or local config files
  • โœ… Keys are never transmitted unless you publish them
  • โŒ Never commit credentials to version control
  • โŒ Never share screenshots/logs containing credentials
  • โœ… Use API keys with minimal required permissions
  • โœ… IP-whitelist your keys when possible
  • โœ… Consider using Binance Testnet for development

How It Works:

  1. Local Launch: Your editor/terminal launches the MCP server locally:

    uvx binance_futures_mcp --binance-api-key $BINANCE_API_KEY --binance-secret-key $BINANCE_SECRET_KEY
    
  2. Keys Stay Local: Your credentials exist only:

    • In your environment variables or local config file
    • On your computer's command line/process table
    • In MCP process memory during HTTPS calls to Binance
  3. No Telemetry: The package contains zero telemetry or analytics code

Rate Limiting & Error Handling

  • โšก Respects Binance's weight-based rate limits
  • ๐Ÿ”„ Automatic order placement rate limiting
  • ๐Ÿ” Automatic HMAC SHA256 signature generation
  • ๐Ÿ›ก๏ธ Comprehensive error handling with clear messages
  • โœ… Parameter validation before API calls

๐Ÿ“š API Reference

This server implements all endpoints documented in the Binance Futures API:

  • Base URL: https://fapi.binance.com
  • API Type: Binance USD-S Margined Futures
  • Authentication: API Key + HMAC SHA256 Signature
  • Rate Limits: Respected automatically

For detailed parameter specifications, see the Binance Futures API Documentation.

๐Ÿ”ง Development

Project Structure

binance-mcp-server/
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ binance_mcp/
โ”‚       โ”œโ”€โ”€ __init__.py          # Package initialization
โ”‚       โ”œโ”€โ”€ __main__.py          # CLI entry point
โ”‚       โ”œโ”€โ”€ server.py            # Main MCP server implementation
โ”‚       โ”œโ”€โ”€ client.py            # Binance API client
โ”‚       โ”œโ”€โ”€ handlers.py          # Tool execution handlers
โ”‚       โ”œโ”€โ”€ tools.py             # Tool definitions (11 trading tools)
โ”‚       โ””โ”€โ”€ config.py            # Configuration management
โ”œโ”€โ”€ Dockerfile                   # Docker containerization
โ”œโ”€โ”€ .dockerignore               # Docker build optimization
โ”œโ”€โ”€ pyproject.toml              # Project configuration
โ”œโ”€โ”€ mcp-config.json             # MCP client configuration example
โ””โ”€โ”€ README.md                   # Documentation

Architecture Overview

  • Modular Design: Separated concerns across multiple components
  • Authentication: Secure API key handling with environment variables
  • Error Handling: Graceful degradation and comprehensive error management

Running Tests

pytest

Code Formatting

black src/
ruff check src/

โ— Error Codes

Common Binance API error codes you might encounter:

Code Description
-1121 Invalid symbol
-2019 Margin is insufficient
-1116 Invalid orderType
-1013 Filter failure (PRICE_FILTER, LOT_SIZE, etc.)
-1102 Mandatory parameter was not sent
-1003 Too many requests (rate limit exceeded)

For a complete list, see the Binance API Error Codes.

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

๐Ÿ“„ License

MIT License - see LICENSE file for details.

โš ๏ธ Disclaimer

โš ๏ธ IMPORTANT: This software is for educational and development purposes. Trading cryptocurrencies involves substantial risk. Use at your own risk and never trade with money you cannot afford to lose.

๐Ÿ’ฌ Support

For issues and questions:

  • Check the Binance API Documentation
  • Review the error codes in the API documentation
  • Ensure your API credentials have the correct permissions

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

binance_futures_mcp-1.2.1.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

binance_futures_mcp-1.2.1-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file binance_futures_mcp-1.2.1.tar.gz.

File metadata

  • Download URL: binance_futures_mcp-1.2.1.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for binance_futures_mcp-1.2.1.tar.gz
Algorithm Hash digest
SHA256 d989ceb26482df79d4a42c8ebf309b51d173e1d3a5dd9982a195febfb39fe8d7
MD5 e280ce632e2934e58c0ab4c618d295bb
BLAKE2b-256 fed3604bfd108f585aac898accea84cf45dba26025d9446d1dc32e405c0205e7

See more details on using hashes here.

File details

Details for the file binance_futures_mcp-1.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for binance_futures_mcp-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 90c43011a1dbfab4f9f27794418607a8f41548e0372e81aba3e6aa1dc4bc7f27
MD5 2b19c91afcb23e551fc6edf904cf4d79
BLAKE2b-256 ff8b27d99525d452b7a30107b5a7edfc63db67d17f37e20def6bd3fef3936af4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page