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.
- 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
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)
GET /health- Server health statusGET /terminal_info- Terminal connection infoGET /account_info- Account details
GET /positions- List open positionsPOST /order- Place new order (BUY/SELL)PUT /position/{ticket}- Modify position (TP/SL)DELETE /position/{ticket}- Close positionGET /history- Historical trades
POST /initialize- Initialize MT5 connectionPOST /shutdown- Graceful shutdown
Requires MT5 terminal running with:
- Account already logged in
- Expert Advisors enabled
- DLL imports allowed (for bridge communication)
# Install dependencies
pip install Flask MetaTrader5
# Run bridge
python mt5_bridge.py
# Test connectivity
curl http://127.0.0.1:5555/health- 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
Proprietary - Part of AlgoAgent Trading System