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.1

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.1
File Size Uploaded Provenance Actions
metatraderx-0.1.1.tar.gz 74.4 kB With provenance Details for metatraderx-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 157.7 kB

Release files / metatraderx-0.1.1.tar.gz

Download URL metatraderx-0.1.1.tar.gz
Size 74.4 kB
Tags Source
SHA-256 checksum
How to use checksums
7166f259afd464f92e308c0d89aff4cc9bd02bb970320dae74398d71345e434d
BLAKE2b-256 checksum
How to use checksums
9b816b83fb1b29ccdb286e45da181b0629966cfc68af48707519a0c2abc057c7
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.1-py3-none-any.whl

Download URL metatraderx-0.1.1-py3-none-any.whl
Size 83.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5e7a72ea96ecb72827d61cded9df4e80bd1899fd62bd71a142ae7d3d512449cf
BLAKE2b-256 checksum
How to use checksums
b16fb72d5428f305582f4b59575a6bf78b51e533c7dbca615863a5112a2b8766
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.1

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.1.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