Skip to content

A complete bridge system that connects MetaTrader 5 to modern web applications through REST APIs and WebSocket streaming. Built with MQL5, Node.js, and React.

License

Notifications You must be signed in to change notification settings

mobjoy0/mt5-bridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

24 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MT5 Bridge

MT5 Node.js React License

A complete bridge system that connects MetaTrader 5 to modern web applications through REST APIs and WebSocket streaming. Built with MQL5, Node.js, and React.

🎯 Overview

MT5 Bridge enables external applications to interact with MetaTrader 5 in real-time by exposing trading and market data through a multi-layer architecture:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   React     β”‚  HTTP   β”‚   Node.js   β”‚  HTTP   β”‚   MT5 EA    β”‚
β”‚  Dashboard  │───────▢│   Backend    │───────▢│SocketBridge β”‚
β”‚ (Port 8002) β”‚  :8891  β”‚ (Port 8891) β”‚  :8890  β”‚ (Port 8890) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
      β”‚                                                 β”‚
      β”‚                                                 β”‚
      └─────────────── WebSocket β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      (Direct Connection)

✨ Key Features

  • πŸ”Œ Real-Time Streaming β€” WebSocket connection for live price updates
  • 🌐 REST API β€” Complete HTTP API for trading and account management
  • πŸ“Š Market Data β€” Access to prices, quotes, and symbol information
  • πŸ’° Account Management β€” Real-time balance, equity, and margin data
  • πŸ“ˆ Order Management β€” Place, modify, and close orders programmatically
  • πŸ“‰ Price History β€” Historical data with interactive charts
  • πŸ“€ CSV Export β€” Export market data for analysis
  • πŸ”’ Lightweight β€” No external dependencies, runs entirely within MT5

Architecture

The project consists of four main components:

1. MetaTrader 5 Expert Advisor β†’ πŸ“– Documentation

An embedded HTTP and WebSocket server that runs inside the MT5 terminal, exposing trading and market data through REST API (port 8890) and WebSocket connections.

2. Node.js Backend β†’ πŸ“– Documentation

A TypeScript-based middleware that proxies requests between the frontend and MT5 EA, providing Swagger documentation and error handling (port 8891).

3. React Dashboard β†’ πŸ“– Documentation

A testing and demonstration interface with live charts, account monitoring, order management, and CSV export capabilities.

4. MT5 Docker Container β†’ πŸ“– Documentation

A Dockerized Debian XFCE environment with VNC/NoVNC access, pre-configured with Wine and MetaTrader 5. Access the desktop via browser at http://localhost:6080.

Quick Start

Prerequisites

  • MetaTrader 5 terminal (build 3000+)
  • Node.js 18+ or Docker
  • npm or yarn

Option 1: Manual Installation

  1. Clone the repository

    git clone https://github.com/mobjoy0/mt5-bridge.git
    cd mt5-bridge
  2. Setup MT5 Expert Advisor

    # Copy files to MT5 data folder
    # MQL5/Experts/SocketBridge/
    # MQL5/Include/SocketBridge/
    
    # Compile in MetaEditor and attach to any chart
    # Enable AutoTrading in MT5
  3. Setup Node.js Backend

    cd web/mt_nodejs
    npm install
    npm run dev
  4. Setup React Dashboard

    cd web/mt5react
    npm install
    npm run dev
  5. Access the Dashboard

    http://localhost:8002
    

Option 2: Docker

# Build and run with Docker Compose
docker-compose up -d

# Access the services
# Node.js Backend: http://localhost:8891
# React Dashboard: http://localhost:8002
# MetaTrader 5 (VNC / NoVNC): http://localhost:6080

After the MT5 container is running, please refer to Documentation for instructions on installing and setting up MetaTrader 5 inside the container.

Documentation

Detailed documentation for each component:

Interactive API Documentation: http://localhost:8891/api-docs (when running)

API Overview

The bridge provides REST API and WebSocket streaming for MT5 integration.

REST Base URL: http://localhost:8891/api/v1
WebSocket URL: ws://localhost:8890

For complete API reference, see the MQL5 EA Documentation or access the Swagger UI at http://localhost:8891/api-docs.

πŸ’‘ Use Cases

  • Algorithmic Trading Bots β€” Execute automated strategies from external systems
  • Custom Trading Dashboards β€” Build web-based interfaces for MT5
  • Risk Management Tools β€” Monitor positions and account metrics in real-time
  • Trade Analytics β€” Export and analyze trading data
  • Mobile Trading Apps β€” Connect mobile apps to MT5 via the API
  • Trading Signal Distribution β€” Broadcast trades to multiple accounts

Technology Stack

Component Technologies
MT5 EA MQL5
Backend Node.js, TypeScript, Express, Swagger
Frontend React, TypeScript, Vite, Lightweight Charts, ApexCharts
Communication REST API, WebSocket (RFC 6455)

🀝 Contributing

Contributions are welcome! Here are some areas where you can help:

  • 🎨 UI/UX Improvements β€” Enhance the React dashboard
  • πŸ“± Mobile Support β€” Responsive design and mobile app
  • πŸ§ͺ Testing β€” Unit and integration tests
  • πŸ“Š Advanced Features β€” Technical indicators, backtesting, etc.
  • 🌐 Internationalization β€” Multi-language support
  • πŸ“– Documentation β€” Improve guides and examples

How to Contribute

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ”’ Security

  • Never expose your MT5 EA ports (8890, 8891) to the public internet without proper authentication
  • Use this system on demo accounts for testing before live trading
  • Always implement proper risk management

⚠️ Disclaimer

This software is provided for educational and development purposes. Use at your own risk. Always test thoroughly on a demo account before deploying to live trading environments. Trading involves substantial risk of loss.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

🌟 Star History

If you find this project useful, please consider giving it a ⭐ on GitHub!


Made with ❀️ for the trading community

About

A complete bridge system that connects MetaTrader 5 to modern web applications through REST APIs and WebSocket streaming. Built with MQL5, Node.js, and React.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published