Skip to main content

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 mt5linux bridge 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

MT5Client 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 MT5Client

with MT5Client(
    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")

You can also manage the connection lifecycle manually:

client = MT5Client(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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mt5_linuxohlcv-0.1.1.tar.gz (31.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mt5_linuxohlcv-0.1.1-py3-none-any.whl (29.5 kB view details)

Uploaded Python 3

File details

Details for the file mt5_linuxohlcv-0.1.1.tar.gz.

File metadata

  • Download URL: mt5_linuxohlcv-0.1.1.tar.gz
  • Upload date:
  • Size: 31.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for mt5_linuxohlcv-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0fdf542685a26b60eb11f9d3d3efbc007ec689f665d3c68f84d74afdf2d25f6c
MD5 058efe5bb21014f0d0eb8ef0167c73b5
BLAKE2b-256 cfb48006b34e7b7692186a9affd4dcf8552334c46d13690a1a4d002eb561cad1

See more details on using hashes here.

File details

Details for the file mt5_linuxohlcv-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mt5_linuxohlcv-0.1.1-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

Hashes for mt5_linuxohlcv-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5dc6ff340bf61054b99a8d7acaa41680e902b10338cb60aff93a985ab150fa51
MD5 b14645e3859e2c56bcbf9cbe953358da
BLAKE2b-256 c063ee69ff32dac96bcb6ee790dd9ae027d05056976cd06d2bb6dfffda7f85d1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page