MEXC
MEXC⚡: High-Performance Crypto Trading Bot for MEXC Exchange
Install / Use
/learn @n-azimi/MEXCREADME
MEXC⚡: High-Performance Crypto Trading Bot for MEXC Exchange
<!-- [](#) --> <!-- [](#) -->📋 Table of Contents
- 🎯 Overview
- 🏗️ Architecture & Component Analysis
- ⚙️ Installation & Setup
- 🛠️ Configuration Management
- 📁 Code Structure & Usage
- 📄 License
- 🔔 Important Notices & Risk Warnings
- 💖 Support & Donations
🎯 Overview
Purpose & Functionality
MEXC⚡ is a complex, production-ready trading bot designed for the MEXC cryptocurrency exchange. The bot provides automated trading capabilities with advanced risk management features, focusing on high-performance execution and comprehensive position monitoring.
Core Capabilities:
- 🤖 Automated Trading: Execute buy/sell orders with precise timing and conditions
- 🎯 Sequential Bracket Orders: Advanced strategy combining entry, stop-loss, and take-profit orders
- 🛡️ Risk Management: Automatic stop-loss placement and position monitoring
- ⏰ Time-Based Trading: Configurable trading windows for specific time periods
- 💵 USDT-Based Positioning: Simplified position sizing using dollar amounts
- 📊 Real-Time Monitoring: Continuous position tracking with protective order management
🏗️ Architecture & Component Analysis
Architecture Overview
The MEXC⚡ trading bot follows a modular, async-first architecture designed for high performance and reliability:
graph TD
%% External Entities on top
User((User))
MEXC((MEXC Exchange))
%% Organize in logical groups using positioning
%% Core Components - Center
subgraph Core [Core Trading System]
TradingBot["TradingBot (main.py)"]
TradingEngine[trading_engine.py]
MexcClient[mexc_client.py]
end
%% Entry Points - Left
subgraph Entry [Entry Points]
RunBot[run_bot.py]
Main[main.py]
end
%% Configuration - Right
subgraph Conf [Configuration]
EnvFile[(".env")]
Config[config.py]
end
%% Data & Utilities - Bottom
subgraph Data [Data & Utilities]
RunList[("runlist.txt")]
TradeablePairs[("tradeable_pairs.txt")]
FindTradeables[find_tradeables.ps1]
TestAPI[test_api.py]
LogFiles[("logs/*.log")]
end
%% Core relationships
TradingBot --> |"Initializes"| TradingEngine
TradingBot --> |"Initializes"| MexcClient
TradingEngine --> |"Uses"| MexcClient
%% Entry point relationships
RunBot --> |"Launches"| Main
Main --> |"Creates"| TradingBot
%% Configuration relationships
EnvFile --> |"Loads Environment Variables"| Config
Config --> |"Creates BotConfig"| TradingBot
Config --> |"Creates MexcCredentials"| MexcClient
Config --> |"Creates TradingParams"| TradingEngine
%% Data Store relationships
FindTradeables --> |"Generates"| TradeablePairs
%% External Connections
User --> |"Run"| RunBot
User --> |"Defines the runlist"| RunList
RunBot --> |"Executes Commands from"| RunList
MEXC <--> |"API Requests/Responses"| MexcClient
%% Data Flows
MexcClient --> |"Market Data"| TradingEngine
MexcClient --> |"Order Status"| TradingEngine
TradingEngine --> |"Trading Signals"| TradingBot
TradingBot --> |"Logs"| LogFiles
TradingBot --> |"Status Updates"| User
TradeablePairs --> |"Provides Available Pairs"| User
TestAPI --> |"API Status"| User
%% Key Methods
TradingBot --> |"place_buy_order()"| TradingEngine
TradingEngine --> |"place_limit_buy_order()"| MexcClient
TradingEngine --> |"monitor_positions()"| MexcClient
%% Styling
classDef external fill:#f96,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5
classDef process fill:#9cf,stroke:#333,stroke-width:1px
classDef datastore fill:#fc9,stroke:#333,stroke-width:1px,stroke-dasharray: 3 3
classDef configStyle fill:#9f9,stroke:#333,stroke-width:1px
class User,MEXC external
class Main,RunBot,TradingBot,TradingEngine,MexcClient,FindTradeables,TestAPI,Config process
class TradeablePairs,LogFiles datastore
class EnvFile,RunList configStyle
Component Breakdown
1. 🔰 main.py
- Role: CLI interface and application orchestration
- Key Functions:
- Command-line argument parsing
- Bot lifecycle management
- Time-based execution scheduling
- Error handling and graceful shutdown
2. 📈 Trading Engine (trading_engine.py)
- Role: Core trading logic and strategy execution
- Key Functions:
- Order placement and management
- USDT-based quantity calculation
- Stop-loss automation
- Position monitoring and lifecycle management
- Sequential bracket order implementation
- Risk management protocols
3. 🔌 MEXC Client (mexc_client.py)
- Role: High-performance MEXC API client
- Key Functions:
- Async HTTP client with connection pooling
- HMAC SHA256 authentication
- Rate limiting and request throttling
- Symbol validation and exchange info retrieval
- Multiple order type support
- Error handling and retry mechanisms
4. ⚙️ Configuration (config.py)
- Role: Configuration management and validation
- Key Functions:
- Environment variable loading
- Default value management
- Credential handling
⚙️ Installation & Setup
📋 Prerequisites
- 🐍 Python 3.8+ (recommended: Python 3.9 or higher)
- 🏦 MEXC Exchange Account with API access enabled
- 🔑 Valid API credentials with trading permissions
- 💻 Windows/Linux compatible
💿 Step-by-Step Installation
1. Environment Setup
# Create virtual environment (recommended)
python -m venv mexc_env
source mexc_env/bin/activate # Linux
# or
mexc_env\Scripts\activate # Windows
# or
conda activate your_environment_name # If you're using conda
# Install dependencies
pip install -r requirements.txt
2. API Configuration
# Copy environment template
cp env_example.txt .env
# Edit .env with your credentials
# Required:
MEXC_API_KEY=your_actual_api_key_here
MEXC_SECRET_KEY=your_actual_secret_key_here
# Optional but recommended:
DRY_RUN=true # Start in test mode
TRADING_SYMBOL=XRPUSDT # Default trading pair
TRADING_QUANTITY=2.0 # Default order size (USDT)
3. Verification
# Test MEXC API
python test_api.py
# Test API connectivity
python main.py --action test-permissions
# Validate your trading symbol
python main.py --action validate --symbol XRPUSDT
# Find tradeable symbols
python main.py --action symbols --search BTC
Execute the PowerShell script below to generate a tradable_pairs.txt file.
This file will list all symbols that support spot trading on the MEXC exchange.
.\find_tradeables.ps1
📦 Dependencies Analysis
Core Dependencies:
requests>=2.31.0
aiohttp>=3.9.0
asyncio>=3.4.3
python-dotenv>=1.0.0
pydantic>=2.5.0
pytz>=2023.3
schedule>=1.2.0
websockets>=12.0
cryptography>=41.0.0
pandas>=2.1.0
numpy>=1.25.0
loguru>=0.7.0
| Package | Purpose |
|---------|---------|
| 🌐 aiohttp | High-performance async HTTP client |
| ✅ pydantic | Data validation and configuration management |
| 📝 loguru | Advanced logging with rotation |
| 🔐 cryptography | HMAC authentication for MEXC API |
| 🌍 python-dotenv | Environment variable management |
🛠️ Configuration Management
🌍 Environment Variables Reference
API Credentials (Required)
MEXC_API_KEY=your_api_key
MEXC_SECRET_KEY=your_secret_key
MEXC_PASSPHRASE=your_passphrase_if_required # Optional passphrase
Trading Parameters
TRADING_SYMBOL=XRPUSDT # Trading pair symbol
TRADING_QUANTITY=2.0 # Order quantity
QUANTITY_IS_USDT=true # true: quantity in USDT, false: base currency
STOP_LOSS_PERCENTAGE=2.0 # Stop-loss (0.1% to 50%)
TAKE_PROFIT_PERCENTAGE=5.0 # Take-profit (0.1% to 100%, optional)
Risk Management
DRY_RUN=true # Test mode without real trades
RATE_LIMIT_RPS=10.0 # API rate limit (requests/second)
LOG_LEVEL=INFO # Logging level (INFO, DEBUG, etc.)
