binance-futures-mcp

binance-futures-mcp

Comprehensive Binance Futures trading MCP server with 41 professional trading tools across account management, order execution, market data, and risk management. Features smart ticker caching, secure authentication, and Docker support for seamless integration with MCP clients.

Category
访问服务器

README

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

  • 41 comprehensive trading tools across 8 categories
  • Smart ticker data caching with 5-minute refresh cycle
  • Proper authentication handling (rejects unauthenticated requests)
  • Active symbol filtering (excludes delisted tokens)
  • 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 41 comprehensive 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/one-way)
  • get_commission_rate - Get commission rates

Risk Management

(4 tools)

  • get_adl_quantile - Get ADL quantile estimation
  • get_leverage_brackets - Get leverage brackets
  • get_force_orders - Get liquidation orders
  • get_position_margin_history - Get margin change history

Order Management

(6 tools)

  • place_order - Place a futures order
  • place_multiple_orders - Place multiple orders in batch
  • cancel_order - Cancel an active order
  • cancel_multiple_orders - Cancel multiple orders
  • cancel_all_orders - Cancel all open orders for a symbol
  • auto_cancel_all_orders - Set a timer to cancel all orders

Order Query

(4 tools)

  • get_open_order - Query current open order by order id
  • get_open_orders - Get all open orders for a symbol
  • get_all_orders - Get all orders (open, filled, cancelled)
  • query_order - Query a specific order's status

Position Management

(4 tools)

  • close_position - Close a position (market order)
  • modify_order - Modify an existing order
  • add_tp_sl_to_position - Add TP/SL to position
  • place_bracket_order - Place an order with TP/SL

Trading Configuration

(4 tools)

  • change_leverage - Change leverage for a symbol
  • change_margin_type - Change margin type (isolated/cross)
  • change_position_mode - Switch between hedge and one-way modes
  • modify_position_margin - Modify position margin

Market Data

(12 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_24hr_ticker - Get 24hr price change statistics
  • get_top_gainers_losers - Get top gainers and losers
  • get_market_overview - Get overall market statistics
  • get_order_book - Get order book depth
  • get_klines - Get candlestick data
  • get_mark_price - Get mark price and funding rate
  • get_aggregate_trades - Get compressed/aggregate trades list
  • get_funding_rate_history - Get funding rate history
  • get_taker_buy_sell_volume - Get taker buy/sell volume ratio

Trading History

(2 tools)

  • get_account_trades - Get account trade history
  • get_income_history - Get income history

💡 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 (41 trading tools)
│       ├── cache.py             # Smart ticker data caching
│       └── 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
  • Smart Caching: 5-minute ticker cache with background refresh
  • Authentication: Secure API key handling with environment variables
  • Error Handling: Graceful degradation and comprehensive error management
  • Active Symbol Filtering: Excludes delisted tokens automatically

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

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选