2024-02-12 21:09:28 +01:00
# History
## Table of contents
2024-11-10 12:25:50 +01:00
- [History ](#history.history )
- [\_\_init\_\_ ](#history.__init__ )
- [initialize ](#history.initialize )
- [get_deals ](#history.get_deals )
- [get_deals_by_ticket ](#history.get_deals_by_ticket )
- [get_deals_by_position ](#history.get_deals_by_position )
- [get_orders ](#history.get_orders )
- [get_orders_by_position ](#history.get_orders_by_position )
- [get_orders_by_ticket ](#history.get_orders_by_ticket )
<a id='history.history'></a>
2024-02-12 21:09:28 +01:00
### History
2023-10-11 09:49:06 +01:00
```python
class History
```
The history class handles completed trade deals and trade orders in the trading history of an account.
2024-02-12 21:09:28 +01:00
#### Attributes
| Name | Type | Description | Default |
|----------------|--------------------|------------------------------------------------------------------------|---------|
| `deals` | `list[TradeDeal]` | Iterable of trade deals | [] |
| `orders` | `list[TradeOrder]` | Iterable of trade orders | [] |
| `total_deals` | `int` | Total number of deals | 0 |
| `total_orders` | `int` | Total number orders | 0 |
| `group` | `str` | Filter for selecting history by symbols. | "" |
| `mt5` | `MetaTrader` | MetaTrader instance | None |
| `config` | `Config` | Config instance | None |
2024-11-10 12:25:50 +01:00
<a id='history.__init__'></a>
2024-02-12 21:09:28 +01:00
### \_\_init\_\_
2023-10-11 09:49:06 +01:00
```python
2024-11-10 12:25:50 +01:00
def __init__ ( * , date_from : datetime | float , date_to : datetime | float , group : str = "" )
2023-10-11 09:49:06 +01:00
```
2024-11-10 12:25:50 +01:00
#### Parameters:
2024-02-12 21:09:28 +01:00
| Name | Type | Description | Default |
|-------------|-------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|
| `date_from` | `datetime\|float` | Date the deals are requested from. Set by the 'datetime' object or as a number of seconds elapsed since 1970.01.01. Defaults to twenty-four hours from the current time in 'utc' | 0 |
| `date_to` | `datetime\|float` | Date up to which the deals are requested. Set by the 'datetime' object or as a number of seconds elapsed since 1970.01.01. Defaults to the current time in "utc" | 0 |
| `group` | `str` | Filter for selecting history by symbols. | "" |
2024-11-10 12:25:50 +01:00
<a id='history.initialize'></a>
### initialize
2023-10-11 09:49:06 +01:00
```python
2024-11-10 12:25:50 +01:00
async def initialize () -> bool
2023-10-11 09:49:06 +01:00
```
2024-11-10 12:25:50 +01:00
Get deals and orders within the timeframe specified in the constructor.
2024-02-12 21:09:28 +01:00
2024-11-10 12:25:50 +01:00
<a id='history.get_deals'></a>
2024-02-12 21:09:28 +01:00
### get_deals
2023-10-11 09:49:06 +01:00
```python
2024-11-10 12:25:50 +01:00
async def get_deals ( self ) -> tuple [ TradeDeal , ... ]
2023-10-11 09:49:06 +01:00
```
2024-11-10 12:25:50 +01:00
Get deals from trading history using the parameters set in the constructor.
2024-05-05 00:08:57 +01:00
2024-11-10 12:25:50 +01:00
#### Returns
| Name | Type | Description |
|---------|-------------------------|-----------------------|
| `deals` | `tuple[TradeDeal, ...]` | A list of trade deals |
2024-05-05 00:08:57 +01:00
2024-11-10 12:25:50 +01:00
<a id='history.get_deals_by_ticket'></a>
### get_deals_by_ticket
2024-05-05 00:08:57 +01:00
```python
2024-11-10 12:25:50 +01:00
def get_deals_by_ticket ( self , * , ticket : int ) -> tuple [ TradeDeal , ... ]
2024-05-05 00:08:57 +01:00
```
2024-11-10 12:25:50 +01:00
Get deals by ticket number. This filters deals by ticket based on the deals already fetched in initialize.
#### Parameters
| Name | Type | Description |
|----------|-------|----------------------|
| `ticket` | `int` | Ticket number to get |
2024-05-05 00:08:57 +01:00
#### Returns:
2024-11-10 12:25:50 +01:00
| Name | Type | Description |
|---------|-------------------------|------------------------|
| `deals` | `tuple[TradeDeal, ...]` | A tuple of trade deals |
2024-05-05 00:08:57 +01:00
2024-11-10 12:25:50 +01:00
<a id='history.get_deals_by_position'></a>
### get_deals_by_position
2024-05-05 00:08:57 +01:00
```python
2024-11-10 12:25:50 +01:00
async def get_deals_by_position ( self , * , position : int ) -> tuple [ TradeDeal , ... ]
2024-05-05 00:08:57 +01:00
```
Get deals by position
2024-11-10 12:25:50 +01:00
#### Parameters
| Name | Type | Description |
|------------|-------|------------------------|
| `position` | `int` | Position number to get |
2023-10-11 09:49:06 +01:00
2024-02-12 21:09:28 +01:00
#### Returns
2024-11-10 12:25:50 +01:00
| Name | Type | Description |
|---------|-------------------------|------------------------|
| `deals` | `tuple[TradeDeal, ...]` | A tuple of trade deals |
2023-10-11 09:49:06 +01:00
2024-11-10 12:25:50 +01:00
<a id='history.get_orders'></a>
2024-02-12 21:09:28 +01:00
### get_orders
2023-10-11 09:49:06 +01:00
```python
2024-11-10 12:25:50 +01:00
async def get_orders ( self ) -> tuple [ TradeOrder , ... ]
2023-10-11 09:49:06 +01:00
```
Get orders from trading history using the parameters set in the constructor.
2024-05-05 00:08:57 +01:00
2024-11-10 12:25:50 +01:00
<a id='history.get_orders_by_position'></a>
### get_orders_by_position
2024-05-05 00:08:57 +01:00
```python
2024-11-10 12:25:50 +01:00
def get_orders_by_position ( self , * , position : int ) -> tuple [ TradeOrder , ... ]
2024-05-05 00:08:57 +01:00
```
Get orders by position.
#### Parameters
2024-11-10 12:25:50 +01:00
| Name | Type | Description |
|------------|-------|------------------------|
| `position` | `int` | Position number to get |
2024-05-05 00:08:57 +01:00
#### Returns
2024-11-10 12:25:50 +01:00
| Name | Type | Description |
|----------|--------------------------|-------------------------|
| `orders` | `tuple[TradeOrder, ...]` | A tuple of trade orders |
2024-05-05 00:08:57 +01:00
2024-11-10 12:25:50 +01:00
<a id='history.get_orders_by_ticket'></a>
### get_orders_by_ticket
2024-05-05 00:08:57 +01:00
```python
2024-11-10 12:25:50 +01:00
def get_orders_by_ticket ( self , * , position : int ) -> tuple [ TradeOrder , ... ]
2024-05-05 00:08:57 +01:00
```
2024-11-10 12:25:50 +01:00
Get orders by ticket number. This filters orders by ticket based on the orders already fetched in initialize.
#### Parameters
| Name | Type | Description |
|----------|-------|----------------------|
| `ticket` | `int` | ticket number to get |
2023-10-11 09:49:06 +01:00
2024-02-12 21:09:28 +01:00
#### Returns
2024-11-10 12:25:50 +01:00
| Name | Type | Description |
|----------|--------------------------|-------------------------|
| `orders` | `tuple[TradeOrder, ...]` | A tuple of trade orders |