mt5.symbol_info_tick() in MetaTrader5 Python: get the latest bid and ask
Returns the last tick of a symbol: time, bid, ask, last price and volume. Use it for the current price. Returns None when there is no tick.
Signature
mt5.symbol_info_tick(symbol) What it does
symbol_info_tick() is the usual way to read the price right now, for example to set the price of a market order.
The result is a named tuple. time is in seconds and time_msc is the same moment in milliseconds.
Parameters
| Parameter | What it is |
|---|---|
symbol | The symbol name, exactly as the broker spells it. Required. |
What it returns
- A named tuple with
time,bid,ask,last,volume,time_msc,flagsandvolume_real. Nonewhen the symbol is unknown, not selected, or has no tick yet. Checkmt5.last_error().
Example
import MetaTrader5 as mt5
if not mt5.initialize():
raise SystemExit(mt5.last_error())
mt5.symbol_select("EURUSD", True)
tick = mt5.symbol_info_tick("EURUSD")
if tick is None:
raise SystemExit(mt5.last_error())
print(tick.bid, tick.ask, f"spread {tick.ask - tick.bid:.5f}")
print("tick at", tick.time_msc, "ms on the broker's clock")
mt5.shutdown() Common mistakes
tick.timecounts seconds on the broker's server clock, not true UTC. Many brokers run two or three hours ahead of UTC, so comparing it with your own clock gives a wrong age.- A symbol that is not in Market Watch has no fresh ticks. Call
symbol_select(symbol, True)first. - At the weekend the last tick can be days old. Check its age before you trust it.
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 current-tick and current-price routes return the latest price. Times come as UTC in time and as broker time in brokerTime, clearly labelled, so the age is easy to work out. On MT5 a hidden symbol is added to Market Watch for you.
See Time zones for how broker time is measured.
GET /users/current/accounts/{account_id}/symbols/{symbol}/current-tickGET /users/current/accounts/{account_id}/symbols/{symbol}/current-priceGET /users/current/accounts/{account_id}/server-time
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']}"
tick = requests.get(f"{base}/symbols/EURUSD/current-tick", headers=h).json()
print(tick["bid"], tick["ask"], tick["time"], tick["brokerTime"]) Related functions
- mt5.symbol_info() in MetaTrader5 Python: read a symbol's settings and limits
- mt5.symbol_select() in MetaTrader5 Python: add a symbol to Market Watch
- mt5.copy_ticks_from() in MetaTrader5 Python: get ticks forward from a date
- mt5.order_send() in MetaTrader5 Python: place, change or close a trade
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.