bybit-trading-mcp

bybit-trading-mcp

Enables AI tools to execute trades and fetch market data across six crypto exchanges via natural language or API, with dual Telegram and MCP interfaces.

Category
访问服务器

README

Bybit V5 Trading Bot + Multi-Exchange MCP Server

🚀 Unified Trading Bot dengan dual interface: Telegram Bot + MCP Server untuk integration dengan AI tools seperti Claude.

🎯 Overview

Sistem ini menggabungkan:

  • MCP Server (Model Context Protocol) dengan FastAPI framework
  • Telegram Bot untuk mobile trading interface
  • Multi-Exchange Support untuk 6 major exchanges
  • Natural Language Processing untuk trading commands
  • Machine Learning integration untuk market analysis

✨ Key Features

🤖 Dual Interface

  • Telegram Bot: Mobile-first interface dengan natural language support
  • MCP Server: HTTP API untuk integration dengan Claude/AI tools
  • Unified Backend: Same trading engine untuk kedua interface

🌐 Multi-Exchange Support

  • Bybit (Primary): Full V5 API - public + private endpoints
  • Binance: Public market data API
  • KuCoin: Public market data API
  • OKX: Public market data API
  • Huobi: Public market data API
  • MEXC: Public market data API

🧠 Intelligent Features

  • Natural Language: "What's Bitcoin price?" → API calls
  • Price Comparison: Real-time comparison across exchanges
  • API Documentation: Contextual help dalam setiap response
  • Error Handling: User-friendly error messages

🚀 Quick Start

1. Requirements

  • Python 3.11+
  • Create .env file (see configuration below)

2. Installation

git clone https://github.com/yourusername/bybit-trading-bot.git
cd bybit-trading-bot
pip install -r requirements.txt

3. Configuration

Create .env file:

# Required
TELEGRAM_BOT_TOKEN=your_telegram_token

# Optional for private endpoints
BYBIT_API_KEY=your_bybit_key
BYBIT_API_SECRET=your_bybit_secret
BYBIT_PUBLIC_ONLY=true  # Set false for trading

# LLM Integration
ZAI_API_KEY=your_llm_api_key
ZAI_BASE_URL=https://api.novita.ai/openai  # Default Novita GPT-OSS

# Optional
BOT_AUTH_REQUIRED=false
LLM_ROUTER_MODEL=your_router_model

4. Run the System

Option 1: Telegram Bot Only

python -m src.main

Option 2: MCP Server Only

python tools/mcp_server.py
# Server: http://localhost:8001

Option 3: Both (Recommended)

# Terminal 1: Start MCP Server
python tools/mcp_server.py

# Terminal 2: Start Telegram Bot
python -m src.main

📱 Telegram Bot Usage

Commands:

/start              # Initialize bot
/help               # Full command guide
/status             # System status

# Market Data
/price BTCUSDT bybit       # Get BTC price from Bybit
/price ETHUSDT binance     # Get ETH price from Binance  
/compare BTCUSDT           # Compare BTC across exchanges
/exchanges                 # List available exchanges

# Account (requires API key)
/balance                   # Wallet balance
/positions                 # Open positions

Natural Language:

"Harga Bitcoin sekarang?"     # → Bybit BTC price
"Compare ETH prices"          # → Multi-exchange comparison  
"Show me SOL on KuCoin"       # → KuCoin SOL price
"What's my balance?"          # → Wallet balance

🔌 MCP Server Integration

For Claude Desktop:

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "bybit-trading": {
      "command": "python",
      "args": ["/path/to/bybit-trading-bot/tools/mcp_server.py"],
      "env": {
        "BYBIT_PUBLIC_ONLY": "true"
      }
    }
  }
}

Direct HTTP Usage:

# Get Bybit ticker
curl "http://localhost:8001/bybit/tickers?category=spot&symbol=BTCUSDT"

# Compare prices across exchanges  
curl "http://localhost:8001/exchanges/compare-prices?symbol=BTCUSDT&exchanges=bybit,binance,kucoin"

# Get API documentation
curl "http://localhost:8001/api-docs?section=market"

🏗️ Project Structure

src/
├── main.py                    # Unified Telegram bot dengan MCP integration
├── bybit_client.py           # Bybit V5 API implementation
├── mcp_telegram_client.py    # MCP client untuk Telegram integration
├── llm.py                    # Natural language processing
├── telegram_bot.py           # Telegram bot core
├── exchange_client.py        # Multi-exchange API client
├── strategy.py              # Trading strategies  
├── model.py                 # Machine learning models
└── config.py                # Configuration management

