MetaTrader 5 for Linux
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.
Installation
-
Install Wine.
-
Install this package on Linux Python:
pip install mt5linux
-
Download the latest mt5server.exe release binary.
Docker
Alternatively, you can run this library using Docker, see the Docker docs.
Usage
Option 1: Library-Managed Containers (Recommended for Docker)
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 port (auto-selected if None)
ui_password=None, # noVNC password
vnc_port=5901, # VNC port
)
mt5.initialize()
mt5.terminal_info()
mt5.shutdown()
# Container is automatically stopped when mt5 is deleted
Option 2: Manual Docker
Run 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()
Option 3: Standalone Server (Linux with Wine)
-
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()
Accessing Container Properties
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 container
For full API documentation, see the official MetaTrader5 Python integration.
Thanks
- hpdeandrade for many improvements and insights about docker.
- ananta-dev for project motivation.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mt5linux-1.1.0.tar.gz.
File metadata
- Download URL: mt5linux-1.1.0.tar.gz
- Upload date:
- Size: 38.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2afb72a5e8dec1826fb2b7dca431ef94f2f44f34462c7b52835390dbb63442fc
|
|
| MD5 |
31e460e1c1db524383d7a19101ab4a1a
|
|
| BLAKE2b-256 |
e74bdd2c5a81a375cc576f8ca55e27f8fd3e046fa9d848a226b16e6eb3a62589
|
File details
Details for the file mt5linux-1.1.0-py3-none-any.whl.
File metadata
- Download URL: mt5linux-1.1.0-py3-none-any.whl
- Upload date:
- Size: 40.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc0f2dc06098168699504145576e920c3ea695dc42db52ff8ef8ae4f747f96f6
|
|
| MD5 |
c25ae3636661260ad5c38c30c8a36d5d
|
|
| BLAKE2b-256 |
c9aaa011925b531cb5279fedbefed58e774ad313200e7a3d325dd7f47fc21117
|