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

ParameterWhat it is
symbolThe 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_mode and visible.
  • None when the terminal has no such symbol or the call failed. Check mt5.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_mode is 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_min and volume_step instead of assuming 0.01. Cent and micro accounts differ, and a wrong size fails with 10014.
  • The bid and ask here are a snapshot. For a fresh price use symbol_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 error codes

All MetaTrader5 Python functions

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.