Crypto Automation Bot
A headless, multi-exchange automated assistant designed for cryptocurrency futures trading with enterprise-grade automation for three critical operations: automated profit-taking, funds management with withdrawal automation, and low-balance alerts.
Project Overview
The Cryptocurrency Trading Automation Bot is a headless, multi-exchange automated assistant designed for cryptocurrency futures trading. It provides enterprise-grade automation for three critical trading operations: automated profit-taking, funds management with withdrawal automation, and low-balance alerts. The bot operates as a 24/7 monitoring service, executing complex financial operations with precision and reliability.
Key Characteristics
- Multi-Exchange Support: Binance and Bybit (via CCXT unified API)
- Production-Ready: Comprehensive error handling, retry mechanisms, and logging
- Security-First: API validation, credential protection, withdrawal safeguards
- Fully Configurable: JSON-based configuration system with extensive validation
- Extensible Architecture: Class-based design allowing easy feature additions
- Cross-Platform: Runs on Windows, Linux, and macOS
- 24/7 Operation: Systemd service support for continuous monitoring
Core Features
Automated Profit-Taking Bot
Purpose: Monitors isolated margin positions and automatically closes them when profit targets are reached.
How It Works:
- Continuously monitors specified trading pairs (e.g., BTC/USDT)
- Tracks unrealized Profit & Loss (PnL) for each position
- Closes positions via market orders when PnL ≥ configured profit target
- Validates that positions are isolated margin to prevent cross-margin accidental closures
- Sends email notifications upon successful position closure
- Implements reduce-only orders to prevent position reversals
Funds Management & Withdrawal Automation
Purpose: Automatically transfers profits, converts assets, and withdraws to external wallets.
How It Works:
- Monitors futures account balance for a specified asset (typically USDT)
- Triggers automation when balance exceeds configured threshold
- Transfers specified amount from futures trading account to spot account
- Converts asset via market order on spot market
- Withdraws converted assets to external wallet via specified network
- Sends email notifications at each stage of the process
Low Balance Alert System
Purpose: Sends email notifications when account balance drops below threshold without open positions (potential liquidation indicator).
How It Works:
- Fetches futures account balance in USDT
- Checks for any open positions across all symbols
- Triggers alert ONLY when both conditions are met: balance is below threshold AND no positions are open
- Implements cooldown mechanism to prevent alert spam (60 minutes default)
- Tracks alert time per exchange to avoid duplicate notifications
Technical Specifications
| Category | Details |
|---|---|
| Technology Stack | CCXT library (v4.0.0+), Python standard libraries (json, time, smtplib, logging), Systemd service integration |
| Performance Metrics | Resource usage: 50-100MB memory, <1% CPU; 6-7 API calls per cycle; 30-second cycle interval; CCXT built-in rate limiting enabled |
| Security Features | 7-layer configuration validation, API permission restrictions, IP whitelisting requirements, withdrawal address verification, credential protection via file permissions |
Architecture Overview
The bot implements a robust class-based design centered around the CryptoAutomationBot class. This architecture enables separation of concerns through modular components that handle exchange initialization, configuration validation, core monitoring functions, and utility operations. The system employs a main execution loop that cycles through enabled exchanges and executes all three core features with comprehensive error handling and retry mechanisms.
Deployment Guide
- Prerequisites: Python 3.7+, pip package manager, CCXT library (4.0.0+), valid exchange API keys, email account with SMTP access
- Windows Deployment: Create Anaconda environment, install dependencies, configure config.json, run validation tests, execute bot
- Linux Deployment: Install Python and pip, create virtual environment, install dependencies, set secure file permissions for config.json, run validation tests
- Systemd Service Setup: Configure cryptobot.service file with proper paths and user permissions, enable service for automatic startup on boot
- Background Execution: Use nohup or screen for persistent operation when SSH session ends
Configuration
Configuration is managed through a single JSON file with comprehensive validation:
{
"global_settings": {
"check_interval_seconds": 30
},
"binance": {
"enabled": true,
"api_key": "YOUR_API_KEY_HERE",
"api_secret": "YOUR_API_SECRET_HERE",
"profit_taker": {
"enabled": true,
"symbol": "BTC/USDT",
"profit_target_usd": 50.0
},
"funds_automation": {
"enabled": true,
"trigger_asset": "USDT",
"trigger_threshold": 100.0,
"transfer_amount": 50.0,
"convert_to_asset": "BTC",
"withdraw_address": "bc1q...",
"withdraw_network": "BTC",
"min_withdraw_amount": 0.0001
}
},
"email_settings": {
"enabled": true,
"smtp_server": "smtp.gmail.com",
"smtp_port": 587,
"sender_email": "[email protected]",
"sender_password": "16-digit app password",
"receiver_email": "[email protected]"
}
}
Monitoring & Maintenance
The bot includes comprehensive logging to bot.log with timestamped entries for all operations. Key monitoring patterns include startup confirmation messages, exchange initialization status, profit target triggers, withdrawal initiations, and low balance alerts. Error patterns help identify authentication failures, network issues, and configuration problems.
[2025-11-14 10:30:45] INFO: Configuration loaded successfully [2025-11-14 10:30:47] INFO: [binance] ✓ PROFIT TARGET REACHED! PnL: $50.00 >= $50.00 [2025-11-14 10:30:48] INFO: [binance] Position closed successfully! Order ID: 123456789 [2025-11-14 10:31:15] INFO: ✓ Withdrawal initiated! Amount: 0.0012 BTC to bc1q... [2025-11-14 10:35:22] ⚠️ LOW BALANCE ALERT! Balance: $8.50 below threshold of $10.00
Real-World Usage Scenarios
Day Trader
Uses profit_taker to automatically close winning positions during active trading hours. Enables email alerts to receive immediate notifications when targets are hit. Runs on laptop during market hours to reduce need for constant chart monitoring while maintaining trading discipline.
Long-Term Position Holder
Opens isolated margin position with high leverage (e.g., 50x). Sets profit_target_usd to desired profit amount. Enables balance_alert for liquidation warning protection. Runs 24/7 via systemd on VPS to ensure positions are managed even during sleep or absence. Receives email notifications when positions close automatically.
Profit Extraction Strategy
Runs profit_taker to generate consistent profits from trading positions. Enables funds_automation to convert profits to BTC or other preferred assets. Automatically withdraws profits to hardware wallet on regular schedule. Reduces exchange exposure while creating passive income stream with full automation.
Risk Management System
Monitors multiple positions across Binance and Bybit simultaneously. Low balance alert detects unexpected liquidations or unauthorized withdrawals. Email notification enables rapid response to emergency situations. Prevents silent account losses and provides peace of mind during volatile market conditions.
Comparison with Alternatives
| Aspect | Alternative Solutions | Our Solution |
|---|---|---|
| Manual Trading | Requires constant monitoring, emotional decision-making, inconsistent execution | 24/7 operation without human intervention, consistent profit-taking discipline, instant notifications |
| Exchange Built-in Automation | Limited to single exchange, restricted functionality, vendor lock-in | Multi-exchange support in single bot, complex fund flows, open-source auditable code, full parameter control |
| Commercial Trading Bots | Subscription fees, percentage of profits taken, lack of transparency, API rate limiting | No subscription fees, no profit sharing, fully transparent source code, direct exchange API access |