mt5.symbol_info() in MetaTrader5 Python: read a symbol's settings and limits
Returns everything the terminal knows about one symbol as a named tuple: digits, point, contract size, volume limits, filling modes and more. None if unknown.
Signature
mt5.symbol_info(symbol) What it does
Use symbol_info() before you build an order. It tells you the smallest volume, the volume step, how many digits a price has, and which filling modes the broker allows.
It also carries visible, which says whether the symbol is in Market Watch.
Parameters
| Parameter | What it is |
|---|---|
symbol | The symbol name, exactly as the broker spells it. Required. |
What it returns
- A named tuple with fields such as
name,bid,ask,digits,point,spread,trade_contract_size,volume_min,volume_max,volume_step,filling_mode,trade_modeandvisible. Nonewhen the terminal has no such symbol or the call failed. Checkmt5.last_error().
Example
import MetaTrader5 as mt5
if not mt5.initialize():
raise SystemExit(mt5.last_error())
info = mt5.symbol_info("EURUSD")
if info is None:
raise SystemExit(f"unknown symbol: {mt5.last_error()}")
if not info.visible:
mt5.symbol_select("EURUSD", True)
# Round a wanted size to what the broker accepts
wanted = 0.123
lots = max(info.volume_min, round(wanted / info.volume_step) * info.volume_step)
print(f"send {lots:.2f} lots, prices have {info.digits} digits")
mt5.shutdown() Common mistakes
filling_modeis a set of bit flags, not one value: 1 means fill or kill is allowed and 2 means immediate or cancel is allowed. A request with a mode the symbol does not allow fails with 10030.- Read
volume_minandvolume_stepinstead of assuming 0.01. Cent and micro accounts differ, and a wrong size fails with 10014. - The
bidandaskhere are a snapshot. For a fresh price usesymbol_info_tick().
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 specification route returns the same settings as JSON: tickSize, minVolume, maxVolume, volumeStep, contractSize, fillingModes, digits, point and more. On MT5 it adds a hidden symbol to Market Watch for you first.
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']}"
spec = requests.get(f"{base}/symbols/EURUSD/specification", headers=h).json()
print(spec["minVolume"], spec["volumeStep"], spec["fillingModes"]) Related functions
- mt5.symbol_info_tick() in MetaTrader5 Python: get the latest bid and ask
- mt5.symbol_select() in MetaTrader5 Python: add a symbol to Market Watch
- mt5.symbols_get() in MetaTrader5 Python: list symbols, with an optional filter
- mt5.order_check() in MetaTrader5 Python: test an order before you send it
Related error codes
- MT5 error 4301: Unknown symbol (ERR_MARKET_UNKNOWN_SYMBOL)
- MT5 error 4302: Symbol is not selected in Market Watch (ERR_MARKET_NOT_SELECTED)
- MT5 error 10030: Invalid order filling type (TRADE_RETCODE_INVALID_FILL)
- MT5 error 10014: Invalid volume (TRADE_RETCODE_INVALID_VOLUME)
- MT5 Python error -4: Not found (RES_E_NOT_FOUND)
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.