Skip to main content

Linux client helpers for MetaTrader 5 via mt5linux

Project description

mt5linux-client

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

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_linux_client 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.0.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.0-py3-none-any.whl (29.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mt5_linuxohlcv-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 56a88255091fa5ae17ef32980dc07992d3f5d050711978eb269693c73cda186b
MD5 ba293a547a4e0b6d2297efb7feb3329c
BLAKE2b-256 9bf0335d16e712827c3648df2e088823d803cc29791cae911e23c1c0603871ab

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mt5_linuxohlcv-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 29.4 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bbcd739ca826c780a23291b8e010416f2bc20725f845eda674561a3709746b43
MD5 f906233892ea1826ae550f267516f73f
BLAKE2b-256 a071f8aeab67453642b7568aa153e80638eb015469d43908a9fc3206832f2961

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