mcp-server-bn
by: kydlikebtc
mcp server bn
πOverview
Purpose: To provide a comprehensive integration framework for executing and managing trading operations on Binance's spot and futures markets.
Overview: The MCP Server for Binance enables users to perform various trading operations efficiently, including spot and futures trading, while ensuring security and compliance with Binance's API standards. It allows traders to monitor balances, manage orders, and configure leverage settings seamlessly.
Key Features:
-
Spot Trading Operations: Capable of executing LIMIT and MARKET orders, monitoring account balances, and managing open and canceled orders to streamline spot trading activities.
-
Futures Trading Operations: Supports a diverse range of order types (e.g., LIMIT, MARKET, STOP, TAKE_PROFIT) and advanced features such as leverage settings (1-125x), position management in one-way and hedge modes, and funding rate tracking to optimize futures trading strategies.
mcp-server-cex-bn
This MCP Server provides integration with Binance's spot and futures trading operations.
Features
Spot Trading Operations
- Execute LIMIT/MARKET orders
- Monitor account balances
- Track open orders
- Cancel existing orders
Futures Trading Operations
- Create LIMIT, MARKET, STOP, and other order types
- Manage leverage settings (1-125x)
- Monitor futures positions and account information
- Track funding rates
- Support one-way and hedge mode positions
- Advanced order types: trailing stops and reduce-only orders
Tools
API Configuration
configure_api_keys
Securely store your Binance API credentials:
await configureBinanceApiKeys({
apiKey: 'your-api-key',
apiSecret: 'your-api-secret'
});
Spot Trading Tools
create_spot_order
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'
});
cancel_order
Cancel an existing order:
await cancelOrder({
symbol: 'BTCUSDT',
orderId: '12345678'
});
get_balances
Check account balances:
const balances = await getBalances();
get_open_orders
List open orders:
const orders = await getOpenOrders({
symbol: 'BTCUSDT' // Optional: specify symbol
});
Futures Trading Tools
create_futures_order
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
});
set_futures_leverage
Adjust leverage for a trading pair:
await setFuturesLeverage({
symbol: 'BTCUSDT',
leverage: 10 // 1-125x
});
get_futures_positions
Get all open futures positions:
const positions = await getFuturesPositions();
get_futures_account
Get detailed futures account information:
const account = await getFuturesAccount();
get_funding_rate
Get funding rate for a futures symbol:
const fundingRate = await getFundingRate({
symbol: 'BTCUSDT'
});
cancel_futures_order
Cancel a futures order:
await cancelFuturesOrder({
symbol: 'BTCUSDT',
orderId: '12345678'
});
Futures Trading Details
Position Modes
- One-way Mode: Single position per symbol. Simplified position management.
- Hedge Mode: Separate long and short positions. Allows simultaneous holdings.
Margin Types
- Isolated Margin: Fixed margin per position.
- Cross Margin: Shared margin across positions.
Funding Rate
Positive funding rates result in longs paying shorts, and vice versa. Payments occur every 8 hours.
Security Considerations
Spot Trading Security
- Never commit API keys to version control.
- Use environment variables for secure storage.
- Limit API key permissions to required operations.
Futures Trading Security
- Set appropriate leverage limits.
- Use stop-loss orders for risk management.
- Monitor margin ratios closely.
Rate Limits
- Respect Binance API rate limits.
- Default limits: 1200 requests/minute for order operations.
Error Handling
Common Error Scenarios
- Invalid API credentials
- Insufficient balance
- Invalid order parameters
Example error handling:
try {
await createFuturesOrder({
symbol: 'BTCUSDT',
side: 'BUY',
type: 'LIMIT',
quantity: '0.001',
price: '40000',
timeInForce: 'GTC'
});
} catch (error) {
// Handle specific errors here
}
Project Structure
.
βββ 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
βββ package.json
βββ pnpm-lock.yaml
βββ tsconfig.json
Development
- Set up environment variables in a
.env
file in the root directory. - Install dependencies:
pnpm install
- Build the server:
pnpm build
- For development with auto-rebuild:
pnpm watch
Installation
Installing via Smithery
To install the Binance Trading Server via Smithery:
npx -y @smithery/cli install mcp-server-cex-bn --client claude
Installing Manually
- Clone the repository.
- Install dependencies:
pnpm install
- Configure your Binance API credentials in
.env
. - Build and start the server:
pnpm build pnpm start
Debugging
Use the MCP Inspector for debugging:
pnpm inspector