MetaTrader5 for Apple Silicon via Docker
Project description
SiliconMetaTrader5 🍏📈
MetaTrader 5 Python library for macOS Apple Silicon
Installation / Upgrade
To get this release, upgrade and pin to 1.2.0:
python3 -m pip install --upgrade "siliconmetatrader5==1.2.0"
python3 -m pip show siliconmetatrader5
Expected output includes:
Version: 1.2.0
Why this release matters
This version is focused on real-world multi-bot stability:
- safer process shutdown behavior (
close()no longer kills everyone) - no false per-call timeout disconnects in slow/emulated environments
- watchdog support for "bridge alive but stuck" detection
- clearer bridge errors for easier debugging
Quick Start
from siliconmetatrader5 import MetaTrader5
import pandas as pd
mt5 = MetaTrader5(host="localhost", port=8001, keepalive=True)
if not mt5.initialize():
raise RuntimeError("MT5 initialize failed")
rates = mt5.copy_rates_from_pos("EURUSD", mt5.TIMEFRAME_M15, 0, 100)
print(pd.DataFrame(rates).tail())
# Recommended: close only this process connection
mt5.close()
v1.2.0 Changes Explained
1) close() vs shutdown() is now explicit
Before this behavior change, users could accidentally stop the shared remote terminal when one process exited.
Now:
close()closes only the current Python client process.shutdown()orclose(remote_shutdown=True)stops the remote MT5 terminal globally.
Why this is critical:
- If you run
monitor + trade + historytogether, one process exiting withclose()should not terminate the other two.
Behavior table:
| Method | Scope | Typical use |
|---|---|---|
close() |
This process only | Normal app exit, multi-bot safe |
shutdown() |
Global terminal | Intentional full stop |
close(remote_shutdown=True) |
This process + global terminal | Single-process controlled setup |
Concrete Bot1/Bot2/Bot3 example:
- Bot1 = monitor process
- Bot2 = trade process
- Bot3 = history/backtest process
Rules:
- If Bot1 exits normally, it should call
close()only. - If Bot2 restarts, it should call
close()only. - If Bot3 finishes replay, it should call
close()only. - None of the above should stop MT5 for other running bots.
- Only your orchestrator/controller process should call
shutdown()(orclose(remote_shutdown=True)) when you intentionally want to stop the whole MT5 terminal.
2) timeout is no longer active runtime behavior
Important clarification:
timeoutis not an idle connection lifetime control anymore.- It is accepted only for backward compatibility.
- Active per-call timeout enforcement is removed to avoid false disconnects in emulated/slow environments.
Recommended pattern:
- Use
keepalive=Truefor long-running bots. - Close intentionally with
close()orshutdown()based on your target scope.
3) Watchdog support added
New APIs:
start_watchdog(...)stop_watchdog()health_status()
What watchdog can detect:
- repeated probe failures
- stuck in-flight calls (
CALL_STUCK) - optional auto-reconnect flow
Example:
from siliconmetatrader5 import MetaTrader5
mt5 = MetaTrader5(host="localhost", port=8001, keepalive=True)
mt5.initialize()
mt5.start_watchdog(
interval_sec=5,
max_miss=3,
probe_timeout_sec=2,
stall_timeout_sec=20,
auto_reconnect=False,
)
print(mt5.health_status())
mt5.stop_watchdog()
mt5.close()
4) Bridge reliability improvements
Internally this release also includes:
- core MT5 wrappers using direct remote calls (
getattr(self.__mt5, method)) instead of broad eval-based forwarding - normalized bridge exceptions via
MT5BridgeError - reason codes:
TIMEOUT,RESULT_EXPIRED,CONNECTION_CLOSED,RPC_ERROR market_book_release(symbol)argument forwarding fix
This helps with:
- clearer error debugging in bots/logs
- fewer ambiguous failures
- safer handling of complex argument types in regular API calls
Data Method Selection (Important)
Use-case based recommendation:
| Use case | Recommended |
|---|---|
| Live monitor / freshest bars | copy_rates_from_pos() |
| Backtest/history by date range | copy_rates_from() / copy_rates_range() |
# live
live_rates = mt5.copy_rates_from_pos("EURUSD", mt5.TIMEFRAME_M5, 0, 500)
# backtest/history
hist_rates = mt5.copy_rates_range("EURUSD", mt5.TIMEFRAME_M5, dt_from, dt_to)
Migration Checklist (from older versions)
- Upgrade package:
python3 -m pip install --upgrade "siliconmetatrader5==1.2.0"
- Verify version:
python3 -m pip show siliconmetatrader5
- Review shutdown path in your bot:
- replace routine global stop calls with
close()for normal exits - keep
shutdown()only for intentional full terminal stop
-
timeout=...in old code can remain for compatibility, but it has no active effect. -
For long-running processes, use
keepalive=Trueand optionally watchdog.
API Snapshot
Constructor:
mt5 = MetaTrader5(host="localhost", port=8001, keepalive=False, timeout=None)
timeout is accepted for backward compatibility and ignored in active runtime behavior.
Additional client methods:
ping()eval(command)execute(command)close(remote_shutdown=False)start_watchdog(...)stop_watchdog()health_status()
Requirements
- Python 3.9+
rpyc>=5.0.0- Running MT5 bridge server
License
MIT License
Author
Bahadir Umut Iscimen
- GitHub: @bahadirumutiscimen
- Email: buiscimen@gmail.com
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file siliconmetatrader5-1.2.0.tar.gz.
File metadata
- Download URL: siliconmetatrader5-1.2.0.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f63a41be0f5d6f4c7591992271426ba7c258d5f3ac020fd1bca256af4538b01f
|
|
| MD5 |
f45531139a5c8c23cc6679109ce3397f
|
|
| BLAKE2b-256 |
6f6972c66ff094d2a41ceb35848ec993fb0fcb71cd10f403f35b4798c3331632
|
File details
Details for the file siliconmetatrader5-1.2.0-py3-none-any.whl.
File metadata
- Download URL: siliconmetatrader5-1.2.0-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1636c4c0c4aeba4924f2c63f00a1d05dbc65669e4851b7ff8256282facd6e85
|
|
| MD5 |
d8dfd8a5dfabba3ffaa78b2e8b2dc259
|
|
| BLAKE2b-256 |
88273c7219b9b9bdb1860fb52c8782041aa82d4c6465ec19b14a3e3fe2713013
|