Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MT5 Bridge

A Flask-based HTTP bridge service that exposes MetaTrader5 terminal functionality over REST API. Runs inside Wine/Windows alongside Terminal64.exe and provides a local HTTP API on 127.0.0.1:5555 for Linux/Django backends to interact with MT5.

Features

  • REST API: Simple JSON-based HTTP endpoints
  • Account Management: Query account info, balance, equity
  • Position Tracking: Get open positions, historical trades
  • Order Execution: Place BUY/SELL orders, modify/close positions
  • Terminal Integration: Health checks, status queries
  • Async Initialization: Automatic retry logic with exponential backoff
  • Thread-Safe: All MT5 calls are serialized to prevent race conditions

Architecture

The bridge runs as a separate service inside Wine (Windows environment):

Terminal64.exe (MT5 Terminal)
    ↓
mt5_bridge.py (Flask HTTP Server @ 127.0.0.1:5555)
    ↓
Linux Backend (Django/Celery)

API Endpoints

Health & Status

  • GET /health - Server health status
  • GET /terminal_info - Terminal connection info
  • GET /account_info - Account details

Positions & Orders

  • GET /positions - List open positions
  • POST /order - Place new order (BUY/SELL)
  • PUT /position/{ticket} - Modify position (TP/SL)
  • DELETE /position/{ticket} - Close position
  • GET /history - Historical trades

Admin

  • POST /initialize - Initialize MT5 connection
  • POST /shutdown - Graceful shutdown

Configuration

Requires MT5 terminal running with:

  • Account already logged in
  • Expert Advisors enabled
  • DLL imports allowed (for bridge communication)

Development

# Install dependencies
pip install Flask MetaTrader5

# Run bridge
python mt5_bridge.py

# Test connectivity
curl http://127.0.0.1:5555/health

Security Notes

  • Only listens on localhost (127.0.0.1)
  • No authentication (operates in private network)
  • All MT5 calls serialized to prevent race conditions
  • Logs all operations for audit trail

License

Proprietary - Part of AlgoAgent Trading System

About

MT5 Bridge - Flask HTTP server for MetaTrader5 terminal integration

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages