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

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.3
File Size Uploaded Provenance Actions
metatraderx-0.1.3.tar.gz 76.6 kB With provenance Details for metatraderx-0.1.3.tar.gz

Built distribution (wheel)

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

Total release size: 161.9 kB

Release files / metatraderx-0.1.3.tar.gz

Download URL metatraderx-0.1.3.tar.gz
Size 76.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0c3cc515528459fe9904eead8f5d38a2144084a4345a57c3d9006f7977eba6d4
BLAKE2b-256 checksum
How to use checksums
4042ae146e9bb64fa599a5360861c4331048fa54fbe10e0f153a50ae4f16c807
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.3-py3-none-any.whl

Download URL metatraderx-0.1.3-py3-none-any.whl
Size 85.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
78e53d11479636a45707859b94f0b9c0980197bacc3c41094c57c8a6907264bc
BLAKE2b-256 checksum
How to use checksums
422e5acf3474e74d50e0eac828302482ecde5dfb59425ee99ab0d4fa336b7d6d
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.3

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