# MT5 Python history_deals_get()

Independent and unofficial. Not affiliated with or endorsed by any broker or platform named here. Educational only: nothing here is advice, and nothing here recommends a broker or a trade.

This is the markdown version of https://openbrokerapi.com/platforms/metatrader-5/functions/python-history-deals-get, written from the same records as that page.

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.

Returns deals from the account's trading history: those between two dates, optionally filtered by symbol, or those of one order, or those of one position.

- Function: `history_deals_get()`
- Interface: MetaTrader5 Python package
- Group: History
- Status: verified. Source: [mql5.com](https://www.mql5.com/en/docs/python_metatrader5/mt5historydealsget_py), checked 2026-10-12.

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. It is in no OpenAPI file on this site and the request builder does not list it.

Note: The page shows three forms of the call: an interval with an optional group filter, an order ticket alone, and a position alone. The two dates are required only in the first form. A deal is one execution, so one order can produce several.

## Signature

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

```python
history_deals_get(
  date_from,
  date_to,
  group="GROUP"
)
```

```python
history_deals_get(
  ticket=TICKET
)
```

```python
history_deals_get(
  position=POSITION
)
```

## Arguments

- `date_from` (type datetime or int, required): The 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_to` (type datetime or int, required): The end of the interval, given the same way. Required in that form, where it comes second.
- `group` (type not stated, optional): A 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.
- `ticket` (type not stated, optional): An order's ticket, to return every deal that carries it in its DEAL_ORDER property. Used on its own, in place of the interval.
- `position` (type not stated, optional): A position's ticket, to return every deal that carries it in its DEAL_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 deal. 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.

```python
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)
deals = mt5.history_deals_get(start, end)
for d in deals or ():
    print(d.ticket, d.symbol, d.volume, d.price, d.profit, d.commission)

mt5.shutdown()
```

## Related MT5 Python functions: History

- [history_deals_total()](https://openbrokerapi.com/platforms/metatrader-5/functions/python-history-deals-total): Returns how many deals are in the account's trading history between two dates.
- [history_orders_get()](https://openbrokerapi.com/platforms/metatrader-5/functions/python-history-orders-get): 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.
- [history_orders_total()](https://openbrokerapi.com/platforms/metatrader-5/functions/python-history-orders-total): Returns how many orders are in the account's trading history between two dates.

## More on MetaTrader 5

- [All MetaTrader 5 functions](https://openbrokerapi.com/platforms/metatrader-5/functions): 78 documented here, grouped by what they do.
- [Trade history: the call at each API](https://openbrokerapi.com/endpoints/history): The same job at every broker and platform API recorded here, HTTP or not.
- [MetaTrader 5 API quickstart](https://openbrokerapi.com/platforms/metatrader-5/quickstart)
- [All MetaTrader 5 error codes](https://openbrokerapi.com/errors/mt5)
- [MetaTrader 5 API page](https://openbrokerapi.com/platforms/metatrader-5): The full record: access, authentication, limits and the source for each.

## Licence and how to cite

The records behind this page are all rights reserved. This file is the page itself, at its own address, in another format. It is not part of the CC BY 4.0 downloads listed at https://openbrokerapi.com/data. Quote from it with a link to the page.

Cite as: MT5 Python history_deals_get(). Broker API Hub, https://openbrokerapi.com/platforms/metatrader-5/functions/python-history-deals-get, newest check 2026-10-12.

Where you rely on a single figure, cite the source and the checked date printed beside it as well. Where this page and a broker's own documentation differ, the documentation wins.
