portable MetaTrader 5 in Docker with a secure RPC API Gateway and real-time WebSocket data streaming
9.9K
This Docker image provides a ready-to-use environment to run a portable MetaTrader 5 (MT5) terminal inside a Windows Server Core container, combined with Python services for real-time account streaming and a secure, general-purpose RPC API Gateway.
It is designed for developers, data scientists, and algorithmic traders who want full programmatic access to all MT5 functions—from data retrieval to trade execution—without installing the terminal locally.
📌 For full deployment instructions, detailed usage examples, and source code, please see the complete GitHub repository: Dockerized-MetaTrader5-with-Python-DataBridge
streamer.py continuously streams live account data (balance, equity, open trades, etc.) to a WebSocket hub.api_gateway.py provides a powerful and secure endpoint to execute almost any function from the MetaTrader5 library remotely, protected by an API key.Pull and start the container with your MT5 credentials, WebSocket hub address, and a secret API key for the RPC Gateway:
docker run -d --name my-mt5-bot \
-p 8080:8080 \
-e MT5_ACCOUNT="YOUR_ACCOUNT_NUMBER" \
-e MT5_PASSWORD="YOUR_ACCOUNT_PASSWORD" \
-e MT5_SERVER="YOUR_MT5_SERVER_NAME" \
-e WEBSOCKET_URI="ws://your-websocket-server-ip:8765" \
-e API_KEY="YOUR_SUPER_SECRET_KEY" \
immahdi/mt5-python:latest
Access the full power of the MetaTrader5 library through a secure RPC endpoint on port 8080. You can call functions by sending a JSON payload to the /rpc endpoint.
docker run -d -p 8080:8080 your-dockerhub-username/mt5-python-bridge
curl -X POST http://<docker-host-ip>:8080/rpc \
-H "Content-Type: application/json" \
-H "X-API-KEY: YOUR_SUPER_SECRET_KEY" \
-d '{
"function_name": "account_info"
}'
curl -X POST http://<docker-host-ip>:8080/rpc \
-H "Content-Type: application/json" \
-H "X-API-KEY: YOUR_SUPER_SECRET_KEY" \
-d '{
"function_name": "order_send",
"kwargs": {
"request": {
"action": 1,
"symbol": "EURUSD",
"volume": 0.01,
"type": 0,
"price": 0,
"magic": 123456,
"comment": "Sent via API Gateway",
"type_filling": 1,
"type_time": 0
}
}
}'
The API intelligently formats the response into a clean, human-readable JSON object.
The container streams live account and open trade data to the WebSocket server you specify via WEBSOCKET_URI.
Example Client:
import asyncio, websockets, json
WEBSOCKET_URI = "ws://<hub-server-ip>:8765"
async def view_stream():
async with websockets.connect(WEBSOCKET_URI) as websocket:
await websocket.send(json.dumps({"type": "viewer_hello"}))
print("Connected as viewer. Receiving live data...")
async for message in websocket:
print(json.dumps(json.loads(message), indent=2))
asyncio.run(view_stream())
Content type
Image
Digest
sha256:d47927174…
Size
2.4 GB
Last updated
10 months ago
docker pull immahdi/mt5-python