Broker API HubMenu

MT5 Python history_orders_get()

functionhistory_orders_get()MetaTrader5 Python packageHistory

Returns orders from the account's trading history: those between two dates, optionally filtered by symbol, or the one with a given ticket, or those of one position.

Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.

Independent and unofficialmql5.comchecked

This is a Python function, not an HTTP endpoint. It has no method, no path and no address to send a request to: the package talks to a MetaTrader 5 terminal running on the same computer.

The page shows three forms of the call: an interval with an optional group filter, a ticket alone, and a position alone. The two dates are required only in the first form.

Signature

The 3 forms of the call on the vendor's page, with the vendor's comments taken out.

history_orders_get(
  date_from,
  date_to,
  group="GROUP"
)
history_orders_get(
  ticket=TICKET
)
history_orders_get(
  position=POSITION
)

Arguments

NameTypeDescription
date_fromrequireddatetime or intThe start of the interval. The page says it is given as a datetime object or as a number of seconds since 1 January 1970. Required in the form of the call that takes an interval, where it comes first.
date_torequireddatetime or intThe end of the interval, given the same way. Required in that form, where it comes second.
groupNot statedA filter on symbol names. The page describes it as comma separated conditions, where * is a wildcard and a leading ! excludes, applied in the order given.
ticketNot statedThe ticket of the one order wanted. Used on its own, in place of the interval.
positionNot statedA position's ticket, to return every order that carries it in its ORDER_POSITION_ID property. Used on its own, in place of the interval.

Return value

Type
tuple of namedtuples, or None
What comes back
One named tuple per order. On failure the page says it returns None, and that last_error() gives the reason.

Sample

Written by this site from the signature and arguments recorded on this page. It has not been run against a terminal, a server or an account, and the values in it are placeholders. No credential is typed into it: where one is needed it is read from an environment variable on your own machine. Nothing is entered on this site.

from datetime import datetime, timezone
import MetaTrader5 as mt5

if not mt5.initialize():
    raise SystemExit(f"initialize() failed: {mt5.last_error()}")

start = datetime(2026, 1, 1, tzinfo=timezone.utc)
end = datetime.now(timezone.utc)
orders = mt5.history_orders_get(start, end, group="*USD*")
for o in orders or ():
    print(o.ticket, o.symbol, o.type, o.volume_initial, o.state)

mt5.shutdown()