tools/
└── mcp_server.py            # FastAPI-MCP server

scripts/
├── debug_llm.py             # LLM debugging
├── debug_tool_calls.py      # Tool call debugging
├── debug_specific_query.py  # Query testing
└── simple_llm_test.py       # LLM sanity test

docs/
├── MCP_TELEGRAM_INTEGRATION.md  # Detailed system documentation
├── natural_language_implementation.md
└── multi_exchange.md

data/
└── auth.json                # Local runtime data

🧪 Testing & Debugging

Test Individual Components:

# Test LLM integration
python scripts/debug_llm.py
python scripts/simple_llm_test.py

# Test tool calls
python scripts/debug_tool_calls.py

# Test specific queries
python scripts/debug_specific_query.py

# Test natural language
python test_true_natural.py

Test MCP Server:

# Start server
python tools/mcp_server.py

# Test endpoints
curl http://localhost:8001/
curl "http://localhost:8001/bybit/tickers?category=spot"
curl "http://localhost:8001/exchanges/compare-prices?symbol=BTCUSDT"

🎯 What's New in This Version

Complete MCP Rewrite: Migrated dari custom implementation ke FastAPI-MCP framework
Multi-Exchange Integration: 6 major exchanges dengan unified interface
Dual Interface: Telegram Bot + MCP Server dalam satu system
API Documentation Context: Contextual help dalam setiap response
Enhanced Error Handling: User-friendly error messages
Natural Language: Advanced LLM integration untuk command parsing

🔒 Security & Best Practices

API Key Management:

  • Use environment variables untuk API keys
  • Never commit keys to repository
  • Use testnet untuk development
  • BYBIT_PUBLIC_ONLY=true untuk safe testing

Rate Limiting:

  • Built-in rate limiting untuk semua exchanges
  • Auto-retry dengan exponential backoff
  • Request queueing untuk high-volume usage

📄 Architecture

┌─────────────────┐    ┌──────────────────┐    ┌────────────────┐
│   Telegram Bot  │◄──►│   MCP Client     │◄──►│   MCP Server   │
│                 │    │                  │    │                │
│ • Commands      │    │ • HTTP Client    │    │ • FastAPI      │
│ • Natural Lang  │    │ • Response Format│    │ • Multi-CEX    │
│ • LLM Chat      │    │ • Error Handling │    │ • API Docs     │
└─────────────────┘    └──────────────────┘    └────────────────┘
                                                        │
                                                        ▼
                              ┌────────────────────────────────────┐
                              │         Exchange APIs              │
                              │ • Bybit (V5)  • Binance          │
                              │ • KuCoin      • OKX               │
                              │ • Huobi       • MEXC              │
                              └────────────────────────────────────┘

🤝 Contributing

  1. Fork the repository
  2. Create feature branch
  3. Implement changes dengan proper tests
  4. Update documentation
  5. Submit pull request

📄 License

MIT License - see LICENSE file for details.

⚠️ Disclaimer

This software is for educational purposes. Trading cryptocurrencies involves substantial risk. Always do your own research and never invest more than you can afford to lose.


🚀 Happy Trading with Multi-Exchange MCP Integration!

  • To enable trading and other private endpoints, set BYBIT_PUBLIC_ONLY=false and provide valid API keys.
  • For faster small-talk replies, consider a lighter LLM_ROUTER_MODEL and smaller LLM_MAX_TOKENS (e.g., 512–2048).

Run MCP Server (optional)

  • Install deps: pip install -r requirements.txt
  • Start server: python -m tools.mcp_server
  • The server exposes two example tools: health_check and echo. Extend to call ZaiClient or Bybit.

Telegram Commands

  • /start and /help: Info bantuan.
  • /time: Server time Bybit (public, production).
  • /ticker <category> [symbol]: Ticker market V5, kategori spot|linear|inverse|option.
  • /balance [COIN]: Wallet balance V5 (private, default accountType=UNIFIED).
  • /signal <category> <symbol> <interval> <mode>: Prediksi XGBoost (scalping/swing) dari kline terkini.
  • /ask <pertanyaan>: Natural language router → LLM memilih aksi (tickers, kline, orderbook, trades, balance, positions, orders, create/cancel order) dan bot mengeksekusi.

License Issues

docs: polish README + add examples

  • Added badges (License, Issues)
  • Added Quickstart and examples/get_price.py
  • Added CHANGELOG and CONTRIBUTING

Quickstart

python examples/get_price.py

推荐服务器

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

官方
精选