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
| Parameter | What it is |
|---|---|
symbol | Only items on this symbol. Optional. |
group | Only items whose symbol matches a filter, such as "*USD*". * is a wildcard, commas separate patterns and ! leaves one out. Optional. |
ticket | Only the item with this ticket. Optional. |
What it returns
- A tuple of order records. An empty tuple means there are none.
Noneon failure. Checkmt5.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
typeis a number. Compare it with constants such asmt5.ORDER_TYPE_BUY_LIMIT, not with text.- Tell
None(the call failed) apart from an empty tuple (no orders). TreatingNoneas "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.
GET /users/current/accounts/{account_id}/ordersGET /users/current/accounts/{account_id}/orders/{order_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 functions
- mt5.orders_total() in MetaTrader5 Python: count pending orders
- mt5.positions_get() in MetaTrader5 Python: read open positions
- mt5.history_orders_get() in MetaTrader5 Python: read past orders
- 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.