Home › Guides

Use MT5 from Python on Mac, Linux or a notebook

Updated 2026-11-26 · HostMT5 guides

MetaQuotes' Python package for MetaTrader 5 only works on Windows, next to a running MT5 terminal. If you write strategies on a Mac or Linux machine, or in a notebook in the cloud, HostMT5 gives you the same data and orders over HTTPS: your MT5 runs on our server, and your Python runs wherever you like.

Why the official package needs Windows

The MetaTrader5 package gets its data "via interprocessor communication directly from the MetaTrader 5 terminal" [1], so the terminal has to run on the same computer as your script. On PyPI, the current release (5.0.6231 when we checked) is published only as Windows wheels (win_amd64) [2]. On a Mac or Linux box, pip install MetaTrader5 has nothing to install, which is why people end up with Wine, a Windows virtual machine or a Windows VPS.

How it works on HostMT5

Five-minute start

  1. Create a free account and add your MT5 account.
  2. In the dashboard, open AI & API and create a key. Choose Read only for data, or Trading if your code will place orders.
  3. Download hostmt5.py next to your script and run:
from hostmt5 import HostMT5

api = HostMT5("mc_your_key")
print(api.accounts())                          # your hosted accounts and their ids
acc = api.account(1)

print(acc.info()["equity"])                    # balance, equity, margin, leverage...
bars = acc.bars("EURUSD", "H1", count=500)      # oldest first: time, open, high, low, close, tick_volume, spread
df = acc.bars_df("XAUUSD", "M15", count=5000)   # the same as a pandas DataFrame
ticks = acc.ticks("EURUSD", count=10000)

Placing orders from Python

t = acc.buy("EURUSD", 0.01, sl_pips=20, tp_pips=40, client_id="signal-123")
acc.modify(t["ticket"], sl=1.0950)
acc.close(t["ticket"], volume=0.005)            # close half
acc.sell_limit("XAUUSD", 0.02, 2700, sl=2712)
acc.close_all(symbol="EURUSD")

Sending the same client_id again within 10 minutes returns the first result instead of trading twice, so a retry after a network error can't double your position.

Acting on each closed candle

for ev in acc.stream(symbols=["EURUSD"], candles=[("EURUSD", "M5")]):   # reconnects by itself
    if ev["type"] == "candle" and ev["closed"]:
        print("bar closed", ev["bar"])          # run your strategy here

A ready-made moving-average crossover, sma_cross.py, does exactly this. Run it on a demo account first.

Coming from the MetaTrader5 package

MetaTrader5 packagehostmt5.py
mt5.account_info()acc.info()
mt5.copy_rates_from_pos()acc.bars(symbol, tf, count=...)
mt5.copy_rates_range()acc.bars(symbol, tf, start=..., end=...) or acc.history()
mt5.copy_ticks_from() / copy_ticks_range()acc.ticks(symbol, count=... or start/end)
mt5.symbol_info()acc.symbol(name)
mt5.positions_get() / orders_get()acc.positions() / acc.orders()
mt5.history_deals_get()acc.deals(days=30)
mt5.order_send()acc.buy(), acc.sell(), acc.order()

Bar, tick and deal times are the same numbers the MetaTrader5 package returns: broker server time as Unix seconds.

Honest limits

Other languages: the same API from Node.js, C#, Go or anything that speaks HTTPS. Full reference: API docs.

Sources

  1. MQL5 docs: MetaTrader for Python (gets data via interprocess communication with the MT5 terminal)
  2. PyPI: MetaTrader5 (files for release 5.0.6231 are Windows wheels only, checked 26 Nov 2026)

FAQ

Does the MetaTrader5 Python package work on Mac or Linux?

No. It talks to an MT5 terminal on the same computer, and PyPI publishes it as Windows wheels only. On HostMT5 your terminal runs in the cloud and Python on any OS reaches it through the API.

Do I need to install packages?

No for REST: hostmt5.py uses only the Python standard library. Live streaming needs pip install websockets.

Can Python place real orders?

Yes with a Trading key, on demo or live accounts. A Read-only key gets data only, and any change is refused.

Does my strategy keep running when my laptop is off?

No. The script runs where you start it; MT5 keeps running on HostMT5. For 24/7 trading, run the script on an always-on machine or write it as an EA in the hosted terminal.

How much history can I download?

Up to 50,000 bars per call and the newest 500,000 bars per symbol and timeframe (about 1.4 years of M1, about 7 years of M5). history() pages back for you.

Host your MT5 in the cloud, free

Real MetaTrader 5 in any browser. EAs 24/7, copy trading, TradingView webhooks. No card needed.

Start free →
More guides

All guides · HostMT5 facts