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
- Your MT5 account (any broker, demo or live) runs in a real terminal on HostMT5, 24/7.
- Your code calls
https://hostmt5.com/api/v1with an API key. Every call reaches your own terminal, so you see exactly what your MT5 sees: your broker's symbols, prices, history and fills. - The Python client is one file, hostmt5.py, using only the standard library. Live streaming also needs
pip install websockets.
Five-minute start
- Create a free account and add your MT5 account.
- In the dashboard, open AI & API and create a key. Choose Read only for data, or Trading if your code will place orders.
- Download
hostmt5.pynext 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 package | hostmt5.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
- Your strategy runs on your machine. If your laptop sleeps, your script stops, even though MT5 keeps running. For a strategy that must trade 24/7, run the script on an always-on machine, or write it as an EA and run it in the hosted terminal.
- Each call travels over the internet, so this isn't for strategies that need sub-millisecond reaction.
- Limits per key: 1,200 data requests and 120 trading requests a minute. Stream prices instead of polling them.
- Up to 50,000 bars per call, and up to the newest 500,000 bars per symbol and timeframe (about 1.4 years of M1).
acc.history()pages back for you. - MetaTrader 5 only; no MT4.
Other languages: the same API from Node.js, C#, Go or anything that speaks HTTPS. Full reference: API docs.
Sources
- MQL5 docs: MetaTrader for Python (gets data via interprocess communication with the MT5 terminal)
- 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.
Real MetaTrader 5 in any browser. EAs 24/7, copy trading, TradingView webhooks. No card needed.
Start free →- A free MT5 VPS alternative: hosted MetaTrader 5, free during launch
- Do you still need an MT5 VPS?
- How to run an MT5 Expert Advisor 24/7 without your PC
- TradingView alerts to MT5 orders with a webhook
- Copy trades between MT5 accounts at different brokers
- A MetaApi alternative for traders, not only developers
- A free PineConnector alternative with MT5 hosting included
- The full MT5 terminal in your browser
- Let an AI assistant work with your MT5 account
- A REST API and live stream for MetaTrader 5
- Let Claude or ChatGPT build and run your MT5 EA
- Download years of MT5 price history to CSV
- Moving Skynet MT5 alerts to HostMT5