Linux client helpers for MetaTrader 5 via mt5linux
Project description
MT5_LinuxOHLCV
MT5_LinuxOHLCV is a small Linux-side wrapper around mt5linux that fetches OHLCV data from a running MetaTrader 5 terminal exposed through the bridge.
Install
pip install MT5_LinuxOHLCV
For local development from this workspace:
pip install .
Requirements
- A running MetaTrader 5 terminal started under Wine or another Windows-compatible environment.
- The
mt5linuxbridge running and reachable from Linux on the address and port you pass into the client. - Symbols available in the terminal before requesting data.
Start MetaTrader 5
Launch the MetaTrader 5 terminal through Wine:
WINEPREFIX=~/.mt5 wine "$HOME/.mt5/drive_c/Program Files/MetaTrader 5/terminal64.exe" &
Keep the terminal running in the background before starting the Python client.
Install Windows-side Python packages
The Wine Python environment must have both mt5linux and MetaTrader5 installed before the bridge can start:
WINE_PYTHON="$HOME/.mt5/drive_c/users/$USER/AppData/Local/Programs/Python/Python311/python.exe"
WINEPREFIX=~/.mt5 wine "$WINE_PYTHON" -m pip install mt5linux MetaTrader5
Start the mt5linux bridge
From the Wine-installed Windows Python, start the mt5linux server that listens for Linux-side clients:
WINE_PYTHON="$HOME/.mt5/drive_c/users/$USER/AppData/Local/Programs/Python/Python311/python.exe"
WINEPREFIX=~/.mt5 wine "$WINE_PYTHON" -m mt5linux
Usage
MT5_LinuxOHLCV holds the connection settings and keeps the bridge connection open, so you only pay
the connection warm-up once, no matter how many times you call fetch_ohlcv. Use it as a context
manager so the connection is always closed:
from MT5_LinuxOHLCV import MT5_LinuxOHLCV
with MT5_LinuxOHLCV(
terminal_path=r"C:\Program Files\MetaTrader 5\terminal64.exe",
bridge_host="127.0.0.1",
bridge_port=18812,
) as client:
df = client.fetch_ohlcv(["PETR4"], timeframes=["1m", "1d"])
print(df.tail())
# Reuses the same open connection.
df2 = client.fetch_ohlcv(["VALE3"], timeframes="1d")
print(df2.tail())
You can also manage the connection lifecycle manually:
client = MT5_LinuxOHLCV(bridge_host="127.0.0.1", bridge_port=18812)
client.connect()
try:
df = client.fetch_ohlcv(["PETR4"], timeframes="1d")
finally:
client.close()
The default bridge settings remain localhost:18812, so you only need to pass these when the server is elsewhere.
Testing
Tests stub out the mt5linux bridge, so they run without a MetaTrader terminal or the mt5linux
server:
pip install -e ".[test]"
pytest
License
GNU General Public License v3.0. See LICENSE for the full text.
Project details
Release history Release notifications | RSS feed
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 mt5_linuxohlcv-0.1.2.tar.gz.
File metadata
- Download URL: mt5_linuxohlcv-0.1.2.tar.gz
- Upload date:
- Size: 32.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e5ee16041a4190240e69dd28c9c927a2e0a7912f922d9d76cb75c68142d3c12
|
|
| MD5 |
80bff1de3b13462cbacf6f9515b0bb5c
|
|
| BLAKE2b-256 |
15ae4926e9ee582d7b33aeaa69370feb97a965d4c85ef0ba857129b4a8e75b3f
|
File details
Details for the file mt5_linuxohlcv-0.1.2-py3-none-any.whl.
File metadata
- Download URL: mt5_linuxohlcv-0.1.2-py3-none-any.whl
- Upload date:
- Size: 29.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c84c4b4575a7a083d1fe33b75d19a1162966346531a67e2f364b62dd8ed0e698
|
|
| MD5 |
a8b163fcbce6f4febd76bb32279e3c7a
|
|
| BLAKE2b-256 |
1e55962cdda83b53f1593dab0470f7b5d7227f7ef5493f879b092f837c9b89dd
|