Skip to main content

MetaTrader5 for Apple Silicon via Docker

Project description

⚡ SiliconMetaTrader5 🍏📈

Ultimate MetaTrader 5 & Python Solution for macOS Apple Silicon

Python Docker Apple Silicon Version

Developer: Bahadir Umut Iscimen | 🇹🇷 Türkçe Oku


[!NOTE]
💡 Clarification: This project does NOT replace the native MetaTrader 5 application installed on your computer. It runs a separate, headless MT5 instance via Docker to enable Python communication and algorithmic trading on macOS. This is an end-to-end solution developed to run MT5 seamlessly on macOS Silicon devices and to perform professional algorithmic trading with a Python client.

[!CAUTION]
⚠️ Usage Purpose & Production Warning: This infrastructure is designed to make strategy development, backtesting, and forward-testing incredibly comfortable in the macOS environment. However, for live (production) trading that requires millisecond precision or involves high capital, using a physical PC or server with native Windows (no emulation layer) is strictly recommended.


📦 What's Inside This Repository?

  • 🐳 docker/ : High-performance MT5 runtime built on Wine + QEMU.
  • 🐍 client/ : Custom Python client package (siliconmetatrader5).
  • 🧪 tests/ : Validation and connection health scripts.

🏗 System Architecture & Workflow

Visualizing the bridge between Apple Silicon, Docker Emulation, and Python.

System Architecture

📸 Screenshots

Localhost VNC Data Fetch
Left: Running on Localhost (VNC) | Right: Python Data Fetching

📡 Data Retrieval Methods

Choose the right method for your specific trading/backtesting scenario:

🎯 Use Case 🛠 Recommended Method
Live Monitor / Fresh Bars copy_rates_from_pos()
Backtest / Historic Data copy_rates_from() / copy_rates_range()

Example Implementation:

# 🟢 Live Data Fetching
live_rates = mt5.copy_rates_from_pos("EURUSD", mt5.TIMEFRAME_M5, 0, 500)

# 🕒 Historical Backtesting
hist_rates = mt5.copy_rates_range("EURUSD", mt5.TIMEFRAME_M5, dt_from, dt_to)

🚀 Zero-to-Hero Setup Guide

Starting from scratch? Follow these steps to get your automated trading engine running on macOS.

1️⃣ Preparation

Open your Terminal and install the foundational tools:

# 1. Install Homebrew (skip if you already have it)
/bin/bash -c "$(curl -fsSL [https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh](https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh))"

# 2. Install Emulation & Container required packages
brew install colima docker qemu lima lima-additional-guestagents

2️⃣ Start the Emulation Engine (Colima)

We configure Colima with x86_64 emulation to ensure Docker handles MT5 seamlessly on Apple Silicon.

# Optional: Reset if Colima state is broken
# colima delete -f

colima start --arch x86_64 --vm-type=qemu --cpu 4 --memory 8

3️⃣ Initialize the MT5 Server

cd docker

# Option A: Foreground (See live logs - Recommended for first setup)
docker compose up --build

# Option B: Detached (Run in background once stable)
# docker compose up --build -d

[!IMPORTANT] Key Notes for Initialization:

  • Build Time: The first build takes roughly 5-10 minutes.
  • 🖥 Booting UI: Transitioning from a black screen to the MT5 interface may take 25-30 minutes during the very first run.
  • 🌐 Visual Access: Go to http://localhost:6081/vnc.html (Password: 123456).
  • 🔑 First Action: Navigate to File > Open an Account, search for your broker, and log in manually.

4️⃣ Install the Python Client

Link your Python environment to the new Docker instance:

python3 -m pip install --upgrade siliconmetatrader5

5️⃣ Verify Connection

Run the built-in tests to ensure smooth data flow:

python tests/test_fetch.py
python tests/test_plot.py

If your terminal displays a successful connection and outputs data, you are ready to build your bots! 🎉


⚙️ Advanced Configuration

🌍 Timezone Customization

The default container timezone is Europe/Istanbul. To change this, edit docker/compose.yaml:

environment:
  - TZ=America/New_York  # Options: UTC, Asia/Tokyo, etc.

