Skip to content

1cbyc/1cbyc-trading-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

82 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

MT5 Trading Bot Portfolio Project

๐Ÿš€ Project Overview

This is a comprehensive MetaTrader 5 (MT5) trading bot system designed for both demo and real trading environments. The project demonstrates advanced Python development, financial technology integration, web interface development, and process management.

๐Ÿ“ Project Structure

mt5-trading-bot/
โ”œโ”€โ”€ demo-trading/           # Demo trading environment (safe for testing)
โ”‚   โ”œโ”€โ”€ main.py            # Demo bot implementation
โ”‚   โ”œโ”€โ”€ config.py          # Demo configuration
โ”‚   โ””โ”€โ”€ .env               # Demo credentials (gitignored)
โ”œโ”€โ”€ real-trading/          # Real trading environment (protected)
โ”‚   โ”œโ”€โ”€ main.py            # Real bot implementation
โ”‚   โ”œโ”€โ”€ config.py          # Real configuration
โ”‚   โ””โ”€โ”€ .env               # Real credentials (gitignored)
โ”œโ”€โ”€ web-interface/         # Flask web dashboard
โ”‚   โ”œโ”€โ”€ app.py             # Main Flask application
โ”‚   โ”œโ”€โ”€ templates/         # HTML templates
โ”‚   โ””โ”€โ”€ static/            # CSS/JS assets
โ”œโ”€โ”€ bot_manager.py         # Process-based bot management
โ”œโ”€โ”€ requirements.txt       # Python dependencies
โ””โ”€โ”€ README.md             # This file

๐Ÿ—๏ธ Architecture Overview

1. Separation of Concerns

  • Demo Trading: Safe environment for testing strategies without financial risk
  • Real Trading: Protected environment with real money trading capabilities
  • Web Interface: Centralized control and monitoring dashboard
  • Bot Manager: Process-based management to avoid threading issues

2. Security Implementation

  • Real trading credentials are gitignored and protected
  • Demo environment isolated from real trading
  • Environment-specific configurations
  • Process isolation for safety

3. Technology Stack

  • Backend: Python 3.x with MT5 integration
  • Web Framework: Flask for dashboard
  • Process Management: Subprocess for bot isolation
  • Real-time Communication: WebSocket-like updates via file monitoring

๐Ÿ”ง Technical Implementation

MT5 Integration

# Key MT5 functions used:
mt5.initialize()           # Initialize MT5 connection
mt5.login()               # Authenticate with broker
mt5.symbol_info()         # Get symbol information
mt5.order_send()          # Execute trades
mt5.account_info()        # Get account details

Process-Based Architecture

  • Why Process-Based?: Avoids Python's GIL limitations and threading issues
  • Benefits:
    • True parallel execution
    • Isolated memory spaces
    • Crash isolation
    • Better resource management

Web Interface Features

  • Real-time Monitoring: Live account balance and trade updates
  • Bot Control: Start/stop bots remotely
  • Manual Trading: Execute trades through web interface
  • Log Viewing: Real-time log monitoring
  • Responsive Design: Works on desktop and mobile

๐Ÿš€ Getting Started

Prerequisites

  • Python 3.8+
  • MetaTrader 5 terminal
  • Broker account (demo or real)

Installation

# Clone the repository
git clone <repository-url>
cd mt5-trading-bot

# Install dependencies
pip install -r requirements.txt

# Set up environment files
cp demo-trading/.env.example demo-trading/.env
cp real-trading/.env.example real-trading/.env

Configuration

  1. Demo Trading Setup:

    cd demo-trading
    # Edit .env with demo account credentials
  2. Real Trading Setup:

    cd real-trading
    # Edit .env with real account credentials
    # โš ๏ธ WARNING: Real money trading

๐ŸŽฏ Usage Examples

Running Individual Bots

# Demo bot
python demo-trading/main.py

# Real bot (requires confirmation)
python real-trading/main.py

Web Interface

# Start the web dashboard
python web-interface/app.py

# Access at http://localhost:5000

Bot Manager

# Start the process-based bot manager
python bot_manager.py

# Features:
# - Start/stop bots
# - Monitor multiple bots
# - Process isolation
# - Crash recovery

๐Ÿ“Š Key Features Explained

1. Trading Strategy Implementation

  • Technical Analysis: RSI, Moving Averages, MACD
  • Risk Management: Stop-loss, take-profit, position sizing
  • Market Analysis: Real-time price monitoring
  • Order Management: Market and limit orders

