siliconmetatrader5
Python client for SiliconMetaTrader5:
the official MetaTrader5 API on macOS (Apple Silicon and Intel), Linux and your own Linux or
Windows servers. MetaTrader 5 runs in the SiliconMetaTrader5 runtime (Wine on macOS and Linux,
natively on a Windows server) and this package talks to it over a local RPyC bridge on 127.0.0.1.
pip install siliconmetatrader5
Set up the runtime first with the desktop app or the smt5 command line: see the
project README. The app's
Bot connection page shows which host and port to use for wherever your code runs.
Usage
from datetime import timedelta
import pandas as pd
from siliconmetatrader5 import MetaTrader5, server_now
mt5 = MetaTrader5(host="127.0.0.1", port=8001, keepalive=True)
if not mt5.initialize():
raise RuntimeError(f"MT5 initialization failed: {mt5.last_error()}")
# live bars
rates = mt5.copy_rates_from_pos("EURUSD", mt5.TIMEFRAME_M15, 0, 150)
print(pd.DataFrame(rates).tail())
# a time range on the broker's clock (not this computer's)
now = server_now(mt5)
rates = mt5.copy_rates_range("EURUSD", mt5.TIMEFRAME_M5, now - timedelta(hours=6), now)
mt5.close()
The method names and arguments are those of the official MetaTrader5 package.
Broker server time
MT5 stamps bars and ticks with the broker's server wall clock encoded as UTC
(e.g. UTC+2 in winter). Passing datetime.now() from your machine therefore
cuts off or shifts the newest bars. Since 1.3.0:
| Function | Returns |
|---|---|
server_time_offset(mt5, symbol="EURUSD") |
seconds to add to UTC for the broker clock (from a live tick; tries 24/7 symbols when the market is closed), or None |
server_now(mt5, symbol="EURUSD", offset=None) |
the broker's current time as an aware datetime, ready for copy_rates_from / copy_rates_range |
format_offset(offset) |
"UTC+2", "UTC-4:30", "unknown" |
bar_time(epoch) |
a bar/tick time field as an aware datetime on the same clock |
Connection lifecycle
close()disconnects this process; the terminal and other clients keep running.shutdown()runs MT5'sshutdown()in the shared bridge process, so every client of that bridge loses the terminal connection until it callsinitialize()again — avoid it when several bots share the bridge.keepalive=Truekeeps the connection serviced in a background thread (long-running bots).start_watchdog(...),stop_watchdog(),health_status()detect a frozen bridge and can reconnect.- Errors are raised as
MT5BridgeErrorwithreason_code(TIMEOUT,RESULT_EXPIRED,CONNECTION_CLOSED,RPC_ERROR) andoperation.
Changelog
1.3.0 — broker server-time helpers (server_now, server_time_offset,
format_offset, bar_time); __version__ is correct again (1.2.3 reported
1.2.2); project moved into the SiliconMetaTrader5 repository (client/); Python 3.14;
Linux classifier.
1.2.3 — packaged bridge server layout fixed.
License
PolyForm Noncommercial 1.0.0: free for personal and other noncommercial use; commercial use needs a separate license from the author.
Metadata
Release files for siliconmetatrader5 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| siliconmetatrader5-1.3.0.tar.gz | 21.9 kB | With provenance | Details for siliconmetatrader5-1.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| siliconmetatrader5-1.3.0-py3-none-any.whl | Python 3 | none | any | Details for siliconmetatrader5-1.3.0-py3-none-any.whl |
Total release size: 40.9 kB
Release files / siliconmetatrader5-1.3.0.tar.gz
| Download URL | siliconmetatrader5-1.3.0.tar.gz |
|---|---|
| Size | 21.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
12d4177ee9c00ae44ae49c724de227c9285c878e5550fbc73237e7060afd3e26
|
|
BLAKE2b-256 checksum How to use checksums |
fd8214a5f038880ee73977510a2207e5c519774ddf5f6acf139d2ce4d8a78a40
|
| 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 5, 2026.
Transparency logRelease files / siliconmetatrader5-1.3.0-py3-none-any.whl
| Download URL | siliconmetatrader5-1.3.0-py3-none-any.whl |
|---|---|
| Size | 19.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d875138c2b714f205209d9a56f9a4b65ae720664dd99035352e5f8b24ab259dd
|
|
BLAKE2b-256 checksum How to use checksums |
be2ed4c27e07d6e6258a68a091c97fba23a1377e1fdaee0f5f7d44c96017add1
|
| 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 5, 2026.
Transparency logSecurity for siliconmetatrader5 1.3.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.
Attestation for siliconmetatrader5-1.3.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 5, 2026.
Transparency logA 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.