mt5.symbols_total() in MetaTrader5 Python: count every symbol the terminal knows

Returns how many symbols the MetaTrader 5 terminal knows, including custom symbols and ones hidden from Market Watch. Returns an integer.

Signature

mt5.symbols_total()

What it does

symbols_total() counts every instrument the broker's server lists for the account, not only the ones shown in Market Watch.

Use it as a quick check that the symbol list has loaded, or to size a loop before you call symbols_get().

What it returns

  • An integer: the number of symbols.
  • A count of 0 right after start-up can mean the list has not arrived from the server yet.

Example

import MetaTrader5 as mt5

if not mt5.initialize():
    raise SystemExit(mt5.last_error())

total = mt5.symbols_total()
shown = len(mt5.symbols_get() or ())
print(f"{total} symbols on the server, {shown} returned by symbols_get()")
mt5.shutdown()

Common mistakes

  • The count includes symbols that are not in Market Watch. Most functions that read prices need the symbol selected first, see symbol_select().

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 symbols route returns the names of every symbol the terminal knows, as a JSON array. Its length is the same count.

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']}"

names = requests.get(f"{base}/symbols", headers=h).json()
print(len(names), "symbols")

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.