2. Safety Mechanisms

  • Demo/Real Separation: Complete isolation between environments
  • Confirmation Dialogs: Real trading requires explicit confirmation
  • Error Handling: Comprehensive exception handling
  • Logging: Detailed logging for debugging and auditing

3. Web Dashboard Features

  • Real-time Updates: Live account and trade monitoring
  • Bot Control: Remote start/stop functionality
  • Manual Trading: Web-based trade execution
  • Log Monitoring: Real-time log viewing
  • Responsive UI: Mobile-friendly interface

๐Ÿ”’ Security Considerations

Credential Protection

# .gitignore entries
real-trading/.env
demo-trading/.env
*.log
__pycache__/

Environment Isolation

  • Separate configurations for demo and real trading
  • Process-based isolation prevents cross-contamination
  • Environment-specific error handling

Trading Safety

  • Demo environment for strategy testing
  • Real trading requires explicit confirmation
  • Comprehensive error handling and logging

๐Ÿงช Testing and Development

Demo Environment

  • Safe for testing strategies
  • No financial risk
  • Identical functionality to real trading
  • Perfect for development and learning

Real Environment

  • Requires careful testing in demo first
  • Real money trading capabilities
  • Enhanced safety measures
  • Professional-grade error handling

๐Ÿ“ˆ Performance Monitoring

Key Metrics

  • Win Rate: Percentage of profitable trades
  • Profit Factor: Ratio of gross profit to gross loss
  • Drawdown: Maximum peak-to-trough decline
  • Sharpe Ratio: Risk-adjusted returns

Logging and Debugging

  • Comprehensive logging system
  • Real-time log monitoring via web interface
  • Error tracking and reporting
  • Performance analytics

๐ŸŽ“ Learning Outcomes

Technical Skills Demonstrated

  1. Python Development: Advanced Python programming
  2. Financial Technology: MT5 API integration
  3. Web Development: Flask web application
  4. Process Management: Subprocess handling
  5. Real-time Systems: Live data processing
  6. Security: Credential management and isolation

Software Engineering Principles

  1. Separation of Concerns: Clear module boundaries
  2. Error Handling: Comprehensive exception management
  3. Logging: Detailed audit trails
  4. Configuration Management: Environment-specific settings
  5. Process Isolation: Safety through separation

Financial Knowledge

  1. Trading Concepts: Technical analysis, risk management
  2. Market Understanding: Real-time data processing
  3. Broker Integration: MT5 platform knowledge
  4. Risk Management: Position sizing, stop-losses

๐Ÿš€ Deployment Options

Local Development

  • Flask web server for local access
  • Process-based bot management
  • Real-time monitoring capabilities

Production Deployment

  • VPS or cloud server recommended
  • Process management with systemd
  • Reverse proxy (nginx) for web interface
  • SSL certificates for security

๐Ÿ“š Interview Talking Points

Technical Architecture

  • "I designed a process-based architecture to avoid Python's GIL limitations"
  • "Implemented complete separation between demo and real trading environments"
  • "Created a web interface for real-time monitoring and control"

Security Implementation

  • "All real trading credentials are gitignored and protected"
  • "Process isolation prevents cross-contamination between environments"
  • "Real trading requires explicit user confirmation"

Problem Solving

  • "Resolved threading issues by using subprocess management"
  • "Implemented comprehensive error handling for financial applications"
  • "Created a responsive web interface for mobile and desktop access"

Learning Journey

  • "Started with basic MT5 integration and evolved to a full trading system"
  • "Learned about financial technology and real-time data processing"
  • "Gained experience with web development and process management"

๐Ÿ”ฎ Future Enhancements

Potential Improvements

  1. Machine Learning: AI-powered trading strategies
  2. Multi-Broker Support: Integration with other platforms
  3. Advanced Analytics: Performance dashboards
  4. Mobile App: Native mobile application
  5. Cloud Deployment: AWS/Azure integration

Scalability Considerations

  1. Database Integration: PostgreSQL for trade history
  2. Message Queues: Redis for real-time updates
  3. Microservices: Service-oriented architecture
  4. Containerization: Docker deployment

๐Ÿ“ž Support and Contact

For questions about this project:

  • Review the code comments for implementation details
  • Check the logs for debugging information
  • Test thoroughly in demo environment before real trading

โš ๏ธ Disclaimer: This is a portfolio project for educational purposes. Real trading involves financial risk. Always test strategies thoroughly in demo environments before using real money.

About

this is the base version of the bot i will be building - decided to make a new version for just deriv/mt5 on https://github.com/1cbyc/deriv-mt5-bot

Resources

Stars

Watchers

Forks

Packages

No packages published