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
Visit Server

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

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured