mt5.version() in MetaTrader5 Python: read the terminal's version and build
Returns the version, build number and release date of the MetaTrader 5 terminal your script is linked to, or None when the call fails.
Signature
mt5.version() What it does
Use version() to log which terminal build your script ran against. A build number helps when a behaviour changes between terminal updates.
What it returns
- A tuple of three values: the terminal version, the build number and the build's release date.
Noneon failure. Checkmt5.last_error().
Example
import MetaTrader5 as mt5
if not mt5.initialize():
raise SystemExit(mt5.last_error())
info = mt5.version()
if info is None:
print("version failed:", mt5.last_error())
else:
ver, build, released = info
print(f"terminal {ver}, build {build}, released {released}")
mt5.shutdown() Common mistakes
- This is the terminal's version, not the version of the Python package. For the package, read
mt5.__version__. - The terminal updates itself. Log the build at start-up so you can match a change in behaviour to an update.
The same with Tickwire on Linux
The package needs a Windows terminal on the same machine. Tickwire runs the terminal for you and gives you a REST API, so the code below runs on Linux, macOS or a server.
Tickwire's terminal status route reports the hosted terminal's build in terminal.build, next to whether it is alive and whether the broker link is up.
import os, requests
API = "https://api.tickwire.io"
h = {"auth-token": os.environ["TW_KEY"]} # your Tickwire key
base = f"{API}/users/current/accounts/{os.environ['TW_ACCOUNT']}"
acc = os.environ["TW_ACCOUNT"]
st = requests.get(f"{API}/mt5/{acc}/status", headers=h).json()
print(st["status"], st["terminal"]["build"]) Related functions
- mt5.initialize() in MetaTrader5 Python: connect Python to the terminal
- mt5.terminal_info() in MetaTrader5 Python: check the terminal and its broker link
- mt5.last_error() in MetaTrader5 Python: find out why the last call failed
Related error codes
MT5 from Python, on any machine
One REST API for MT4 and MT5, with idempotent orders and an audit log. Read the MT5 Python API page or the quickstart.