BingX MCP Server
Enables LLM agents to access BingX cryptocurrency exchange market data and execute trades through the official API, with support for account management, order creation, and technical indicators.
README
BingX MCP Server
Production-ready MCP (Model Context Protocol) server for the BingX cryptocurrency exchange. Enables LLM agents to access BingX market data and execute trades through the official BingX API.
Features
- Market Data: Ticker, OHLCV/candles, order book depth, recent trades, funding rate, open interest
- Account: Balance, open positions, PnL
- Trading: Create/cancel orders, order history, leverage management
- Scalping Metrics: Spread, orderbook imbalance, buy/sell delta, volume spike, ATR, RSI, VWAP
- Technical Indicators: EMA, SMA, VWAP, RSI, ATR, MACD, Bollinger Bands, Volume Delta, CVD, Momentum, ROC
- WebSocket Client: Real-time streams with auto-reconnect
- Security: HMAC-SHA256 signature, rate limiting, retry logic, structured logging
Architecture
bingx-mcp2/
├── src/
│ ├── api/
│ │ └── client.py # HTTP client with HMAC-SHA256 auth
│ ├── services/
│ │ ├── market.py # Market data service
│ │ ├── account.py # Account/balance service
│ │ ├── trade.py # Trading operations service
│ │ └── indicators.py # Technical indicator calculations
│ ├── tools/
│ │ ├── account_tools.py # Balance, positions MCP tools
│ │ ├── trade_tools.py # Order, leverage MCP tools
│ │ ├── market_tools.py # Ticker, klines, orderbook MCP tools
│ │ └── scalping_tools.py # Indicators, scalping metrics MCP tools
│ ├── models/
│ │ ├── common.py # Shared models
│ │ ├── market.py # Market data Pydantic models
│ │ ├── account.py # Account Pydantic models
│ │ └── trade.py # Trade Pydantic models
│ ├── utils/
│ │ ├── config.py # Environment configuration
│ │ ├── logging.py # Loguru structured logging
│ │ ├── ratelimit.py # Token-bucket rate limiter
│ │ └── retry.py # Exponential backoff retry
│ └── websocket/
│ └── client.py # WebSocket client with auto-reconnect
├── main.py # Entry point
├── requirements.txt
├── .env.example
└── README.md
Installation
Prerequisites
- Python 3.12+
- BingX API Key and Secret Key
Setup
# Clone the repository
git clone <repo-url> bingx-mcp2
cd bingx-mcp2
# Create virtual environment
python3 -m venv .venv
source .venv/bin/activate # Linux/Mac
# .venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
# Configure API keys
cp .env.example .env
# Edit .env with your credentials
Environment Variables
Create a .env file:
BINGX_API_KEY=your_bingx_api_key
BINGX_SECRET_KEY=your_bingx_secret_key
BINGX_ENV=prod-live # or 'prod-vst' for demo environment
Getting API Keys
- Log in to BingX
- Navigate to API Management under your user menu
- Click Create API
- Set permissions: enable Perpetual Futures Trading (at minimum)
- Save the API Key and Secret Key securely
Usage
Starting the Server
Stdio transport (default, for Claude Desktop / Cursor):
python main.py
SSE transport (for HTTP-based clients, OpenAI Agents SDK):
python main.py --sse --host 0.0.0.0 --port 8000
MCP Tools Reference
| Tool | Description | Auth |
|---|---|---|
get_balance |
Total/available balance, unrealized PnL, per-asset | Yes |
get_positions |
Open positions with entry price, mark price, liq price | Yes |
get_open_orders |
Currently open orders | Yes |
get_order_history |
Historical orders with time/count filters | Yes |
create_order |
Create MARKET/LIMIT/STOP/TAKE_PROFIT orders | Yes |
cancel_order |
Cancel order by ID | Yes |
cancel_all_orders |
Cancel all open orders for a symbol | Yes |
set_leverage |
Set leverage (1-125x) | Yes |
get_ticker |
Last price, bid, ask, spread | No |
get_klines |
OHLCV candlestick data (all intervals) | No |
get_orderbook |
Order book depth with imbalance | No |
get_recent_trades |
Recent public trades | No |
get_open_interest |
Open interest | No |
get_funding_rate |
Funding rate, mark price, index price | No |
get_long_short_ratio |
Long/short ratio from trades | No |
get_taker_flow |
Taker buy/sell volume delta | No |
calculate_indicators |
EMA, SMA, RSI, MACD, BB, VWAP, ATR, etc. | No |
get_scalping_metrics |
Comprehensive scalping snapshot | No |
Order Types Supported
# Market order
create_order(symbol="BTC-USDT", side="BUY", type="MARKET", quantity=0.01)
# Limit order
create_order(symbol="BTC-USDT", side="SELL", type="LIMIT", quantity=0.01, price=100000)
# Stop-loss market
create_order(symbol="BTC-USDT", side="SELL", type="STOP_MARKET", quantity=0.01, stop_price=95000)
# Stop-loss limit
create_order(symbol="BTC-USDT", side="SELL", type="STOP", quantity=0.01, price=94900, stop_price=95000)
# Take-profit market
create_order(symbol="BTC-USDT", side="SELL", type="TAKE_PROFIT_MARKET", quantity=0.01, stop_price=105000)
# Take-profit limit
create_order(symbol="BTC-USDT", side="SELL", type="TAKE_PROFIT", quantity=0.01, price=105100, stop_price=105000)
Claude Desktop Integration
Add to your claude_desktop_config.json:
{
"mcpServers": {
"bingx": {
"command": "python",
"args": ["/absolute/path/to/bingx-mcp2/main.py"],
"env": {
"BINGX_API_KEY": "your_api_key",
"BINGX_SECRET_KEY": "your_secret_key"
}
}
}
}
Cursor Integration
Add to Cursor's MCP configuration (~/.cursor/mcp.json):
{
"mcpServers": {
"bingx": {
"command": "python",
"args": ["/absolute/path/to/bingx-mcp2/main.py"],
"env": {
"BINGX_API_KEY": "your_api_key",
"BINGX_SECRET_KEY": "your_secret_key"
}
}
}
}
OpenAI Agents SDK Integration
Run the server in SSE mode:
python main.py --sse --port 8000
Then connect in your agent:
from agents import Agent, Runner
from agents.mcp import MCPServerSse
async def main():
async with MCPServerSse(
name="bingx",
params={
"url": "http://localhost:8000/sse",
},
) as server:
agent = Agent(
name="trading_agent",
instructions="You are a crypto trading assistant with access to BingX market data.",
mcp_servers=[server],
)
result = await Runner.run(agent, "What's the current BTC price and order book imbalance?")
print(result.final_output)
Technical Details
API Endpoints Used
Based on the official BingX API documentation:
| Category | Endpoint | Method |
|---|---|---|
| Market | /openApi/swap/v2/quote/ticker |
GET |
| Market | /openApi/swap/v2/quote/bookTicker |
GET |
| Market | /openApi/swap/v2/quote/depth |
GET |
| Market | /openApi/swap/v2/quote/trades |
GET |
| Market | /openApi/swap/v3/quote/klines |
GET |
| Market | /openApi/swap/v2/quote/openInterest |
GET |
| Market | /openApi/swap/v2/quote/premiumIndex |
GET |
| Account | /openApi/swap/v3/user/balance |
GET |
| Account | /openApi/swap/v2/user/positions |
GET |
| Trade | /openApi/swap/v2/trade/order |
POST |
| Trade | /openApi/swap/v2/trade/order |
DELETE |
| Trade | /openApi/swap/v2/trade/openOrders |
GET |
| Trade | /openApi/swap/v2/trade/allOrders |
GET |
| Trade | /openApi/swap/v2/trade/allOpenOrders |
DELETE |
| Trade | /openApi/swap/v2/trade/leverage |
POST |
Authentication
Requests are signed using HMAC-SHA256:
- Parameters are sorted alphabetically
- Query string is built:
param1=value1¶m2=value2&...×tamp=... - HMAC-SHA256 signature is computed with the secret key and hex-encoded
- Signature is appended:
querystring&signature=...
Rate Limiting
The client enforces BingX API rate limits:
- Market data: 500 requests/10 seconds per IP
- Account/Trade: 5-10 requests/second
Error Handling
- Automatic retry with exponential backoff (max 3 attempts)
- Domain fallback (bingx.com -> bingx.pro)
- Structured logging to stderr and rotating log files
- All errors returned as JSON with descriptive messages
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。