Bybit MCP Server

Bybit MCP Server

Enables cryptocurrency trading on Bybit exchange through comprehensive market data access, account management, and automated trading operations. Features smart position validation, trailing stop losses, and risk management tools with demo mode support for safe testing.

Category
访问服务器

README

Bybit MCP Server (Node.js)

A Model Context Protocol (MCP) server for Bybit trading operations, built with Node.js and TypeScript.

Features

  • Perfect Authentication - Uses exact Cloud Functions signature logic
  • Smart Position Validation - Automatic validation against Bybit trading rules
  • Position Mode Detection - Automatically detects one-way vs hedge mode
  • 16 Trading Tools - Complete market data, account, and trading operations
  • Demo Mode Support - Safe testing environment

Installation

  1. Build the server:

    cd /Users/rkondis/personalwork/mcp-bybit-node
    npm install
    npm run build
    
  2. Configure environment:

    • Copy .env file with your Bybit API credentials
    • Set DEMO=true for safe testing

Claude MCP Integration

Method 1: Using the startup script (Recommended)

Step 1: Ensure your .env file exists with your API keys:

# Check if .env file exists
ls -la /Users/rkondis/personalwork/mcp-bybit-node/.env

# If it doesn't exist, create it:
cat > /Users/rkondis/personalwork/mcp-bybit-node/.env << EOF
ACCESS_KEY=your_access_key_here
SECRET_KEY=your_secret_key_here
DEMO=true
EOF

Step 2: Add to Claude MCP:

claude mcp add-json bybit-node '{
  "type": "stdio",
  "command": "/Users/rkondis/personalwork/mcp-bybit-node/start-server.sh",
  "args": []
}'

The startup script automatically loads API keys from the .env file.

Method 2: Direct node execution with environment variables

claude mcp add-json bybit-node '{
  "type": "stdio",
  "command": "node",
  "args": ["/Users/rkondis/personalwork/mcp-bybit-node/dist/index.js"],
  "env": {
    "ACCESS_KEY": "your_access_key_here",
    "SECRET_KEY": "your_secret_key_here",
    "DEMO": "true"
  }
}'

Method 3: Using working directory (reads .env automatically)

claude mcp add-json bybit-node '{
  "type": "stdio",
  "command": "node",
  "args": ["dist/index.js"],
  "cwd": "/Users/rkondis/personalwork/mcp-bybit-node",
  "env": {
    "DEMO": "true"
  }
}'

This method uses the existing .env file in the working directory.

Available Tools

  1. Market Data:

    • get_tickers - Get ticker information
    • get_orderbook - Get orderbook data
    • get_kline - Get K-line (candlestick) data
    • get_instruments_info - Get exchange information
  2. Account Management:

    • get_wallet_balance - Get wallet balance
    • get_positions - Get position information
    • get_api_key_information - Get API key information
  3. Trading Operations:

    • validate_order_quantity - Validate order quantity against trading rules
    • calculate_position_size - Calculate optimal position size based on risk management
    • calculate_trailing_stop - Calculate trailing stop loss with breakeven and profit protection
    • detect_position_mode - Detect position mode and get recommended positionIdx
    • place_order - Execute order with automatic position mode detection
    • place_order_with_trailing_stop - Place order with built-in trailing stop loss
    • cancel_order - Cancel order
    • get_order_history - Get order history
    • get_open_orders - Get open orders
  4. Position Management:

    • set_leverage - Set leverage for a specific symbol
    • set_trading_stop - Set trading stop
    • set_margin_mode - Set margin mode
  5. Utility:

    • get_access_key - Get access key from environment
    • get_secret_key - Get secret key from environment

Testing

Test the MCP server:

cd /Users/rkondis/personalwork/mcp-bybit-node
node test-mcp.js

Test trade execution:

cd /Users/rkondis/personalwork/mcp-bybit-node
node test-order.js

Usage Examples

Validate order before placing:

// Check if $80 worth of ETHUSDT is valid
validate_order_quantity("linear", "ETHUSDT", 80)
// Returns: { validatedQty: "0.02", estimatedCost: "73.18", adjustments: [] }

Place a validated order:

// Place market buy order for ETHUSDT
place_order("linear", "ETHUSDT", "Buy", "Market", "0.02", positionIdx="0")

Calculate position size with risk management:

// Calculate position size for 2% risk with $1000 balance
calculate_position_size("linear", "ETHUSDT", 1000, 2, 3500, 3600, 10)
// Returns: {
//   recommendedQty: "0.57",
//   riskAmount: 20,
//   positionValue: 2052,
//   takeProfitSuggestion: 3800,
//   warnings: []
// }

Calculate trailing stop loss with profit protection:

// Calculate trailing stop for a long position
calculate_trailing_stop("linear", "ETHUSDT", 3600, 3750, "Buy", 3500, 50)
// Returns: {
//   newStopLoss: 3700,
//   trailingActivated: true,
//   breakevenProtection: true,
//   profitProtected: 0,
//   recommendations: {
//     shouldUpdateStop: true,
//     protectionLevel: "breakeven",
//     reasoning: "Breakeven protection activated - stop moved to entry price"
//   }
// }

Place order with trailing stop loss:

// Place market buy order with 50 USDT trailing stop
place_order_with_trailing_stop("linear", "ETHUSDT", "Buy", "Market", "0.02", null, "50")
// Returns: Order placed with automatic trailing stop that follows price movement

Set leverage:

// Set 10x leverage for ETHUSDT
set_leverage("linear", "ETHUSDT", "10", "10")

Check positions:

// Get all linear positions
get_positions("linear")

Key Improvements Over Python Version

  • ✅ No signature errors - Perfect authentication with Bybit API
  • ✅ Smart validation - Automatic position size and mode validation
  • ✅ Better error handling - Comprehensive error messages and recovery
  • ✅ TypeScript support - Full type safety and IntelliSense

Troubleshooting

If Claude MCP fails to start:

  1. Check file permissions:

    ls -la /Users/rkondis/personalwork/mcp-bybit-node/dist/index.js
    # Should show: -rwxr-xr-x (executable)
    
  2. Test server directly:

    cd /Users/rkondis/personalwork/mcp-bybit-node
    node dist/index.js
    # Should show: "Bybit MCP Server (Node.js) running on stdio"
    
  3. Check environment variables:

    cat /Users/rkondis/personalwork/mcp-bybit-node/.env
    
  4. Use the startup script:

    /Users/rkondis/personalwork/mcp-bybit-node/start-server.sh
    

Security Notes

  • Always use DEMO=true for testing
  • Never commit API keys to version control
  • Use environment variables for sensitive data
  • Test thoroughly in demo mode before production use

Support

The server includes comprehensive logging and error handling. Check the console output for detailed information about any issues.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选