Skip to main content

MetaTraderX

A universal MetaTrader 5 and MetaTrader 4 Python API for Windows, Linux and macOS. import metatraderx as mt5 works like import MetaTrader5 as mt5, with the same functions, constants and result types.

On Windows it drives the installed terminal through the official package. On Linux and macOS the terminal is the Wine build MetaQuotes ships; MetaTraderX starts a worker inside the same Wine prefix and talks to it over an authenticated loopback socket. The worker starts and stops with your program, so no RPyC server, container or separate process has to be run by hand.

A device with no terminal can use the same API against a running mtx serve on another machine.

Install

pip install metatraderx
mtx install        # MetaTrader 5; `mtx install 4` for MetaTrader 4
mtx setup          # Linux and macOS: Wine, Windows Python and the MetaTrader5 package
mtx terminal list
mtx terminal select 0

Broker builds with a custom executable are found too, and any executable can be selected by path.

Use

import metatraderx as mt5

if not mt5.initialize(login=12345678, password="...", server="Broker-Demo"):
    raise SystemExit(mt5.last_error())

print(mt5.account_info())
print(mt5.to_frame(mt5.copy_rates_from_pos("EURUSD", mt5.TIMEFRAME_H1, 0, 500)))
mt5.shutdown()

A specific terminal or a server, with the MetaTrader class:

import metatraderx as mtx

mt = mtx.MetaTrader(terminal="/home/me/.mt5/drive_c/Program Files/MetaTrader 5/terminal64.exe")
mt = mtx.MetaTrader(url="mtx://trading-box:8765", token="...")
mt.initialize()

Command line

mtx symbols --first 20
mtx fetch rates EURUSD --tf M15 --from 2025-01-01 --to 2025-02-01 -o eurusd.csv
mtx fetch deals --from -30d -o deals.json
mtx serve --host 0.0.0.0 --auth auto --read-only
mtx display --tunnel

The command line has no trading commands.

Documentation

https://kshraven.github.io/metatraderx/

Installation terminal, Wine and package setup
Python API functions, constants, result types, the MetaTrader class
Cache, Offline mode, Verbosity keeping data and working without a terminal
Server and clients sharing a terminal
Terminal display the terminal window in a browser
Command line every mtx command
Platforms Windows, Linux, macOS, MetaTrader 4
Settings environment variables and saved settings

MetaTrader 4

MetaTrader 4 has no Python API. Read-only data (account, symbols, rates, positions, deal history) is available through the bundled MetaTraderXBridge expert, which is experimental. See MetaTrader 4.

Notice

MetaTraderX is an independent project and is not affiliated with or endorsed by MetaQuotes Ltd. MetaTrader is a trademark of MetaQuotes Ltd. Trading carries risk, and the software is provided as is under the licence below.

Licence

MIT

Metadata

Release files for metatraderx 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 metatraderx 0.1.0
File Size Uploaded Provenance Actions
metatraderx-0.1.0.tar.gz 74.1 kB With provenance Details for metatraderx-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 157.1 kB

Release files / metatraderx-0.1.0.tar.gz

Download URL metatraderx-0.1.0.tar.gz
Size 74.1 kB
Tags Source
SHA-256 checksum
How to use checksums
109c03c0f778280f64260c83d05f7bf16da4ded3e0a735419fbc338ba20d92e3
BLAKE2b-256 checksum
How to use checksums
718ee1ea1da711f737723ff8796e5626e08aef92c097340021f0164c7727a52b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

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

Download URL metatraderx-0.1.0-py3-none-any.whl
Size 83.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fb8de5dfa7d4face3cb926cf36a8eed0967ca81c624a868289709c31cb56210b
BLAKE2b-256 checksum
How to use checksums
24ef955ab670198dff52f951485e6c4e82bb8b623c3bd47cdd19970b1490cedc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Security for metatraderx 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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for metatraderx-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

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.

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