Skip to main content

OpenMT5Gateway

Open-source, zero-DLL MetaTrader 5 bridge for macOS, Linux, and Windows.

Run Python trading bots against MetaTrader 5 natively on macOS (Apple Silicon / Intel), Linux, Docker, or Windows — without MetaQuotes' Windows-only Python wheel, without C++ .dll injection, and without paid cloud proxies.


Why This Exists

  • MetaQuotes publishes pip install MetaTrader5 exclusively for Windows — installing it on macOS or Linux fails (No matching distribution found for MetaTrader5).
  • C++ DLL socket bridges break inside macOS/Linux Wine wrappers.
  • MQL5 natively supports outbound client TCP sockets (SocketCreate, SocketConnect, SocketSend, SocketRead). OpenMT5Gateway flips the direction: Python runs a lightweight, token-authenticated TCP server, and a pure-MQL5 Expert Advisor connects outward from inside MT5.
flowchart LR
    PY["Python Trading Bot<br/>(macOS / Linux / Windows)"] <-->|"NDJSON RPC over TCP<br/>127.0.0.1:18812"| EA["OpenMT5Gateway.mq5<br/>(Pure MQL5, Zero DLLs)"]
    EA <-->|"Native OrderSend & CopyRates"| MT5["Broker MT5 Server"]

Features

  • Zero External Runtime Dependencies: Uses Python stdlib only (socket, threading, json, hmac, decimal).
  • Token Authentication: Constant-time hmac.compare_digest verification (AUTH / AUTH_ACK).
  • Correlated RPC Multiplexing: Concurrent commands safely matched by request_id.
  • Idempotent Execution: Duplicate external_id orders are blocked automatically.
  • Automatic Broker Suffix Resolution: Resolves symbols like EURUSD, EURUSD.a, EURUSDm, EURUSD.raw, EURUSD_pro.
  • Filling-Mode Fallback in MQL5: Automatically retries IOC -> FOK -> RETURN.
  • Live Telemetry & Reconciliation: Streams balance/equity snapshots and pulls historical closed deals.

Installation & Quickstart

1. Install Python Package

pip install -e .

2. Test Locally Right Now (Simulated Demo EA)

python -m open_mt5_gateway.cli \
  --port 18812 \
  --token "local-dev-secret" \
  --simulate-demo \
  --symbols EURUSD GBPUSD XAUUSD

3. Connect Real MetaTrader 5 (macOS / Windows)

  1. Copy mql5/OpenMT5Gateway.mq5 into your MT5 Data Folder under MQL5/Experts/.
  2. Compile in MetaEditor (0 errors).
  3. Enable Allow Algorithmic Trading in MT5 (Tools -> Options -> Expert Advisors).
  4. Start your Python gateway, then attach OpenMT5Gateway onto any MT5 chart with matching InpPort and InpAuthToken.
from decimal import Decimal
from open_mt5_gateway import GatewayConfig, OpenMT5Client, OpenMT5GatewayServer, OrderRequest

with OpenMT5GatewayServer(GatewayConfig(port=18812, auth_token="my-secret")) as gw:
    gw.wait_for_connection(timeout=30.0)
    client = OpenMT5Client(gw)

    acct = client.get_account()
    print(acct.login, acct.balance)

    res = client.submit_order(
        OrderRequest(
            external_id="trade-001",
            symbol="EURUSD",
            side="buy",
            volume=Decimal("0.10"),
            stop_loss=Decimal("1.08200"),
            take_profit=Decimal("1.08900"),
        )
    )
    print(res)

Publishing to GitHub & PyPI

# Push to GitHub
gh repo create open-mt5-gateway --public --source=. --push

# Build & publish to PyPI
pip install build twine
python -m build
twine upload dist/*

License

MIT License — see LICENSE.

Metadata

Release files for open-mt5-gateway 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for open-mt5-gateway 0.1.0
File Size Uploaded Provenance Actions
open_mt5_gateway-0.1.0.tar.gz 14.7 kB Without provenance Details for open_mt5_gateway-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for open-mt5-gateway 0.1.0
File Interpreter ABI Platform Actions
open_mt5_gateway-0.1.0-py3-none-any.whl Python 3 none any Details for open_mt5_gateway-0.1.0-py3-none-any.whl

Total release size: 26.7 kB

Release files / open_mt5_gateway-0.1.0.tar.gz

Download URL open_mt5_gateway-0.1.0.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b75f6b4c4fa2c42d23fbeafa764caa8117e771b91ae9f1d74b500d57082ad750
BLAKE2b-256 checksum
How to use checksums
5d6c427b894df7b5a6288b9821da02e846cb6c4f3436bd88f624631a56459ded
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.15

Release files / open_mt5_gateway-0.1.0-py3-none-any.whl

Download URL open_mt5_gateway-0.1.0-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0224d99b669210d9076076614285a5d344b21a384b9bd3cdaedc996272b47f94
BLAKE2b-256 checksum
How to use checksums
804a3a7a7a9db7c52b28b9ac8c4c696b74277a01a022b42af3635f36cab464e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.15

Security for open-mt5-gateway 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page