(Note: This alters the Linux container VNC layer, not your broker's server time.)

🖥 Screen Resolution & Performance

Adjust visual settings in docker/start.sh:

# Resolution setup
Xvfb :100 -ac -screen 0 1366x768x24 &

# Window Manager (Optional - May increase VNC latency)
# openbox &

Apply changes: cd docker && docker compose up --build -d

📊 MT5 History Depth (MaxBars)

To access deeper bar history for heavy backtesting, edit docker/mt5cfg.ini:

MaxBars=500000  # Options: 100000, 250000, 500000, 1000000

(Trade-off: Higher memory usage and slightly slower startup sync.)


💻 Example Usage

A quick boilerplate to start fetching data instantly:

import pandas as pd
from siliconmetatrader5 import MetaTrader5

# Initialize Bridge
mt5 = MetaTrader5(host="localhost", port=8001, keepalive=True)

if not mt5.initialize():
    raise RuntimeError("🚨 MT5 initialization failed!")

# Fetch Live Data
rates_live = mt5.copy_rates_from_pos("EURUSD", mt5.TIMEFRAME_M15, 0, 150)
print(pd.DataFrame(rates_live).tail())

# Graceful Exit
mt5.close() 

🆕 Client Updates (Important)

Check your version: python3 -m pip show siliconmetatrader5

🛠 Core Improvements

  1. Connection Lifecycle (close vs shutdown):
    • close() disconnects the current process.
    • shutdown() completely stops the remote MT5 terminal (Use carefully in multi-bot setups).
  2. Timeout Semantics: Active per-call timeout is removed. Use keepalive=True for long-running bots.
  3. Watchdog Support: New methods start_watchdog(...), stop_watchdog(), and health_status() added to detect frozen bridges.
  4. Reliability: Direct remote call dispatch, normalized error codes (TIMEOUT, CONNECTION_CLOSED), and market_book_release forwarding fixes.

🛡 Challenges & Architectural Solutions

  • Architecture Mismatch: Mitigated crash loops by enforcing QEMU-based full x86_64 emulation instead of Rosetta.
  • IPC Timeout Patterns: Integrated retry-oriented behavior in the Python client to counter emulation pressure.
  • SSL/TLS Compatibility: Embedded necessary Windows/Wine dependencies for secure, reliable broker communication.

🔁 Daily Routine Checklist

▶️ Start the System:

if colima status 2>/dev/null | grep -q "colima is running"; then
  echo "Colima is ready 🟢"
else
  colima start
fi
cd docker && docker compose up -d

⏹ Stop the System Safely:

cd docker && docker compose down
colima stop

❓ FAQ (Frequently Asked Questions)

Q: I rebooted my Mac, what do I run?

Run the start script from the repository root. Make sure Colima starts first, then launch Docker compose.

Q: My MT5 screen stays black via VNC. What do I do?

Ensure Colima is running in QEMU/x86_64 mode. Stop detached mode and run docker compose up --build in the foreground to monitor error logs.

Q: How do I cleanly stop everything?

Run cd docker && docker compose down and let the containers terminate gracefully before shutting down Colima.


Built with ☕ and code for the Apple Silicon algorithmic trading community.

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.1.tar.gz (21.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.1-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file siliconmetatrader5-1.2.1.tar.gz.

File metadata

  • Download URL: siliconmetatrader5-1.2.1.tar.gz
  • Upload date:
  • Size: 21.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.1.tar.gz
Algorithm Hash digest
SHA256 56ae98d1b9c4d4d18864062716c86a54c1b343ebf30e4332684ba37bdeb9de52
MD5 488258a977d08ab0bb30d03a47f0e2dd
BLAKE2b-256 0411537ed4f3cb9e7296834cfb08648243f5b717ec36afca2ede48755e9d7863

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for siliconmetatrader5-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0bf64264cf375c6d60f79fdb560242a9363980e23498cc6318fcc973700fcf67
MD5 76328355eaec2feedb9b3ef5ccfd7b48
BLAKE2b-256 481076fde42abe4020e7351df19c6c8d0dca418c04eb619771c316ba8ecd06e0

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