A package that uses Wine, RPyC, and mt5server.exe (a standalone binary with all dependencies) to run MetaTrader5 on Linux.
For an explanation of who should use mt5linux and why, see Motivation and Use Cases.
-
Install Wine.
-
Install this package on Linux Python:
pip install mt5linux
-
Download the latest mt5server.exe release binary.
Alternatively, you can run this library using Docker, see the Docker docs.
The library can automatically start and stop Docker containers for you:
from mt5linux import MetaTrader5
mt5 = MetaTrader5(
host="localhost",
mt5_login=12345678,
mt5_password="your_password",
mt5_server="Broker-Server",
engine="auto", # 'auto', 'docker', or 'udocker'
image_tag="latest", # Docker image tag
ui_port=8080, # noVNC http port (auto-selected if None)
ui_host="localhost", # noVNC host for the UI URL
ui_password=None, # noVNC password
vnc_port=5901, # VNC port
)
mt5.initialize()
mt5.terminal_info()
mt5.shutdown()
# Container is automatically stopped when mt5 is deletedRun Docker manually with docker compose up -d, then connect:
from mt5linux import MetaTrader5
mt5 = MetaTrader5(host="localhost", port=18812)
mt5.initialize()
mt5.terminal_info()
mt5.shutdown()-
Open MetaTrader5 on Windows/Wine.
-
Start the server:
wine mt5server.exe [-p/--port <port>]
The default port is
18812. View all options with:wine mt5server.exe --help
-
Connect from Linux Python:
from mt5linux import MetaTrader5 mt5 = MetaTrader5() mt5.initialize(server=<server_ip>, login=<login_id>, password=<password>) # Or simply: mt5.initialize() to auto-search for the server mt5.terminal_info() mt5.shutdown()
When using library-managed containers, access the container manager via the container property:
mt5 = MetaTrader5(mt5_login=12345678, mt5_password="password")
print(mt5.container.name) # Container name
print(mt5.container.status()) # 'running', 'exited', etc.
print(mt5.container.ui_port) # noVNC port
print(mt5.container.is_running()) # True/False
mt5.container.stop() # Stop container
mt5.container.start() # Start container (if using controlled containers)
mt5.container.remove() # Remove containerFor full API documentation, see the official MetaTrader5 Python integration.
- hpdeandrade for many improvements and insights about docker.
- ananta-dev for project motivation.