Skip to main content

MetaTrader5 for Apple Silicon via Docker

Project description

SiliconMetaTrader5 🍏📈

MetaTrader 5 Python library for macOS Apple Silicon

PyPI License


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() or close(remote_shutdown=True) stops the remote MT5 terminal globally.

Why this is critical:

  • If you run monitor + trade + history together, one process exiting with close() 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() (or close(remote_shutdown=True)) when you intentionally want to stop the whole MT5 terminal.

2) timeout is no longer active runtime behavior

Important clarification:

  • timeout is 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=True for long-running bots.
  • Close intentionally with close() or shutdown() 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)

  1. Upgrade package:
python3 -m pip install --upgrade "siliconmetatrader5==1.2.0"
  1. Verify version:
python3 -m pip show siliconmetatrader5
  1. Review shutdown path in your bot:
  • replace routine global stop calls with close() for normal exits
  • keep shutdown() only for intentional full terminal stop
  1. timeout=... in old code can remain for compatibility, but it has no active effect.

  2. For long-running processes, use keepalive=True and 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

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

siliconmetatrader5-1.2.0.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

siliconmetatrader5-1.2.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

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

Hashes for siliconmetatrader5-1.2.0.tar.gz
Algorithm Hash digest
SHA256 f63a41be0f5d6f4c7591992271426ba7c258d5f3ac020fd1bca256af4538b01f
MD5 f45531139a5c8c23cc6679109ce3397f
BLAKE2b-256 6f6972c66ff094d2a41ceb35848ec993fb0fcb71cd10f403f35b4798c3331632

See more details on using hashes here.

File details

Details for the file siliconmetatrader5-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for siliconmetatrader5-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a1636c4c0c4aeba4924f2c63f00a1d05dbc65669e4851b7ff8256282facd6e85
MD5 d8dfd8a5dfabba3ffaa78b2e8b2dc259
BLAKE2b-256 88273c7219b9b9bdb1860fb52c8782041aa82d4c6465ec19b14a3e3fe2713013

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page