Files
aiomql/docs/core/backtesting/get_data.md
T

163 lines
5.9 KiB
Markdown
Raw Normal View History

2024-11-15 21:13:19 +01:00
# Get Data
2024-11-13 04:29:37 +01:00
2024-11-15 21:13:19 +01:00
## Table of Contents
2024-11-13 04:29:37 +01:00
2024-11-15 21:13:19 +01:00
- [Cursor](#get_data.cursor)
- [BackTestData](#get_data.back_test_data)
- [set_attrs](#get_data.back_test_data.set_attrs)
- [fields](#get_data.back_test_data.fields)
- [GetData](#get_data.getdata)
- [\__init\__](#get_data.get_data.__init__)
- [pickle_data](#get_data.pickle_data)
- [load_data](#get_data.load_data)
- [save_data](#get_data.save_data)
- [get_data](#get_data.get_data)
2024-11-13 04:29:37 +01:00
2024-11-15 21:13:19 +01:00
<a id="get_data.cursor"></a>
### Cursor
2024-11-13 04:29:37 +01:00
```python
class Cursor(NamedTuple)
```
2024-11-15 21:13:19 +01:00
A cursor to iterate over the data. Marks the current position in time.
2024-11-13 04:29:37 +01:00
2024-11-15 21:13:19 +01:00
<a id="get_data.back_test_data"></a>
### BackTestData
2024-11-13 04:29:37 +01:00
```python
@dataclass
2024-11-15 21:13:19 +01:00
class BackTestData
2024-11-13 04:29:37 +01:00
```
The data class to store the backtesting data.
2024-11-15 21:13:19 +01:00
#### Attributes:
| Name | Type | Description |
|------------------|----------|------------------------------------------------|
| `name` | `str` | The name of the backtest data |
| `terminal` | `dict` | The terminal information |
| `version` | `tuple` | The version of the terminal |
| `account` | `dict` | The account information |
| `symbols` | `dict` | The symbols information |
| `ticks` | `dict` | The ticks data |
| `rates` | `dict` | The rates data |
| `span` | `range` | The range of the data |
| `range` | `range` | The range of the data |
| `orders` | `dict` | The orders data |
| `deals` | `dict` | The deals data |
| `positions` | `dict` | The positions data |
| `open_positions` | `set` | The open positions |
| `cursor` | `Cursor` | The cursor to iterate over the data |
| `margins` | `dict` | The margins data |
| `fully_loaded` | `bool` | A flag to indicate if the data is fully loaded |
<a id="get_data.set_attrs"></a>
#### set_attrs
2024-11-13 04:29:37 +01:00
```python
def set_attrs(**kwargs)
```
Set the attributes of the class on the instance.
2024-11-15 21:13:19 +01:00
<a id="get_data.fields"></a>
2024-11-13 04:29:37 +01:00
#### fields
```python
@property
def fields()
```
A list of the fields of the class.
2024-11-15 21:13:19 +01:00
<a id="get_data.getdata"></a>
### GetData
2024-11-13 04:29:37 +01:00
```python
2024-11-15 21:13:19 +01:00
class GetData
2024-11-13 04:29:37 +01:00
```
A class to get the backtesting data from the MetaTrader5 terminal.
2024-11-15 21:13:19 +01:00
#### Attributes:
| Name | Type | Description |
|--------------|-----------------------|---------------------------------------|
| `start` | `datetime` | The start date of the data |
| `end` | `datetime` | The end date of the data |
| `symbols` | `Iterable[str]` | The symbols to get the data for |
| `timeframes` | `Iterable[TimeFrame]` | The timeframes to get the data for |
| `name` | `str` | The name of the backtest data |
| `range` | `range` | The range of the data |
| `span` | `range` | The span of the data |
| `data` | `BackTestData` | The backtesting data |
| `mt5` | `MetaTrader` | The MetaTrader5 instance |
| `task_queue` | `TaskQueue` | The task queue to handle the requests |
<a id="get_data.__init__"></a>
#### \__init\__
2024-11-13 04:29:37 +01:00
```python
2024-11-15 21:13:19 +01:00
def __init__(*, start: datetime, end: datetime, symbols: Sequence[str],
timeframes: Sequence[TimeFrame], name: str = "")
2024-11-13 04:29:37 +01:00
```
Get the backtesting data from the MetaTrader5 terminal.
2024-11-15 21:13:19 +01:00
#### Parameters:
| Name | Type | Description |
|--------------|-----------------------|------------------------------------------------|
| `start` | `datetime` | The start date of the data |
| `end` | `datetime` | The end date of the data |
| `symbols` | `Sequence[str]` | The symbols to get the data for |
| `timeframes` | `Sequence[TimeFrame]` | The timeframes to get the data for |
| `name` | `str` | The name of the backtest data |
2024-11-13 04:29:37 +01:00
2024-11-15 21:13:19 +01:00
<a id="get_data.pickle_data"></a>
#### pickle_data
2024-11-13 04:29:37 +01:00
```python
@classmethod
def pickle_data(cls, *, data: BackTestData, name: str | Path)
```
Pickle the data to a file.
2024-11-15 21:13:19 +01:00
#### Parameters:
| Name | Type | Description |
|--------|-------------------------|----------------------|
| `data` | `BackTestData` | The data to pickle |
| `name` | `str \| Path` | The name of the file |
2024-11-13 04:29:37 +01:00
2024-11-15 21:13:19 +01:00
<a id="get_data.load_data"></a>
#### load_data
2024-11-13 04:29:37 +01:00
```python
@classmethod
def load_data(cls, *, name: str | Path) -> BackTestData
```
Load the data from a file.
2024-11-15 21:13:19 +01:00
#### Parameters:
| Name | Type | Description |
|--------|-------------------------|----------------------|
| `name` | `str \| Path` | The name of the file |
2024-11-13 04:29:37 +01:00
2024-11-15 21:13:19 +01:00
<a id="get_data.save_data"></a>
#### save_data
2024-11-13 04:29:37 +01:00
```python
def save_data(*, name: str | Path = "")
```
Save the data to a file.
2024-11-15 21:13:19 +01:00
#### Parameters:
| Name | Type | Description |
|--------|-------------------------|----------------------|
| `name` | `str \| Path` | The name of the file |
2024-11-13 04:29:37 +01:00
2024-11-15 21:13:19 +01:00
<a id="get_data.get_data"></a>
#### get_data
2024-11-13 04:29:37 +01:00
```python
async def get_data(workers: int = None)
```
Use the task queue to get the data from the MetaTrader5 terminal.
2024-11-15 21:13:19 +01:00
#### Parameters:
| Name | Type | Description |
|-----------|-------|------------------------------------------------|
| `workers` | `int` | The number of workers to use in the task queue |