mt5.orders_get() in MetaTrader5 Python: read pending orders

Returns the account's pending orders as a tuple of named tuples, all of them or filtered by symbol, group or ticket. Returns None on failure.

Signature

mt5.orders_get()
mt5.orders_get(symbol="...")
mt5.orders_get(group="...")
mt5.orders_get(ticket=...)

What it does

orders_get() lists limit and stop orders that have not filled yet. Give at most one filter.

Each item has fields such as ticket, symbol, type, volume_initial, volume_current, price_open, sl, tp and magic.

Parameters

ParameterWhat it is
symbolOnly items on this symbol. Optional.
groupOnly items whose symbol matches a filter, such as "*USD*". * is a wildcard, commas separate patterns and ! leaves one out. Optional.
ticketOnly the item with this ticket. Optional.

What it returns

  • A tuple of order records. An empty tuple means there are none.
  • None on failure. Check mt5.last_error().

Example

import MetaTrader5 as mt5

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

orders = mt5.orders_get(symbol="EURUSD")
if orders is None:
    raise SystemExit(mt5.last_error())
for o in orders:
    print(o.ticket, o.type, o.volume_current, o.price_open)
mt5.shutdown()

Common mistakes

  • type is a number. Compare it with constants such as mt5.ORDER_TYPE_BUY_LIMIT, not with text.
  • Tell None (the call failed) apart from an empty tuple (no orders). Treating None as "no orders" hides real problems.

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 orders route returns pending orders as JSON with id, symbol, type as text such as ORDER_TYPE_BUY_LIMIT, volume, currentVolume and openPrice. The single-order route reads one by id.

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

for o in requests.get(f"{base}/orders", headers=h).json():
    if o["symbol"] == "EURUSD":
        print(o["id"], o["type"], o["openPrice"])

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.