Files
aiomql/docs/core/base.md
T

136 lines
4.4 KiB
Markdown
Raw Normal View History

2024-11-13 04:29:37 +01:00
# Base
2024-02-12 21:09:28 +01:00
## Table of Contents
2024-11-13 04:29:37 +01:00
- [Base](#base.base)
- [set_attributes](#base.set_attributes)
- [annotations](#base.annotations)
- [get_dict](#base.get_dict)
- [class_vars](#base.class_vars)
- [dict](#base.dict)
- [_Base](#_base._base)
<a id="base.base"></a>
2024-02-12 21:09:28 +01:00
### Base
2023-10-11 09:49:06 +01:00
```python
2024-02-12 21:09:28 +01:00
class Base
2023-10-11 09:49:06 +01:00
```
2024-02-12 21:09:28 +01:00
A base class for all data model classes in the aiomql package. This class provides a set of common methods
and attributes for all data model classes.
2023-10-11 09:49:06 +01:00
2024-11-13 04:29:37 +01:00
#### Attributes:
| Name | Type | Description |
|-----------|-------|------------------------------------------------------------------------------------------------------|
| `exclude` | `set` | A set of attributes to be excluded when retrieving attributes using the *get_dict* and *dict* method |
| `include` | `set` | A set of attributes to be included when retrieving attributes using the *get_dict* and *dict* method |
2023-10-11 09:49:06 +01:00
2024-02-12 21:09:28 +01:00
<a id="base.__init__"></a>
### __init__
```python
def __init__(**kwargs)
```
#### Parameters:
| Name | Type | Description |
|----------|-------|---------------------------------------------------|
| `kwargs` | `Any` | Object attributes and values as keyword arguments |
2023-10-11 09:49:06 +01:00
2024-11-13 04:29:37 +01:00
2024-02-12 21:09:28 +01:00
<a id="base.set_attributes"></a>
### set_attributes
2023-10-11 09:49:06 +01:00
```python
def set_attributes(**kwargs)
```
2024-02-12 21:09:28 +01:00
Set keyword arguments as object attributes. Only sets attributes that have been annotated on the class body.
2024-11-13 04:29:37 +01:00
#### Parameters:
2024-02-12 21:09:28 +01:00
| Name | Type | Description |
|----------|-------|---------------------------------------------------|
| `kwargs` | `Any` | Object attributes and values as keyword arguments |
2024-11-13 04:29:37 +01:00
#### Raises:
2024-02-12 21:09:28 +01:00
| Exception | Description |
|------------------|-----------------------------------------------------------------------------------|
| `AttributeError` | When assigning an attribute that does not belong to the class or any parent class |
2024-11-13 04:29:37 +01:00
#### Notes:
2024-02-12 21:09:28 +01:00
Only sets attributes that have been annotated on the class body.
2024-11-13 04:29:37 +01:00
2024-02-12 21:09:28 +01:00
<a id="base.annotations"></a>
### annotations
2023-10-11 09:49:06 +01:00
```python
@property
@cache
def annotations() -> dict
```
Class annotations from all ancestor classes and the current class.
2024-11-13 04:29:37 +01:00
#### Returns:
| Type | Description |
|------------------|-----------------------------------|
| `dict[str, Any]` | A dictionary of class annotations |
2023-10-11 09:49:06 +01:00
2024-02-12 21:09:28 +01:00
<a id="base.get_dict"></a>
2024-11-13 04:29:37 +01:00
#### get_dict
2023-10-11 09:49:06 +01:00
```python
def get_dict(exclude: set = None, include: set = None) -> dict
```
Returns class attributes as a dict, with the ability to filter
2024-11-13 04:29:37 +01:00
#### Parameters:
2024-02-12 21:09:28 +01:00
| Name | Type | Description |
|-----------|-------|------------------------------------|
| `exclude` | `set` | A set of attributes to be excluded |
| `include` | `set` | Specific attributes to be returned |
2024-11-13 04:29:37 +01:00
#### Returns:
2024-02-12 21:09:28 +01:00
| Type | Description |
|--------|--------------------------------------------|
| `dict` | A dictionary of specified class attributes |
2024-11-13 04:29:37 +01:00
#### Notes:
2024-02-12 21:09:28 +01:00
You can only set either of include or exclude. If you set both, include will take precedence
2024-11-13 04:29:37 +01:00
2024-02-12 21:09:28 +01:00
<a id="base.class_vars"></a>
2024-11-13 04:29:37 +01:00
### class_vars
2023-10-11 09:49:06 +01:00
```python
@property
@cache
def class_vars()
```
Annotated class attributes
2024-11-13 04:29:37 +01:00
#### Returns:
2024-02-12 21:09:28 +01:00
| Type | Description |
|--------|-------------------------------------------------------------------------------------------|
| `dict` | A dictionary of available class attributes in all ancestor classes and the current class. |
2023-10-11 09:49:06 +01:00
2024-11-13 04:29:37 +01:00
2024-02-12 21:09:28 +01:00
<a id="base.dict"></a>
### dict
2023-10-11 09:49:06 +01:00
```python
@property
def dict() -> dict
```
All instance and class attributes as a dictionary, except those excluded in the Meta class.
2024-11-13 04:29:37 +01:00
#### Returns:
2024-02-12 21:09:28 +01:00
| Type | Description |
|--------|-----------------------------------------------|
| `dict` | A dictionary of instance and class attributes |
2024-11-13 04:29:37 +01:00
<a id="_base._base></a>
### _Base(Base)
Base class that provides access to the MetaTrader and Config classes as well as the MetaBackTester class for
backtesting mode.
#### Attributes:
| Name | Type | Description | Default |
|----------|--------------|-------------------------------------|---------|
| `mt5` | `MetaTrader` | An instance of the MetaTrader class | |
| `config` | `Config` | An instance of the Config class | |