mirror of
https://github.com/Ichinga-Samuel/aiomql.git
synced 2026-08-21 07:48:06 +00:00
v4
This commit is contained in:
+54
-29
@@ -1,30 +1,55 @@
|
|||||||
# Table of Contents
|
# Table of Contents
|
||||||
- [MetaTrader](core/meta_trader.md)
|
|
||||||
- [Config](core/config.md)
|
- [Core](core)
|
||||||
- [Base](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/core/base.md)
|
- [MetaTrader](core/meta_trader.md)
|
||||||
- [Constants](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/core/constants.md)
|
- [Config](core/config.md)
|
||||||
- [TaskQueue](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/core/task_queue.md)
|
- [Base](core/base.md)
|
||||||
- [Models](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/core/models.md)
|
- [Constants](core/constants.md)
|
||||||
- [Bot_Builder](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/bot_builder.md)
|
- [TaskQueue](core/task_queue.md)
|
||||||
- [Account](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/account.md)
|
- [Models](core/models.md)
|
||||||
- [Candle](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/candle.md)
|
- [Errors](core/errors.md)
|
||||||
- [Candles](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/candle.md)
|
- [Exceptions](core/exceptions.md)
|
||||||
- [Executor](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/executor.md)
|
- [MetaBackTester](core/meta_backtester.md)
|
||||||
- [History](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/history.md)
|
|
||||||
- [Order](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/order.md)
|
- [BackTesting](core/backtesting)
|
||||||
- [Positions](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/postions.md)
|
- [BackTestAccount](core/backtesting/backtest_account.md)
|
||||||
- [RAM](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/ram.md)
|
- [BackTestEngine](core/backtesting/backtest_engine.md)
|
||||||
- [Records](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/records.md)
|
- [GetData](core/backtesting/get_data.md)
|
||||||
- [TradeRecords](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/trade_records.md)
|
- [TradesManager](core/backtesting/trades_manager.md)
|
||||||
- [Result](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/result.md)
|
- [BackTestController](core/backtesting/backtest_controller.md)
|
||||||
- [Session](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/sessions.md)
|
|
||||||
- [Sessions](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/sessions.md)
|
- [Lib](lib)
|
||||||
- [Symbol](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/symbol.md)
|
- [Account](lib/account.md)
|
||||||
- [Strategy](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/stategy.md)
|
- [Bot](lib/bot.md)
|
||||||
- [Terminal](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/terminal.md)
|
- [Candle](lib/candle.md)
|
||||||
- [Tick](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/ticks.md)
|
- [Candles](lib/candle.md)
|
||||||
- [Ticks](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/ticks.md)
|
- [History](lib/history.md)
|
||||||
- [Trader](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/trader.md)
|
- [Order](lib/order.md)
|
||||||
- [utils](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/utils.md)
|
- [Positions](lib/positions.md)
|
||||||
- [Errors](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/core/errors.md)
|
- [RAM](lib/ram.md)
|
||||||
- [Exceptions](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/core/exceptions.md)
|
- [TradeRecords](lib/trade_records.md)
|
||||||
|
- [Result](lib/result.md)
|
||||||
|
- [Session](lib/sessions.md)
|
||||||
|
- [Sessions](lib/sessions.md)
|
||||||
|
- [Symbol](lib/symbol.md)
|
||||||
|
- [Strategy](lib/strategy.md)
|
||||||
|
- [Terminal](lib/terminal.md)
|
||||||
|
- [Tick](lib/ticks.md)
|
||||||
|
- [Ticks](lib/ticks.md)
|
||||||
|
- [Trader](lib/trader.md)
|
||||||
|
|
||||||
|
- [Contrib](contrib)
|
||||||
|
- [CandlePatterns](contrib/candle_patterns)
|
||||||
|
- [Fractals](contrib/candle_patterns/fractals.md)
|
||||||
|
|
||||||
|
- [Symbols](contrib/symbols)
|
||||||
|
- [ForexSymbol](contrib/symbols/forex_symbol.md)
|
||||||
|
|
||||||
|
- [Utils](contrib/utils)
|
||||||
|
- [Tracker](contrib/utils/tracker.md)
|
||||||
|
|
||||||
|
- [Traders](contrib/traders)
|
||||||
|
- [ScalpTrader](contrib/traders/scalp_trader.md)
|
||||||
|
- [SimpleTrader](contrib/traders/simple_trader.md)
|
||||||
|
|
||||||
|
- [Utils](_utils.md)
|
||||||
|
|||||||
+128
@@ -0,0 +1,128 @@
|
|||||||
|
# Utils
|
||||||
|
Utils is a collection of utility functions that are used throughout the codebase. It is a collection of functions.
|
||||||
|
|
||||||
|
## Table of Contents
|
||||||
|
- [round_off](#_utiils.round_off)
|
||||||
|
- [dict_to_string](#_utils.dict_to_string)
|
||||||
|
- [round_down](#_utils.round_down)
|
||||||
|
- [round_up](#_utils.round_up)
|
||||||
|
- [async_cache](#_utils.async_cache)
|
||||||
|
- [backoff_decorator](#_utils.backoff_decorator)
|
||||||
|
- [error_handler](#_utils.error_handler)
|
||||||
|
- [error_handler_sync](#_utils.error_handler_sync)
|
||||||
|
|
||||||
|
|
||||||
|
<a id="_utils.round_off"></a>
|
||||||
|
### round_off
|
||||||
|
```python
|
||||||
|
def round_off(value: float, step: float, round_down: bool = True) -> float:
|
||||||
|
```
|
||||||
|
Rounds off a value to the nearest step. If round_down is True, it will round down, otherwise it will round up.
|
||||||
|
|
||||||
|
#### Parameters:
|
||||||
|
| Name | Type | Description | Default |
|
||||||
|
|------------|-------|--------------------------------------------|---------|
|
||||||
|
| value | float | The value to round off. | |
|
||||||
|
| step | float | The step to round off to. | |
|
||||||
|
| round_down | bool | Whether to round down. If False, round up. | True |
|
||||||
|
|
||||||
|
#### Returns:
|
||||||
|
| Type | Description |
|
||||||
|
|-------|------------------------|
|
||||||
|
| float | The rounded off value. |
|
||||||
|
|
||||||
|
|
||||||
|
<a id="_utils.dict_to_string"></a>
|
||||||
|
### dict_to_string
|
||||||
|
```python
|
||||||
|
def dict_to_string(data: dict, multi=True) -> str:
|
||||||
|
```
|
||||||
|
Converts a dictionary to a string. If multi is True, it will return a multi-line string.
|
||||||
|
|
||||||
|
#### Parameters:
|
||||||
|
| Name | Type | Description | Default |
|
||||||
|
|-------|------|----------------------------------------|---------|
|
||||||
|
| data | dict | The dictionary to convert to a string. | |
|
||||||
|
| multi | bool | Whether to return a multi-line string. | True |
|
||||||
|
|
||||||
|
#### Returns:
|
||||||
|
| Type | Description |
|
||||||
|
|------|-----------------------------|
|
||||||
|
| str | The dictionary as a string. |
|
||||||
|
|
||||||
|
|
||||||
|
<a id="_utils.round_down"></a>
|
||||||
|
### round_down
|
||||||
|
```python
|
||||||
|
def round_down(value: float, base: int) -> int:
|
||||||
|
```
|
||||||
|
Rounds down a value to the nearest base.
|
||||||
|
|
||||||
|
#### Parameters:
|
||||||
|
| Name | Type | Description |
|
||||||
|
|-------|-------|------------------------------------|
|
||||||
|
| value | float | The value to round down. |
|
||||||
|
| base | int | The base to round down to. |
|
||||||
|
|
||||||
|
|
||||||
|
<a id="_utils.round_up"></a>
|
||||||
|
### round_up
|
||||||
|
```python
|
||||||
|
def round_up(value: float, base: int) -> int:
|
||||||
|
```
|
||||||
|
Rounds up a value to the nearest base.
|
||||||
|
|
||||||
|
#### Parameters:
|
||||||
|
| Name | Type | Description |
|
||||||
|
|-------|-------|----------------------------------|
|
||||||
|
| value | float | The value to round up. |
|
||||||
|
| base | int | The base to round up to. |
|
||||||
|
|
||||||
|
|
||||||
|
<a id="_utils.async_cache"></a>
|
||||||
|
### async_cache
|
||||||
|
```python
|
||||||
|
def async_cache(func: Callable) -> Callable:
|
||||||
|
```
|
||||||
|
A decorator to cache the result of an async function.
|
||||||
|
|
||||||
|
|
||||||
|
<a id="_utils.backoff_decorator"></a>
|
||||||
|
### backoff_decorator
|
||||||
|
```python
|
||||||
|
def backoff_decorator(func=None, *, max_retries: int = 2, retries: int = 0, error="") -> Callable:
|
||||||
|
```
|
||||||
|
A decorator to retry a function with exponential backoff.
|
||||||
|
|
||||||
|
#### Parameters:
|
||||||
|
| Name | Type | Description | Default |
|
||||||
|
|-------------|------|--------------------------------------------|---------|
|
||||||
|
| func | | The function to decorate. | |
|
||||||
|
| max_retries | int | The maximum number of retries. | 2 |
|
||||||
|
| retries | int | The current number of retries. | 0 |
|
||||||
|
| error | str | The error message to display on exception. | |
|
||||||
|
|
||||||
|
|
||||||
|
<a id="_utils.error_handler"></a>
|
||||||
|
### error_handler
|
||||||
|
```python
|
||||||
|
async def error_handler(func=None, *, msg="", exe=Exception, response=None, log_error_msg=True) -> Callable:
|
||||||
|
```
|
||||||
|
A decorator to handle exceptions in an async function.
|
||||||
|
|
||||||
|
#### Parameters:
|
||||||
|
| Name | Type | Description | Default |
|
||||||
|
|---------------|------|--------------------------------------------|---------|
|
||||||
|
| func | | The function to decorate. | |
|
||||||
|
| msg | str | The error message to display on exception. | |
|
||||||
|
| exe | | The exception to catch. | |
|
||||||
|
| response | | The response to return on exception. | |
|
||||||
|
| log_error_msg | bool | Whether to log the error message. | True |
|
||||||
|
|
||||||
|
|
||||||
|
<a id="_utils.error_handler_sync"></a>
|
||||||
|
### error_handler_sync
|
||||||
|
```python
|
||||||
|
def error_handler_sync(func=None, *, msg="", exe=Exception, response=None, log_error_msg=True) -> Callable:
|
||||||
|
```
|
||||||
|
A decorator to handle exceptions in a sync function.
|
||||||
@@ -1,58 +1,55 @@
|
|||||||
# Table of Contents
|
# BackTestAccount
|
||||||
|
|
||||||
* [backtest\_account](#backtest_account)
|
## Table of Contents
|
||||||
* [BackTestAccount](#backtest_account.BackTestAccount)
|
- [BackTestAccount](#back_test_account.back_test_account)
|
||||||
* [get\_dict](#backtest_account.BackTestAccount.get_dict)
|
- [get_dict](#back_test_account.back_test_account.get_dict)
|
||||||
* [asdict](#backtest_account.BackTestAccount.asdict)
|
- [asdict](#back_test_account.asdict)
|
||||||
* [set\_attrs](#backtest_account.BackTestAccount.set_attrs)
|
- [set_attrs](#back_test_account.set_attrs)
|
||||||
|
|
||||||
<a id="backtest_account"></a>
|
|
||||||
|
|
||||||
# backtest\_account
|
|
||||||
|
|
||||||
<a id="backtest_account.BackTestAccount"></a>
|
|
||||||
|
|
||||||
## BackTestAccount Objects
|
|
||||||
|
|
||||||
|
### BackTestAccount
|
||||||
|
<a id="back_test_account.back_test_account"></a>
|
||||||
```python
|
```python
|
||||||
@dataclass
|
@dataclass
|
||||||
class BackTestAccount()
|
class BackTestAccount:
|
||||||
```
|
```
|
||||||
|
The `BackTestAccount` class provides data structure for managing account data specifically for backtesting purposes.
|
||||||
|
|
||||||
Account data for backtesting
|
#### Attributes:
|
||||||
|
| Name | Type | Description |
|
||||||
|
|-------------|---------------|-----------------------------------------------------------|
|
||||||
|
| `balance` | `float` | The account balance for the backtest |
|
||||||
|
| `equity` | `float` | The equity value of the account during the backtest |
|
||||||
|
| `currency` | `str` | The currency type used in the backtesting account |
|
||||||
|
| `leverage` | `float` | Leverage ratio applied to the backtest account |
|
||||||
|
| `spread` | `int` | Spread value applied to simulated trades |
|
||||||
|
|
||||||
<a id="backtest_account.BackTestAccount.get_dict"></a>
|
|
||||||
|
|
||||||
#### get\_dict
|
|
||||||
|
|
||||||
|
<a id="back_test_account.get_dict"></a>
|
||||||
|
### get_dict
|
||||||
```python
|
```python
|
||||||
def get_dict(exclude: set = None, include: set = None)
|
def get_dict(exclude: set = None, include: set = None) -> dict
|
||||||
```
|
```
|
||||||
|
Returns a dictionary representation of the account data. The `exclude` and `include` parameters allow filtering of data keys.
|
||||||
|
|
||||||
Returns a dictionary of the account data. Using the exclude and include arguments, you can filter the data
|
#### Arguments:
|
||||||
|
| Name | Type | Description |
|
||||||
|
|-----------|-------|----------------------------------------------------------|
|
||||||
|
| `exclude` | `set` | A set of attribute names to exclude from the dictionary. |
|
||||||
|
| `include` | `set` | A set of attribute names to include in the dictionary. |
|
||||||
|
|
||||||
**Arguments**:
|
|
||||||
|
|
||||||
- `exclude` _set_ - A set of keys to exclude
|
|
||||||
- `include` _set_ - A set of keys to include
|
|
||||||
|
|
||||||
<a id="backtest_account.BackTestAccount.asdict"></a>
|
|
||||||
|
|
||||||
#### asdict
|
|
||||||
|
|
||||||
|
<a id="back_test_account.asdict"></a>
|
||||||
|
### asdict
|
||||||
```python
|
```python
|
||||||
def asdict()
|
def asdict() -> dict
|
||||||
```
|
```
|
||||||
|
Returns a dictionary of all attributes in the account data without filtering.
|
||||||
|
|
||||||
Returns a dictionary of the account data
|
|
||||||
|
|
||||||
<a id="backtest_account.BackTestAccount.set_attrs"></a>
|
|
||||||
|
|
||||||
#### set\_attrs
|
|
||||||
|
|
||||||
|
### set_attrs
|
||||||
|
<a id="back_test_account.set_attrs"></a>
|
||||||
```python
|
```python
|
||||||
def set_attrs(**kwargs)
|
def set_attrs(**kwargs)
|
||||||
```
|
```
|
||||||
|
Sets multiple attributes at once by passing key-value pairs as keyword arguments.
|
||||||
Se the attributes of the account data to the instance
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,125 +1,104 @@
|
|||||||
# Table of Contents
|
# BackTestController
|
||||||
|
|
||||||
* [backtest\_controller](#backtest_controller)
|
## Table of Contents
|
||||||
* [BackTestController](#backtest_controller.BackTestController)
|
- [BackTestController](#backtest_controller.back_test_controller)
|
||||||
* [backtest\_engine](#backtest_controller.BackTestController.backtest_engine)
|
- [backtest_engine](#backtest_controller.backtest_engine)
|
||||||
* [add\_tasks](#backtest_controller.BackTestController.add_tasks)
|
- [add_tasks](#backtest_controller.add_tasks)
|
||||||
* [set\_parties](#backtest_controller.BackTestController.set_parties)
|
- [set_parties](#backtest_controller.set_parties)
|
||||||
* [parties](#backtest_controller.BackTestController.parties)
|
- [parties](#backtest_controller.parties)
|
||||||
* [control](#backtest_controller.BackTestController.control)
|
- [control](#backtest_controller.control)
|
||||||
* [stop\_backtesting](#backtest_controller.BackTestController.stop_backtesting)
|
- [stop_backtesting](#backtest_controller.stop_backtesting)
|
||||||
* [wait](#backtest_controller.BackTestController.wait)
|
- [wait](#backtest_controller.wait)
|
||||||
* [abort](#backtest_controller.BackTestController.abort)
|
- [abort](#backtest_controller.abort)
|
||||||
|
|
||||||
<a id="backtest_controller"></a>
|
|
||||||
|
|
||||||
# backtest\_controller
|
|
||||||
|
|
||||||
<a id="backtest_controller.BackTestController"></a>
|
|
||||||
|
|
||||||
## BackTestController Objects
|
|
||||||
|
|
||||||
|
<a id="backtest_controller.back_test_controller"></a>
|
||||||
|
### BackTestController
|
||||||
```python
|
```python
|
||||||
class BackTestController()
|
class BackTestController
|
||||||
```
|
```
|
||||||
|
|
||||||
The controller for the backtesting engine.
|
The controller for the backtesting engine.
|
||||||
It also act's as a synchronizier for running multiple strategies (tasks) using a threading.Barrier primitive.
|
It also acts as a synchronizer for running multiple strategies (tasks) using a threading.Barrier primitive.
|
||||||
It handles the updating of open positions and close them when necessary.
|
It handles the updating of open positions and close them when necessary.
|
||||||
It handles the iterator for the backtesting engine and handles it movement in time by moving it to the next time step.
|
It handles the iterator for the backtesting engine and handles it movement in time by moving it to the next time step.
|
||||||
|
|
||||||
**Attributes**:
|
#### Attributes:
|
||||||
|
| Name | Type | Description |
|
||||||
|
|-------------|----------------------|----------------------------------------------|
|
||||||
|
| `_instance` | `BackTestController` | The instance of the controller |
|
||||||
|
| `config` | `Config` | The configuration for the backtesting engine |
|
||||||
|
| `tasks` | `list[Task]` | The tasks that are being run |
|
||||||
|
| `barrier` | `Barrier` | The barrier for synchronizing the tasks |
|
||||||
|
|
||||||
- `_instance` _Self_ - The instance of the controller
|
|
||||||
- `config` _Config_ - The configuration for the backtesting engine
|
|
||||||
- `tasks` _list[Task]_ - The tasks that are being run
|
|
||||||
- `barrier` _Barrier_ - The barrier for synchronizing the tasks
|
|
||||||
|
|
||||||
<a id="backtest_controller.BackTestController.backtest_engine"></a>
|
|
||||||
|
|
||||||
#### backtest\_engine
|
|
||||||
|
|
||||||
|
<a id="backtest_controller.backtest_engine"></a>
|
||||||
|
#### backtest_engine
|
||||||
```python
|
```python
|
||||||
@property
|
@property
|
||||||
def backtest_engine()
|
def backtest_engine()
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns the backtest engine
|
Returns the backtest engine
|
||||||
|
|
||||||
<a id="backtest_controller.BackTestController.add_tasks"></a>
|
|
||||||
|
|
||||||
#### add\_tasks
|
|
||||||
|
|
||||||
|
<a id="backtest_controller.add_tasks"></a>
|
||||||
|
#### add_tasks
|
||||||
```python
|
```python
|
||||||
def add_tasks(*tasks: Task)
|
def add_tasks(*tasks: Task)
|
||||||
```
|
```
|
||||||
|
Adds a task to the tasks list
|
||||||
|
|
||||||
Adds tasks to the tasks list
|
|
||||||
|
|
||||||
<a id="backtest_controller.BackTestController.set_parties"></a>
|
|
||||||
|
|
||||||
#### set\_parties
|
|
||||||
|
|
||||||
|
<a id="backtest_controller.set_parties"></a>
|
||||||
|
#### set_parties
|
||||||
```python
|
```python
|
||||||
def set_parties(*, parties: int)
|
def set_parties(*, parties: int)
|
||||||
```
|
```
|
||||||
|
|
||||||
Sets the number of parties for the barrier. The barrier will wait for the number of parties to reach the barrier.
|
Sets the number of parties for the barrier. The barrier will wait for the number of parties to reach the barrier.
|
||||||
This has to be done here as it can be impossible to know the eventual number of parties to set the barrier to during initialization.
|
This has to be done here as it can be impossible to know the eventual number of parties to set the barrier to during initialization.
|
||||||
|
|
||||||
**Arguments**:
|
#### Parameters:
|
||||||
|
| Name | Type | Description |
|
||||||
|
|-----------|-------|---------------------------------------------|
|
||||||
|
| `parties` | `int` | The number of parties to set the barrier to |
|
||||||
|
|
||||||
- `parties` _int_ - The number of parties to set the barrier to
|
|
||||||
|
|
||||||
<a id="backtest_controller.BackTestController.parties"></a>
|
|
||||||
|
|
||||||
|
<a id="backtest_controller.parties"></a>
|
||||||
#### parties
|
#### parties
|
||||||
|
|
||||||
```python
|
```python
|
||||||
@property
|
@property
|
||||||
def parties()
|
def parties()
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns the number of parties for the barrier
|
Returns the number of parties for the barrier
|
||||||
|
|
||||||
<a id="backtest_controller.BackTestController.control"></a>
|
|
||||||
|
|
||||||
|
<a id="backtest_controller.control"></a>
|
||||||
#### control
|
#### control
|
||||||
|
|
||||||
```python
|
```python
|
||||||
async def control()
|
async def control()
|
||||||
```
|
```
|
||||||
|
|
||||||
The backtest controller. It controls the backtesting engine and the tasks that are being run.
|
The backtest controller. It controls the backtesting engine and the tasks that are being run.
|
||||||
It acts as a synchronizer for the tasks and the backtesting engine.
|
It acts as a synchronizer for the tasks and the backtesting engine.
|
||||||
|
|
||||||
<a id="backtest_controller.BackTestController.stop_backtesting"></a>
|
|
||||||
|
|
||||||
#### stop\_backtesting
|
|
||||||
|
|
||||||
|
<a id="backtest_controller.stop_backtesting"></a>
|
||||||
|
#### stop_backtesting
|
||||||
```python
|
```python
|
||||||
def stop_backtesting()
|
def stop_backtesting()
|
||||||
```
|
```
|
||||||
|
|
||||||
Stop the backtester, and shutdown the executor
|
Stop the backtester, and shutdown the executor
|
||||||
|
|
||||||
<a id="backtest_controller.BackTestController.wait"></a>
|
|
||||||
|
|
||||||
|
<a id="backtest_controller.wait"></a>
|
||||||
#### wait
|
#### wait
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def wait()
|
def wait()
|
||||||
```
|
```
|
||||||
|
|
||||||
Called by individual tasks to indicate completion of their cycle
|
Called by individual tasks to indicate completion of their cycle
|
||||||
|
|
||||||
<a id="backtest_controller.BackTestController.abort"></a>
|
|
||||||
|
|
||||||
|
<a id="backtest_controller.abort"></a>
|
||||||
#### abort
|
#### abort
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def abort()
|
def abort()
|
||||||
```
|
```
|
||||||
|
|
||||||
Aborts the barrier
|
Aborts the barrier
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,185 +1,162 @@
|
|||||||
# Table of Contents
|
# Get Data
|
||||||
|
|
||||||
* [get\_data](#get_data)
|
## Table of Contents
|
||||||
* [Cursor](#get_data.Cursor)
|
|
||||||
* [BackTestData](#get_data.BackTestData)
|
|
||||||
* [set\_attrs](#get_data.BackTestData.set_attrs)
|
|
||||||
* [fields](#get_data.BackTestData.fields)
|
|
||||||
* [GetData](#get_data.GetData)
|
|
||||||
* [\_\_init\_\_](#get_data.GetData.__init__)
|
|
||||||
* [pickle\_data](#get_data.GetData.pickle_data)
|
|
||||||
* [load\_data](#get_data.GetData.load_data)
|
|
||||||
* [save\_data](#get_data.GetData.save_data)
|
|
||||||
* [get\_data](#get_data.GetData.get_data)
|
|
||||||
|
|
||||||
<a id="get_data"></a>
|
- [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)
|
||||||
|
|
||||||
# get\_data
|
|
||||||
|
|
||||||
<a id="get_data.Cursor"></a>
|
|
||||||
|
|
||||||
## Cursor Objects
|
|
||||||
|
|
||||||
|
<a id="get_data.cursor"></a>
|
||||||
|
### Cursor
|
||||||
```python
|
```python
|
||||||
class Cursor(NamedTuple)
|
class Cursor(NamedTuple)
|
||||||
```
|
```
|
||||||
|
A cursor to iterate over the data. Marks the current position in time.
|
||||||
|
|
||||||
A cursor to iterate over the data. Marks the current position.
|
|
||||||
|
|
||||||
<a id="get_data.BackTestData"></a>
|
|
||||||
|
|
||||||
## BackTestData Objects
|
|
||||||
|
|
||||||
|
<a id="get_data.back_test_data"></a>
|
||||||
|
### BackTestData
|
||||||
```python
|
```python
|
||||||
@dataclass
|
@dataclass
|
||||||
class BackTestData()
|
class BackTestData
|
||||||
```
|
```
|
||||||
|
|
||||||
The data class to store the backtesting data.
|
The data class to store the backtesting data.
|
||||||
|
|
||||||
**Attributes**:
|
#### 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 |
|
||||||
|
|
||||||
- `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.BackTestData.set_attrs"></a>
|
|
||||||
|
|
||||||
#### set\_attrs
|
|
||||||
|
|
||||||
|
<a id="get_data.set_attrs"></a>
|
||||||
|
#### set_attrs
|
||||||
```python
|
```python
|
||||||
def set_attrs(**kwargs)
|
def set_attrs(**kwargs)
|
||||||
```
|
```
|
||||||
|
|
||||||
Set the attributes of the class on the instance.
|
Set the attributes of the class on the instance.
|
||||||
|
|
||||||
<a id="get_data.BackTestData.fields"></a>
|
|
||||||
|
|
||||||
|
<a id="get_data.fields"></a>
|
||||||
#### fields
|
#### fields
|
||||||
|
|
||||||
```python
|
```python
|
||||||
@property
|
@property
|
||||||
def fields()
|
def fields()
|
||||||
```
|
```
|
||||||
|
|
||||||
A list of the fields of the class.
|
A list of the fields of the class.
|
||||||
|
|
||||||
<a id="get_data.GetData"></a>
|
|
||||||
|
|
||||||
## GetData Objects
|
|
||||||
|
|
||||||
|
<a id="get_data.getdata"></a>
|
||||||
|
### GetData
|
||||||
```python
|
```python
|
||||||
class GetData()
|
class GetData
|
||||||
```
|
```
|
||||||
|
|
||||||
A class to get the backtesting data from the MetaTrader5 terminal.
|
A class to get the backtesting data from the MetaTrader5 terminal.
|
||||||
|
|
||||||
**Attributes**:
|
#### 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 |
|
||||||
|
|
||||||
- `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.
|
|
||||||
- `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.GetData.__init__"></a>
|
|
||||||
|
|
||||||
#### \_\_init\_\_
|
|
||||||
|
|
||||||
|
<a id="get_data.__init__"></a>
|
||||||
|
#### \__init\__
|
||||||
```python
|
```python
|
||||||
def __init__(*,
|
def __init__(*, start: datetime, end: datetime, symbols: Sequence[str],
|
||||||
start: datetime,
|
timeframes: Sequence[TimeFrame], name: str = "")
|
||||||
end: datetime,
|
|
||||||
symbols: Sequence[str],
|
|
||||||
timeframes: Sequence[TimeFrame],
|
|
||||||
name: str = "")
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Get the backtesting data from the MetaTrader5 terminal.
|
Get the backtesting data from the MetaTrader5 terminal.
|
||||||
|
|
||||||
**Arguments**:
|
#### 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 |
|
||||||
|
|
||||||
- `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.
|
|
||||||
|
|
||||||
<a id="get_data.GetData.pickle_data"></a>
|
|
||||||
|
|
||||||
#### pickle\_data
|
|
||||||
|
|
||||||
|
<a id="get_data.pickle_data"></a>
|
||||||
|
#### pickle_data
|
||||||
```python
|
```python
|
||||||
@classmethod
|
@classmethod
|
||||||
def pickle_data(cls, *, data: BackTestData, name: str | Path)
|
def pickle_data(cls, *, data: BackTestData, name: str | Path)
|
||||||
```
|
```
|
||||||
|
|
||||||
Pickle the data to a file.
|
Pickle the data to a file.
|
||||||
|
|
||||||
**Arguments**:
|
#### Parameters:
|
||||||
|
| Name | Type | Description |
|
||||||
|
|--------|-------------------------|----------------------|
|
||||||
|
| `data` | `BackTestData` | The data to pickle |
|
||||||
|
| `name` | `str \| Path` | The name of the file |
|
||||||
|
|
||||||
- `data` _BackTestData_ - The data to pickle.
|
|
||||||
- `name` _str | Path_ - The name of the file to pickle the data to.
|
|
||||||
|
|
||||||
<a id="get_data.GetData.load_data"></a>
|
|
||||||
|
|
||||||
#### load\_data
|
|
||||||
|
|
||||||
|
<a id="get_data.load_data"></a>
|
||||||
|
#### load_data
|
||||||
```python
|
```python
|
||||||
@classmethod
|
@classmethod
|
||||||
def load_data(cls, *, name: str | Path) -> BackTestData
|
def load_data(cls, *, name: str | Path) -> BackTestData
|
||||||
```
|
```
|
||||||
|
|
||||||
Load the data from a file.
|
Load the data from a file.
|
||||||
|
|
||||||
**Arguments**:
|
#### Parameters:
|
||||||
|
| Name | Type | Description |
|
||||||
|
|--------|-------------------------|----------------------|
|
||||||
|
| `name` | `str \| Path` | The name of the file |
|
||||||
|
|
||||||
- `name` _str | Path_ - The name of the file to load the data from.
|
|
||||||
|
|
||||||
<a id="get_data.GetData.save_data"></a>
|
|
||||||
|
|
||||||
#### save\_data
|
|
||||||
|
|
||||||
|
<a id="get_data.save_data"></a>
|
||||||
|
#### save_data
|
||||||
```python
|
```python
|
||||||
def save_data(*, name: str | Path = "")
|
def save_data(*, name: str | Path = "")
|
||||||
```
|
```
|
||||||
|
|
||||||
Save the data to a file.
|
Save the data to a file.
|
||||||
|
|
||||||
**Arguments**:
|
#### Parameters:
|
||||||
|
| Name | Type | Description |
|
||||||
|
|--------|-------------------------|----------------------|
|
||||||
|
| `name` | `str \| Path` | The name of the file |
|
||||||
|
|
||||||
- `name` _str | Path_ - The name of the file to save the data to. If not provided, the name of the data is used.
|
|
||||||
|
|
||||||
<a id="get_data.GetData.get_data"></a>
|
|
||||||
|
|
||||||
#### get\_data
|
|
||||||
|
|
||||||
|
<a id="get_data.get_data"></a>
|
||||||
|
#### get_data
|
||||||
```python
|
```python
|
||||||
async def get_data(workers: int = None)
|
async def get_data(workers: int = None)
|
||||||
```
|
```
|
||||||
|
|
||||||
Use the task queue to get the data from the MetaTrader5 terminal.
|
Use the task queue to get the data from the MetaTrader5 terminal.
|
||||||
|
#### Parameters:
|
||||||
**Arguments**:
|
| Name | Type | Description |
|
||||||
|
|-----------|-------|------------------------------------------------|
|
||||||
- `workers` _int_ - The number of workers to use in the task queue. If not provided, the default number of workers
|
| `workers` | `int` | The number of workers to use in the task queue |
|
||||||
is used.
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,410 +1,374 @@
|
|||||||
# Table of Contents
|
# TradesManager
|
||||||
|
|
||||||
* [trades\_manager](#trades_manager)
|
## Table of Contents
|
||||||
* [TradeManager](#trades_manager.TradeManager)
|
- [trades_manager](#trades_manager.trades_manager)
|
||||||
* [update](#trades_manager.TradeManager.update)
|
- [TradesManager](#trades_manager.trades_manager)
|
||||||
* [values](#trades_manager.TradeManager.values)
|
- [update](#trades_manager.trade_manager.update)
|
||||||
* [keys](#trades_manager.TradeManager.keys)
|
- [values](#trades_manager.trade_manager.values)
|
||||||
* [items](#trades_manager.TradeManager.items)
|
- [keys](#trades_manager.trade_manager.keys)
|
||||||
* [to\_dict](#trades_manager.TradeManager.to_dict)
|
- [items](#trades_manager.trade_manager.items)
|
||||||
* [PositionsManager](#trades_manager.PositionsManager)
|
- [to_dict](#trades_manager.trade_manager.to_dict)
|
||||||
* [\_\_init\_\_](#trades_manager.PositionsManager.__init__)
|
- [PositionsManager](#trades_manager.positions_manager)
|
||||||
* [margin](#trades_manager.PositionsManager.margin)
|
- [\__init\__](#positions_manager.__init__)
|
||||||
* [close](#trades_manager.PositionsManager.close)
|
- [margin](#positions_manager.margin)
|
||||||
* [get\_margin](#trades_manager.PositionsManager.get_margin)
|
- [close](#positions_manager.close)
|
||||||
* [delete\_margin](#trades_manager.PositionsManager.delete_margin)
|
- [get_margin](#positions_manager.get_margin)
|
||||||
* [set\_margin](#trades_manager.PositionsManager.set_margin)
|
- [delete_margin](#positions_manager.delete_margin)
|
||||||
* [positions\_get](#trades_manager.PositionsManager.positions_get)
|
- [set_margin](#positions_manager.set_margin)
|
||||||
* [positions\_total](#trades_manager.PositionsManager.positions_total)
|
- [positions_get](#positions_manager.positions_get)
|
||||||
* [open\_positions](#trades_manager.PositionsManager.open_positions)
|
- [positions_total](#positions_manager.positions_total)
|
||||||
* [OrdersManager](#trades_manager.OrdersManager)
|
- [open_positions](#positions_manager.open_positions)
|
||||||
* [get\_orders\_range](#trades_manager.OrdersManager.get_orders_range)
|
- [OrdersManager](#trades_manager.orders_manager)
|
||||||
* [history\_orders\_get](#trades_manager.OrdersManager.history_orders_get)
|
- [get_orders_range](#orders_manager.get_orders_range)
|
||||||
* [history\_orders\_total](#trades_manager.OrdersManager.history_orders_total)
|
- [history_orders_get](#orders_manager.history_orders_get)
|
||||||
* [DealsManager](#trades_manager.DealsManager)
|
- [history_orders_total](#orders_manager.history_orders_total)
|
||||||
* [get\_deals\_range](#trades_manager.DealsManager.get_deals_range)
|
- [DealsManager](#trades_manager.deals_manager)
|
||||||
* [history\_deals\_get](#trades_manager.DealsManager.history_deals_get)
|
- [get_deals_range](#deals_manager.get_deals_range)
|
||||||
* [history\_deals\_total](#trades_manager.DealsManager.history_deals_total)
|
- [history_deals_get](#deals_manager.history_deals_get)
|
||||||
|
- [history_deals_total](#deals_manager.history_deals_total)
|
||||||
|
|
||||||
<a id="trades_manager"></a>
|
|
||||||
|
|
||||||
# trades\_manager
|
|
||||||
|
|
||||||
<a id="trades_manager.TradeManager"></a>
|
|
||||||
|
|
||||||
## TradeManager Objects
|
|
||||||
|
|
||||||
|
<a id="trades_manager.trades_manager"></a>
|
||||||
|
### TradesManager
|
||||||
```python
|
```python
|
||||||
class TradeManager(Generic[TradeData])
|
class TradeManager(Generic[TradeData])
|
||||||
```
|
```
|
||||||
|
|
||||||
A generic class to manage trades data during a backtest. It is the parent class of the
|
A generic class to manage trades data during a backtest. It is the parent class of the
|
||||||
PositionsManager, OrdersManager, and DealsManager. It implements some dict-like methods to manage the data.
|
PositionsManager, OrdersManager, and DealsManager. It implements some dict-like methods to manage the data.
|
||||||
It has a private attribute _data to store the data. It exposes the data through the values, keys, and items methods.
|
It has a private attribute _data to store the data. It exposes the data through the values, keys, and items methods.
|
||||||
It also has a to_dict method to convert the data to a dictionary.
|
It also has a `to_dict` method to convert the data to a dictionary.
|
||||||
|
|
||||||
**Attributes**:
|
#### Parameters:
|
||||||
|
| Name | Type | Description |
|
||||||
- `_data` _dict[int, TradeData]_ - The data to store the trades.
|
|---------|------------------------|------------------------------|
|
||||||
|
| `_data` | `dict[int, TradeData]` | The data to store the trades |
|
||||||
|
|
||||||
|
|
||||||
**Examples**:
|
#### Examples:
|
||||||
|
```python
|
||||||
>>> manager = TradeManager()
|
>>> manager = TradeManager()
|
||||||
>>> manager[123456] = TradePosition(ticket=123456, symbol="EURUSD", volume=0.1)
|
>>> manager[123456] = TradePosition(ticket=123456, symbol="EURUSD", volume=0.1)
|
||||||
>>> manager.update(ticket=123456, symbol="EURUSD", volume=0.1)
|
>>> manager.update(ticket=123456, symbol="EURUSD", volume=0.1)
|
||||||
>>> manager[123456]
|
>>> manager[123456]
|
||||||
TradePosition(ticket=123456, symbol='EURUSD', volume=0.1)
|
TradePosition(ticket=123456, symbol='EURUSD', volume=0.1)
|
||||||
>>> manager.values()
|
>>> manager.values()
|
||||||
(TradePosition(ticket=123456, symbol='EURUSD', volume=0.1),)
|
(TradePosition(ticket=123456, symbol='EURUSD', volume=0.1),)
|
||||||
>>> manager.keys()
|
>>> manager.keys()
|
||||||
(123456,)
|
(123456,)
|
||||||
>>> manager.items()
|
>>> manager.items()
|
||||||
((123456, TradePosition(ticket=123456, symbol='EURUSD', volume=0.1)),)
|
((123456, TradePosition(ticket=123456, symbol='EURUSD', volume=0.1)),)
|
||||||
>>> manager.to_dict()
|
>>> manager.to_dict()
|
||||||
- `{123456` - {'ticket': 123456, 'symbol': 'EURUSD', 'volume': 0.1}}
|
{'123456' - {'ticket': 123456, 'symbol': 'EURUSD', 'volume': 0.1}}
|
||||||
>>> pos = manager.get(123456)
|
>>> pos = manager.get(123456)
|
||||||
>>> pos
|
>>> pos
|
||||||
TradePosition(ticket=123456, symbol='EURUSD', volume=0.1)
|
TradePosition(ticket=123456, symbol='EURUSD', volume=0.1)
|
||||||
>>> pos in manager
|
>>> pos in manager
|
||||||
True
|
True
|
||||||
>>> len(manager)
|
>>> len(manager)
|
||||||
1
|
1
|
||||||
>>> pos in manager
|
>>> pos in manager
|
||||||
False
|
False
|
||||||
|
```
|
||||||
<a id="trades_manager.TradeManager.update"></a>
|
|
||||||
|
|
||||||
|
<a id="trades_manager.update"></a>
|
||||||
#### update
|
#### update
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def update(*, ticket: int, **kwargs)
|
def update(*, ticket: int, **kwargs)
|
||||||
```
|
```
|
||||||
|
|
||||||
Update the data of a trade. Given the ticket of the trade and the new data to update.
|
Update the data of a trade. Given the ticket of the trade and the new data to update.
|
||||||
|
|
||||||
**Arguments**:
|
#### Parameters:
|
||||||
|
| Name | Type | Description |
|
||||||
|
|------------|-------|------------------------------------|
|
||||||
|
| `ticket` | `int` | The ticket of the trade to update. |
|
||||||
|
| `**kwargs` | | The new data to update. |
|
||||||
|
|
||||||
- `ticket` _int_ - The ticket of the trade to update.
|
|
||||||
- `**kwargs` - The new data to update.
|
|
||||||
|
|
||||||
<a id="trades_manager.TradeManager.values"></a>
|
|
||||||
|
|
||||||
#### values
|
|
||||||
|
|
||||||
|
<a id="trades_manager.values"></a>
|
||||||
|
### values
|
||||||
```python
|
```python
|
||||||
def values() -> tuple[TradeData, ...]
|
def values() -> tuple[TradeData, ...]
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns the values of the data.
|
Returns the values of the data.
|
||||||
|
|
||||||
<a id="trades_manager.TradeManager.keys"></a>
|
|
||||||
|
|
||||||
#### keys
|
|
||||||
|
|
||||||
|
<a id="trades_manager.keys"></a>
|
||||||
|
### keys
|
||||||
```python
|
```python
|
||||||
def keys() -> tuple[int, ...]
|
def keys() -> tuple[int, ...]
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns the keys of the data.
|
Returns the keys of the data.
|
||||||
|
|
||||||
<a id="trades_manager.TradeManager.items"></a>
|
|
||||||
|
|
||||||
#### items
|
|
||||||
|
|
||||||
|
<a id="trades_manager.items"></a>
|
||||||
|
### items
|
||||||
```python
|
```python
|
||||||
def items() -> tuple[tuple[int, TradeData], ...]
|
def items() -> tuple[tuple[int, TradeData], ...]
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns the items of the data.
|
Returns the items of the data.
|
||||||
|
|
||||||
<a id="trades_manager.TradeManager.to_dict"></a>
|
|
||||||
|
|
||||||
#### to\_dict
|
|
||||||
|
|
||||||
|
<a id="trades_manager.to_dict"></a>
|
||||||
|
### to_dict
|
||||||
```python
|
```python
|
||||||
def to_dict()
|
def to_dict()
|
||||||
```
|
```
|
||||||
|
|
||||||
Convert the data to a dictionary.
|
Convert the data to a dictionary.
|
||||||
|
|
||||||
<a id="trades_manager.PositionsManager"></a>
|
|
||||||
|
|
||||||
## PositionsManager Objects
|
|
||||||
|
|
||||||
|
<a id="trades_manager.positions_manager"></a>
|
||||||
```python
|
```python
|
||||||
class PositionsManager(TradeManager)
|
class PositionsManager(TradeManager)
|
||||||
```
|
```
|
||||||
|
A class to manage the open positions during a backtest. It is a subclass of It has an additional
|
||||||
A class to manage the open positions during a backtest. It is a subclass of TradeManager. It has an additional
|
|
||||||
attribute _open_positions to store the open positions. It also has a margins attribute to store the margins of the
|
attribute _open_positions to store the open positions. It also has a margins attribute to store the margins of the
|
||||||
open positions. It overrides some methods of the TradeManager class to manage the open positions.
|
open positions. It overrides some methods of the TradeManager class to manage the open positions.
|
||||||
|
|
||||||
**Attributes**:
|
#### Attributes:
|
||||||
|
| Name | Type | Description |
|
||||||
|
|------------------|--------------------|--------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `data` | `dict` | The data to store the trades. This used for continuation of the backtesting, if it was stopped with some open positions. |
|
||||||
|
| `open_positions` | `set[int]` | The open positions. |
|
||||||
|
| `margins` | `dict[int, float]` | The margins of the open positions. |
|
||||||
|
|
||||||
- `_open_positions` _set[int]_ - The open positions.
|
|
||||||
- `margins` _dict[int, float]_ - The margins of the open positions.
|
|
||||||
|
|
||||||
<a id="trades_manager.PositionsManager.__init__"></a>
|
|
||||||
|
|
||||||
#### \_\_init\_\_
|
|
||||||
|
|
||||||
|
<a id="positions_manager.__init__"></a>
|
||||||
|
#### \__init\__
|
||||||
```python
|
```python
|
||||||
def __init__(*,
|
def __init__(*, data: dict = None, open_positions: set[int] = None, margins: dict = None)
|
||||||
data: dict = None,
|
|
||||||
open_positions: set[int] = None,
|
|
||||||
margins: dict = None)
|
|
||||||
```
|
```
|
||||||
|
Positions manager manages the open positions during a backtest. It is a subclass of It has an
|
||||||
Positions manager manages the open positions during a backtest. It is a subclass of TradeManager. It has an
|
|
||||||
additional attribute _open_positions to store the open positions. It also has a margins attribute to store the
|
additional attribute _open_positions to store the open positions. It also has a margins attribute to store the
|
||||||
margins of the open positions. It overrides some methods of the TradeManager class to manage the open positions.
|
margins of the open positions. It overrides some methods of the TradeManager class to manage the open positions.
|
||||||
|
|
||||||
**Arguments**:
|
#### Parameters:
|
||||||
|
| Name | Type | Description |
|
||||||
|
|------------------|--------------------|--------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `data` | `dict` | The data to store the trades. This used for continuation of the backtesting, if it was stopped with some open positions. |
|
||||||
|
| `open_positions` | `set[int]` | The open positions. |
|
||||||
|
| `margins` | `dict[int, float]` | The margins of the open positions. |
|
||||||
|
|
||||||
- `data` _dict, optional_ - The data to store the trades. This used for continuation of the backtesting, if it
|
|
||||||
was stopped with some open positions.
|
|
||||||
|
|
||||||
- `open_positions` _set, optional_ - The open positions. Defaults to None.
|
|
||||||
|
|
||||||
- `margins` _dict, optional_ - The margins of the open positions. Defaults to None.
|
|
||||||
|
|
||||||
<a id="trades_manager.PositionsManager.margin"></a>
|
|
||||||
|
|
||||||
#### margin
|
|
||||||
|
|
||||||
|
<a id="positions_manager.margin"></a>
|
||||||
|
### margin
|
||||||
```python
|
```python
|
||||||
@property
|
@property
|
||||||
def margin()
|
def margin()
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns the total margin of all open positions
|
Returns the total margin of all open positions
|
||||||
|
|
||||||
<a id="trades_manager.PositionsManager.close"></a>
|
|
||||||
|
|
||||||
#### close
|
|
||||||
|
|
||||||
|
<a id="positions_manager.close"></a>
|
||||||
|
### close
|
||||||
```python
|
```python
|
||||||
def close(*, ticket: int) -> bool
|
def close(*, ticket: int) -> bool
|
||||||
```
|
```
|
||||||
|
|
||||||
Close a position. Given the ticket of the position to close.
|
Close a position. Given the ticket of the position to close.
|
||||||
|
|
||||||
**Arguments**:
|
#### Parameters:
|
||||||
|
| Name | Type | Description |
|
||||||
|
|----------|-------|--------------------------------------|
|
||||||
|
| `ticket` | `int` | The ticket of the position to close. |
|
||||||
|
|
||||||
- `ticket` _int_ - The ticket of the position to close.
|
|
||||||
|
|
||||||
<a id="trades_manager.PositionsManager.get_margin"></a>
|
|
||||||
|
|
||||||
#### get\_margin
|
|
||||||
|
|
||||||
|
<a id="positions_manager.get_margin"></a>
|
||||||
|
#### get_margin
|
||||||
```python
|
```python
|
||||||
def get_margin(*, ticket: int) -> float
|
def get_margin(*, ticket: int) -> float
|
||||||
```
|
```
|
||||||
|
|
||||||
Get the margin of a position. Given the ticket of the position.
|
Get the margin of a position. Given the ticket of the position.
|
||||||
|
|
||||||
**Arguments**:
|
#### Parameters:
|
||||||
|
| Name | Type | Description |
|
||||||
- `ticket` _int_ - The ticket of the position.
|
|----------|-------|-----------------------------|
|
||||||
|
| `ticket` | `int` | The ticket of the position. |
|
||||||
|
|
||||||
|
|
||||||
**Returns**:
|
#### Returns:
|
||||||
|
| Type | Description |
|
||||||
|
|---------|-----------------------------|
|
||||||
|
| `float` | The margin of the position. |
|
||||||
|
|
||||||
- `float` - The margin of the position.
|
|
||||||
|
|
||||||
<a id="trades_manager.PositionsManager.delete_margin"></a>
|
|
||||||
|
|
||||||
#### delete\_margin
|
|
||||||
|
|
||||||
|
<a id="positions_manager.delete_margin"></a>
|
||||||
|
### delete_margin
|
||||||
```python
|
```python
|
||||||
def delete_margin(*, ticket: int)
|
def delete_margin(*, ticket: int)
|
||||||
```
|
```
|
||||||
|
|
||||||
Delete the margin of a position. Given the ticket of the position.
|
Delete the margin of a position. Given the ticket of the position.
|
||||||
|
|
||||||
**Arguments**:
|
#### Parameters:
|
||||||
|
| Name | Type | Description |
|
||||||
|
|----------|-------|-----------------------------|
|
||||||
|
| `ticket` | `int` | The ticket of the position. |
|
||||||
|
|
||||||
- `ticket` _int_ - The ticket of the position.
|
|
||||||
|
|
||||||
<a id="trades_manager.PositionsManager.set_margin"></a>
|
|
||||||
|
|
||||||
#### set\_margin
|
|
||||||
|
|
||||||
|
<a id="positions_manager.set_margin"></a>
|
||||||
|
### set_margin
|
||||||
```python
|
```python
|
||||||
def set_margin(*, ticket: int, margin: float)
|
def set_margin(*, ticket: int, margin: float)
|
||||||
```
|
```
|
||||||
|
|
||||||
Set the margin of a position. Given the ticket of the position and the margin.
|
Set the margin of a position. Given the ticket of the position and the margin.
|
||||||
|
|
||||||
**Arguments**:
|
#### Parameters:
|
||||||
|
| Name | Type | Description |
|
||||||
|
|----------|---------|-----------------------------|
|
||||||
|
| `ticket` | `int` | The ticket of the position. |
|
||||||
|
| `margin` | `float` | The margin of the position. |
|
||||||
|
|
||||||
- `ticket` _int_ - The ticket of the position.
|
|
||||||
- `margin` _float_ - The margin of the position
|
|
||||||
|
|
||||||
<a id="trades_manager.PositionsManager.positions_get"></a>
|
|
||||||
|
|
||||||
#### positions\_get
|
|
||||||
|
|
||||||
|
<a id="positions_manager.positions_get"></a>
|
||||||
|
### positions_get
|
||||||
```python
|
```python
|
||||||
def positions_get(*,
|
def positions_get(*, ticket: int = None, symbol: str = None, group: None = None) -> tuple[TradePosition, ...]
|
||||||
ticket: int = None,
|
|
||||||
symbol: str = None,
|
|
||||||
group: None = None) -> tuple[TradePosition, ...]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Get positions. Given the ticket, symbol, or group of the positions.
|
Get positions. Given the ticket, symbol, or group of the positions.
|
||||||
|
|
||||||
**Arguments**:
|
#### Parameters:
|
||||||
|
| Name | Type | Description |
|
||||||
|
|----------|-------|-----------------------------|
|
||||||
|
| `ticket` | `int` | The ticket of the position. |
|
||||||
|
| `symbol` | `str` | The symbol of the position. |
|
||||||
|
| `group` | `str` | The group of the position. |
|
||||||
|
|
||||||
- `ticket` _int_ - The ticket of the position.
|
#### Returns:
|
||||||
- `symbol` _str_ - The symbol of the position.
|
| Type | Description |
|
||||||
- `group` _str_ - The group
|
|------------------------|-----------------------------|
|
||||||
|
| `tuple[TradePosition]` | The positions. |
|
||||||
|
|
||||||
|
#### Returns:
|
||||||
|
| Type | Description |
|
||||||
|
|-----------------------------|-----------------------------|
|
||||||
|
| `tuple[TradePosition, ...]` | The positions. |
|
||||||
|
|
||||||
|
|
||||||
**Returns**:
|
<a id="positions_manager.positions_total"></a>
|
||||||
|
### positions_total
|
||||||
tuple[TradePosition, ...]: The positions
|
|
||||||
|
|
||||||
<a id="trades_manager.PositionsManager.positions_total"></a>
|
|
||||||
|
|
||||||
#### positions\_total
|
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def positions_total() -> int
|
def positions_total() -> int
|
||||||
```
|
```
|
||||||
|
|
||||||
Get the total number of open positions.
|
Get the total number of open positions.
|
||||||
|
|
||||||
**Returns**:
|
#### Returns:
|
||||||
|
| Type | Description |
|
||||||
|
|-------|-------------------------------------|
|
||||||
|
| `int` | The total number of open positions. |
|
||||||
|
|
||||||
- `int` - The total number of open positions.
|
|
||||||
|
|
||||||
<a id="trades_manager.PositionsManager.open_positions"></a>
|
|
||||||
|
|
||||||
#### open\_positions
|
|
||||||
|
|
||||||
|
<a id="positions_manager.open_positions"></a>
|
||||||
|
#### open_positions
|
||||||
```python
|
```python
|
||||||
@property
|
@property
|
||||||
def open_positions() -> tuple[TradePosition, ...]
|
def open_positions() -> tuple[TradePosition, ...]
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns the open positions.
|
Returns the open positions.
|
||||||
|
|
||||||
**Arguments**:
|
#### Parameters:
|
||||||
|
| Name | Type | Description |
|
||||||
|
|----------|-------|-----------------------------|
|
||||||
|
| `ticket` | `int` | The ticket of the position. |
|
||||||
|
|
||||||
tuple[TradePosition, ...]: The open positions.
|
|
||||||
|
|
||||||
<a id="trades_manager.OrdersManager"></a>
|
|
||||||
|
|
||||||
## OrdersManager Objects
|
|
||||||
|
|
||||||
|
<a id="trades_manager.orders_manager"></a>
|
||||||
|
### OrdersManager
|
||||||
```python
|
```python
|
||||||
class OrdersManager(TradeManager)
|
class OrdersManager(TradeManager)
|
||||||
```
|
```
|
||||||
|
Managers orders data during a backtest. It is a subclass of It manages access to the historical
|
||||||
Managers orders data during a backtest. It is a subclass of TradeManager. It manages access to the historical
|
|
||||||
orders data
|
orders data
|
||||||
|
|
||||||
<a id="trades_manager.OrdersManager.get_orders_range"></a>
|
|
||||||
|
|
||||||
#### get\_orders\_range
|
|
||||||
|
|
||||||
|
<a id="orders_manager.get_orders_range"></a>
|
||||||
|
#### get_orders_range
|
||||||
```python
|
```python
|
||||||
def get_orders_range(*, date_from: float,
|
def get_orders_range(*, date_from: float, date_to: float) -> tuple[TradeData, ...]
|
||||||
date_to: float) -> tuple[TradeData, ...]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Get orders within a date range. Given the start and end date of the range.
|
Get orders within a date range. Given the start and end date of the range.
|
||||||
|
|
||||||
**Arguments**:
|
#### Parameters:
|
||||||
|
| Name | Type | Description |
|
||||||
|
|-------------|---------|------------------------------|
|
||||||
|
| `date_from` | `float` | The start date of the range. |
|
||||||
|
| `date_to` | `float` | The end date of the range. |
|
||||||
|
|
||||||
- `date_from` _float_ - The start date of the range.
|
#### Returns:
|
||||||
- `date_to` _float_ - The end date of the range.
|
| Type | Description |
|
||||||
|
|--------------------|-----------------------------------|
|
||||||
|
| `tuple[TradeData]` | The orders within the date range. |
|
||||||
|
|
||||||
|
|
||||||
**Returns**:
|
#### Returns:
|
||||||
|
| Type | Description |
|
||||||
|
|--------------------|-----------------------------------|
|
||||||
|
| `tuple[TradeData]` | The orders within the date range. |
|
||||||
|
|
||||||
tuple[TradeData, ...]: The orders within the date range.
|
|
||||||
|
|
||||||
<a id="trades_manager.OrdersManager.history_orders_get"></a>
|
|
||||||
|
|
||||||
#### history\_orders\_get
|
|
||||||
|
|
||||||
|
<a id="orders_manager.history_orders_get"></a>
|
||||||
|
#### history_orders_get
|
||||||
```python
|
```python
|
||||||
def history_orders_get(*,
|
def history_orders_get(*, date_from: float | datetime = None, date_to: float | datetime = None,
|
||||||
date_from: float | datetime = None,
|
group: str = "", ticket: int = None, position: int = None) -> tuple[TradeOrder, ...]
|
||||||
date_to: float | datetime = None,
|
|
||||||
group: str = "",
|
|
||||||
ticket: int = None,
|
|
||||||
position: int = None) -> tuple[TradeOrder, ...]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Get historical orders. Given the start and end date of the range, the group, ticket, or position of the
|
Get historical orders. Given the start and end date of the range, the group, ticket, or position of the
|
||||||
orders.
|
orders.
|
||||||
|
|
||||||
**Arguments**:
|
#### Parameters:
|
||||||
|
| Name | Type | Description |
|
||||||
|
|-------------|---------|------------------------------|
|
||||||
|
| `date_from` | `float` | The start date of the range. |
|
||||||
|
| `date_to` | `float` | The end date of the range. |
|
||||||
|
| `group` | `str` | The group of the orders. |
|
||||||
|
| `ticket` | `int` | The ticket of the order. |
|
||||||
|
| `position` | `int` | The position of the order. |
|
||||||
|
|
||||||
- `date_from` _float, datetime_ - The start date of the range.
|
#### Returns:
|
||||||
- `date_to` _float, datetime_ - The end date of the range.
|
| Type | Description |
|
||||||
- `group` _str_ - The group of the orders.
|
|---------------------|------------------------|
|
||||||
- `ticket` _int_ - The ticket of the order.
|
| `tuple[TradeOrder]` | The historical orders. |
|
||||||
- `position` _int_ - The position of the order.
|
|
||||||
|
|
||||||
|
|
||||||
**Returns**:
|
<a id="orders_manager.history_orders_total"></a>
|
||||||
|
### history_orders_total
|
||||||
tuple[TradeOrder, ...]: The historical orders.
|
|
||||||
|
|
||||||
<a id="trades_manager.OrdersManager.history_orders_total"></a>
|
|
||||||
|
|
||||||
#### history\_orders\_total
|
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def history_orders_total(*, date_from: datetime | float,
|
def history_orders_total(*, date_from: datetime | float,
|
||||||
date_to: datetime | float) -> int
|
date_to: datetime | float) -> int
|
||||||
```
|
```
|
||||||
|
|
||||||
Get the total number of historical orders. Given the start and end date of the range.
|
Get the total number of historical orders. Given the start and end date of the range.
|
||||||
|
|
||||||
**Arguments**:
|
#### Parameters:
|
||||||
|
| Name | Type | Description |
|
||||||
|
|-------------|---------|------------------------------|
|
||||||
|
| `date_from` | `float` | The start date of the range. |
|
||||||
|
| `date_to` | `float` | The end date of the range. |
|
||||||
|
|
||||||
- `date_from` _datetime, float_ - The start date of the range.
|
|
||||||
- `date_to` _datetime, float_ - The end date of the range.
|
|
||||||
|
|
||||||
<a id="trades_manager.DealsManager"></a>
|
|
||||||
|
|
||||||
## DealsManager Objects
|
|
||||||
|
|
||||||
|
<a id="trades_manager.deals_manager"></a>
|
||||||
|
### DealsManager
|
||||||
```python
|
```python
|
||||||
class DealsManager(TradeManager)
|
class DealsManager(TradeManager)
|
||||||
```
|
```
|
||||||
|
|
||||||
<a id="trades_manager.DealsManager.get_deals_range"></a>
|
<a id="deals_manager.get_deals_range"></a>
|
||||||
|
#### get_deals_range
|
||||||
#### get\_deals\_range
|
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def get_deals_range(*, date_from: float,
|
def get_deals_range(*, date_from: float, date_to: float) -> tuple[TradeData, ...]
|
||||||
date_to: float) -> tuple[TradeData, ...]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Get deals within a date range. Given the start and end date of the range.
|
Get deals within a date range. Given the start and end date of the range.
|
||||||
|
|
||||||
**Arguments**:
|
#### Parameters:
|
||||||
|
| Name | Type | Description |
|
||||||
|
|-------------|---------|------------------------------|
|
||||||
|
| `date_from` | `float` | The start date of the range. |
|
||||||
|
| `date_to` | `float` | The end date of the range. |
|
||||||
|
|
||||||
- `date_from` _float_ - The start date of the range.
|
#### Returns:
|
||||||
- `date_to` _float_ - The end date of the range.
|
| Type | Description |
|
||||||
|
|--------------------|-----------------------------------|
|
||||||
|
| `tuple[TradeData]` | The deals within the date range. |
|
||||||
|
|
||||||
|
|
||||||
**Returns**:
|
<a id="deals_manager.history_deals_get"></a>
|
||||||
|
### history_deals_get
|
||||||
tuple[TradeData, ...]: The deals within the date range.
|
|
||||||
|
|
||||||
<a id="trades_manager.DealsManager.history_deals_get"></a>
|
|
||||||
|
|
||||||
#### history\_deals\_get
|
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def history_deals_get(*,
|
def history_deals_get(*,
|
||||||
date_from: float | datetime = None,
|
date_from: float | datetime = None,
|
||||||
@@ -413,35 +377,33 @@ def history_deals_get(*,
|
|||||||
ticket: int = None,
|
ticket: int = None,
|
||||||
position: int = None) -> tuple[TradeDeal, ...]
|
position: int = None) -> tuple[TradeDeal, ...]
|
||||||
```
|
```
|
||||||
|
|
||||||
History deals get. Given the start and end date of the range, the group, ticket, or position of the deals.
|
History deals get. Given the start and end date of the range, the group, ticket, or position of the deals.
|
||||||
|
|
||||||
**Arguments**:
|
#### Parameters:
|
||||||
|
| Name | Type | Description |
|
||||||
|
|-------------|---------|------------------------------|
|
||||||
|
| `date_from` | `float` | The start date of the range. |
|
||||||
|
| `date_to` | `float` | The end date of the range. |
|
||||||
|
| `group` | `str` | The group of the deals. |
|
||||||
|
| `ticket` | `int` | The ticket of the deal. |
|
||||||
|
| `position` | `int` | The position of the deal. |
|
||||||
|
|
||||||
- `date_from` _float, datetime_ - The start date of the range.
|
|
||||||
- `date_to` _float, datetime_ - The end date of the range.
|
|
||||||
- `group` _str_ - The group of the deals.
|
|
||||||
- `ticket` _int_ - The ticket of the deal.
|
|
||||||
- `position` _int_ - The position of the deal.
|
|
||||||
|
|
||||||
<a id="trades_manager.DealsManager.history_deals_total"></a>
|
|
||||||
|
|
||||||
#### history\_deals\_total
|
|
||||||
|
|
||||||
|
<a id="deals_manager.history_deals_total"></a>
|
||||||
|
#### history_deals_total
|
||||||
```python
|
```python
|
||||||
def history_deals_total(*, date_from: datetime | float,
|
def history_deals_total(*, date_from: datetime | float,
|
||||||
date_to: datetime | float) -> int
|
date_to: datetime | float) -> int
|
||||||
```
|
```
|
||||||
|
|
||||||
Get the total number of historical deals. Given the start and end date of the range
|
Get the total number of historical deals. Given the start and end date of the range
|
||||||
|
|
||||||
**Arguments**:
|
#### Parameters:
|
||||||
|
| Name | Type | Description |
|
||||||
- `date_from` _datetime, float_ - The start date of the range.
|
|-------------|---------|------------------------------|
|
||||||
- `date_to` _datetime, float_ - The end date of the range.
|
| `date_from` | `float` | The start date of the range. |
|
||||||
|
| `date_to` | `float` | The end date of the range. |
|
||||||
|
|
||||||
**Returns**:
|
|
||||||
|
|
||||||
- `int` - The total number of historical deals.
|
|
||||||
|
|
||||||
|
#### Returns:
|
||||||
|
| Type | Description |
|
||||||
|
|-------|---------------------------------------|
|
||||||
|
| `int` | The total number of historical deals. |
|
||||||
|
|||||||
+91
-52
@@ -1,72 +1,111 @@
|
|||||||
# Config
|
# Config
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
- [Config](#config.Config)
|
- [Config](#config.config)
|
||||||
- [account\_info](#config.account_info)
|
- [account_info](#config.account_info)
|
||||||
- [load\_config](#config.load_config)
|
- [backtest_engine](#config.backtest_engine)
|
||||||
- [create\_records\_dir](#config.create_records_dir)
|
- [set_attributes](#config.set_attributes)
|
||||||
|
- [load_config](#config.load_config)
|
||||||
|
|
||||||
|
|
||||||
<a id="config.Config"></a>
|
<a id="config.config"></a>
|
||||||
```python
|
```python
|
||||||
class Config
|
class Config
|
||||||
```
|
```
|
||||||
A class for handling configuration settings for the aiomql package. A single instance of this class is created and used
|
The global config object. It is a singleton class for handling configuration settings for the aiomql package.
|
||||||
per bot instance.
|
A single instance of this class is created and used per bot instance.
|
||||||
### Class Attributes
|
|
||||||
| Name | Type | Description | Default |
|
#### Attributes:
|
||||||
|------------------|--------------|-----------------------------------------------------|-----------------------------------------------------|
|
| Name | Type | Description |
|
||||||
| `record\_trades` | `bool` | Whether to keep record of trades or not. | True |
|
|--------------------------------|-------------------------------|-------------------------------------------------------------------------|
|
||||||
| `filename` | `str` | Name of the config file | aiomql.json |
|
| `login` | `int` | The account login number |
|
||||||
| `records\_dir` | `str\| Path` | Path to the directory where trade records are saved | Should be relative to the project root |
|
| `trade_record_mode` | `Literal["csv", "json"]` | The mode for recording trades |
|
||||||
| `login` | `str` | Trading account number | |
|
| `password` | `str` | The account password |
|
||||||
| `password` | `str` | Trading account password | |
|
| `server` | `str` | The account server |
|
||||||
| `server` | `str` | Broker server | |
|
| `path` | `str \| Path` | The path to the terminal |
|
||||||
| `path` | `str\|Path` | Path to terminal file | Absolute |
|
| `timeout` | `int` | The timeout argument for the terminal |
|
||||||
| `timeout` | `int` | Timeout for terminal connection | |
|
| `filename` | `str` | The filename of the config file |
|
||||||
| `config_dir` | `str` | Directory where the config file is located | Optional. Should be relative to the root directory |
|
| `state` | `dict` | The state of the configuration |
|
||||||
| `state` | `dict` | A global state object | |
|
| `root` | `Path` | The root directory of the project |
|
||||||
| `task_queue` | `Queue` | A global queue for handling tasks | |
|
| `record_trades` | `bool` | To record trades or not. Default is True |
|
||||||
| `bot` | `Bot` | The bot instance | Added to the config object after bot initialization |
|
| `records_dir` | `Path` | The directory to store trade records, relative to the root directory |
|
||||||
| `root_dir` | `str` | Root directory of the project | |
|
| `records_dir_name` | `str` | The name of the trade records directory |
|
||||||
|
| `backtest_dir` | `Path` | The directory to store backtest results, relative to the root directory |
|
||||||
|
| `backtest_dir_name` | `str` | The name of the backtest directory |
|
||||||
|
| `task_queue` | `TaskQueue` | The TaskQueue object for handling background tasks |
|
||||||
|
| `_backtest_engine` | `BackTestEngine` | The backtest engine object |
|
||||||
|
| `bot` | `Bot` | The bot object |
|
||||||
|
| `_instance` | `Self` | The instance of the Config class |
|
||||||
|
| `mode` | `Literal["backtest", "live"]` | The trading mode, either backtest or live, default is live |
|
||||||
|
| `use_terminal_for_backtesting` | `bool` | Use the terminal for backtesting, default is True |
|
||||||
|
| `shutdown` | `bool` | A signal to shut down the terminal, default is False |
|
||||||
|
| `force_shutdown` | `bool` | A signal to force shut down the terminal, default is False |
|
||||||
|
|
||||||
|
#### Notes:
|
||||||
|
By default, the config class looks for a file named aiomql.json. This can be changed by setting the filename
|
||||||
|
attribute to the desired file name. The root directory of the project can be set by passing the root argument
|
||||||
|
to the load_config method or during object instantiation. If not provided it is assumed to be the current working
|
||||||
|
directory. All directories and files are assumed to be relative to the root directory except when an absolute path
|
||||||
|
is provided, this includes the config file, the records_dir and the backtest_dir attributes.
|
||||||
|
The root directory is used to locate the config file and to set the records_dir and backtest_dir attributes.
|
||||||
|
|
||||||
#### Notes
|
|
||||||
By default, the config class looks for a file named aiomql.json.
|
|
||||||
You can change this by passing the filename keyword argument to the constructor.
|
|
||||||
By passing reload=True to the load_config method, you can reload and search again for the config file.
|
|
||||||
|
|
||||||
<a id="config.account_info"></a>
|
<a id="config.account_info"></a>
|
||||||
### account\_info
|
### account_info
|
||||||
```python
|
```python
|
||||||
def account_info() -> dict['login', 'password', 'server']
|
def account_info() -> dict['login', 'password', 'server']
|
||||||
```
|
```
|
||||||
Returns Account login details as found in the config object if available
|
Returns Account login details as found in the config object if available
|
||||||
#### Returns
|
|
||||||
| Type | Description |
|
#### Returns:
|
||||||
|--------|-------------------------------------------------------|
|
| Type | Description |
|
||||||
| `dict` | A dictionary with login, password, and server details |
|
|---------------------------------------|-------------------------------------------------------|
|
||||||
|
| `dict['login', 'password', 'server']` | A dictionary with login, password, and server details |
|
||||||
|
|
||||||
|
<a id="config.backtest_engine"></a>
|
||||||
|
### backtest_engine
|
||||||
|
```python
|
||||||
|
@property
|
||||||
|
def backtest_engine(self)
|
||||||
|
```
|
||||||
|
Returns the backtest engine object.
|
||||||
|
|
||||||
|
#### Returns:
|
||||||
|
| Type | Description |
|
||||||
|
|-----------------|------------------------|
|
||||||
|
| `BackTestEngine` | The backtest engine object |
|
||||||
|
|
||||||
|
|
||||||
|
<a id="config.backtest_engine.setter"></a>
|
||||||
|
```python
|
||||||
|
@backtest_engine.setter
|
||||||
|
def backtest_engine(self, value: BackTestEngine)
|
||||||
|
```
|
||||||
|
Sets the backtest engine object.
|
||||||
|
|
||||||
|
#### Parameters:
|
||||||
|
| Name | Type | Description |
|
||||||
|
|---------|------------------|----------------------------|
|
||||||
|
| `value` | `BackTestEngine` | The backtest engine object |
|
||||||
|
|
||||||
|
<a id="config.set_attributes"></a>
|
||||||
|
### set_attributes
|
||||||
|
```python
|
||||||
|
def set_attributes(self, **kwargs)
|
||||||
|
```
|
||||||
|
Set attributes on the config object. The root folder attribute can't be set here.
|
||||||
|
|
||||||
<a id="config.load_config"></a>
|
<a id="config.load_config"></a>
|
||||||
### load\_config
|
### load_config
|
||||||
```python
|
```python
|
||||||
def load_config(self, *, file: str = None, reload: bool = True, filename: str = None, config_dir: str = '')
|
def load_config(*, file: str | Path = None, filename: str = None, root: str | Path = None, **kwargs) -> Config
|
||||||
```
|
```
|
||||||
Load configuration settings from a file.
|
Load configuration settings from a file and reset the config object.
|
||||||
#### Parameters
|
|
||||||
| Name | Type | Description |
|
|
||||||
|--------------|--------|-------------------------------------------------------------------------------------------------------------|
|
|
||||||
| `file` | `str` | The file to load the configuration settings from. If not provided, the default file is used. |
|
|
||||||
| `reload` | `bool` | Whether to reload the configuration settings or not. |
|
|
||||||
| `filename` | `str` | The name of the file to load the configuration settings from. If not provided, the default filename is used |
|
|
||||||
| `config_dir` | `str` | The directory where the configuration file is located. Default is the root directory |
|
|
||||||
|
|
||||||
<a id="config.create_records_dir"></a>
|
#### Parameters:
|
||||||
### create_records_dir
|
| Name | Type | Description |
|
||||||
```python
|
|------------|---------------|----------------------------------------------------------------------------------------------------|
|
||||||
def create_records_dir(self, *, records_dir: str | Path = 'records'):
|
| `file` | `str \| Path` | The absolute path to the config file. |
|
||||||
```
|
| `filename` | `str` | The name of the file to load if file path is not specified. If not provided `aiomql.json` is used. |
|
||||||
Create a directory for saving trade records.
|
| `root` | `str` | The root directory of the project. |
|
||||||
#### Parameters
|
| `**kwargs` | `dict` | Additional keyword arguments to be set on the config object. |
|
||||||
| Name | Type | Description |
|
|
||||||
|----------------|-------------|-------------------------------------------------------------------|
|
|
||||||
| `records\_dir` | `str\|Path` | The directory where trade records are saved. Default is 'records' |
|
|
||||||
|
|||||||
+31
-28
@@ -9,8 +9,9 @@ MetaTrader 5 constants defined as Enums.
|
|||||||
- [opposite](#ordertype.opposite)
|
- [opposite](#ordertype.opposite)
|
||||||
- [BookType](#BookType)
|
- [BookType](#BookType)
|
||||||
- [TimeFrame](#TimeFrame)
|
- [TimeFrame](#TimeFrame)
|
||||||
- [time](#timeframe.time)
|
- [get_timeframe](#timeframe.get_timeframe)
|
||||||
- [get](#timeframe.get)
|
- [seconds](#timeframe.seconds)
|
||||||
|
- [all](#timeframe.all)
|
||||||
- [CopyTicks](#CopyTicks)
|
- [CopyTicks](#CopyTicks)
|
||||||
- [PositionType](#PositionType)
|
- [PositionType](#PositionType)
|
||||||
- [PositionReason](#PositionReason)
|
- [PositionReason](#PositionReason)
|
||||||
@@ -156,41 +157,43 @@ TIMEFRAME Enum.
|
|||||||
| `W1` | 604800 | One Week |
|
| `W1` | 604800 | One Week |
|
||||||
| `MN1` | 2592000 | One Month |
|
| `MN1` | 2592000 | One Month |
|
||||||
|
|
||||||
<a id="timeframe.get"></a>
|
|
||||||
### get
|
|
||||||
```python
|
|
||||||
@classmethod
|
|
||||||
def get(cls, time: int) -> 'TimeFrame':
|
|
||||||
```
|
|
||||||
Gets the TIMEFRAME enum value from a time in seconds
|
|
||||||
#### Parameters
|
|
||||||
| Name | Type | Description |
|
|
||||||
|-------|------|----------------------|
|
|
||||||
| time | int | The time in seconds |
|
|
||||||
#### Returns
|
|
||||||
| Type | Description |
|
|
||||||
|------------|--------------------------------------|
|
|
||||||
| TimeFrame | The TIMEFRAME enum value |
|
|
||||||
|
|
||||||
<a id="timeframe.time"></a>
|
<a id="timeframe.seconds"></a>
|
||||||
### time
|
### seconds
|
||||||
```python
|
```python
|
||||||
@property
|
@property
|
||||||
def time()
|
def seconds() -> int
|
||||||
```
|
```
|
||||||
The number of seconds in a TIMEFRAME
|
The number of seconds in a TIMEFRAME
|
||||||
#### Returns
|
|
||||||
| Type | Description |
|
|
||||||
|------|--------------------------------------|
|
|
||||||
| int | The number of seconds in a TIMEFRAME |
|
|
||||||
|
|
||||||
<a id="TimeFrame.example"></a>
|
|
||||||
### Example
|
|
||||||
|
|
||||||
|
<a id="timeframe.get_timeframe"></a>
|
||||||
|
#### get_timeframe
|
||||||
```python
|
```python
|
||||||
t = TimeFrame.H1
|
@property
|
||||||
print(t.seconds) # 3600
|
def get_timeframe()
|
||||||
```
|
```
|
||||||
|
Get a timeframe object from a time value in seconds
|
||||||
|
|
||||||
|
#### Returns:
|
||||||
|
| Type | Description |
|
||||||
|
|-----------|-----------------------------|
|
||||||
|
| TimeFrame | The corresponding timeframe |
|
||||||
|
|
||||||
|
|
||||||
|
<a id="timeframe.all"></a>
|
||||||
|
#### all
|
||||||
|
```python
|
||||||
|
@classmethod
|
||||||
|
def all()
|
||||||
|
```
|
||||||
|
Get all the timeframes
|
||||||
|
|
||||||
|
#### Returns:
|
||||||
|
| Type | Description |
|
||||||
|
|-----------------------|-----------------------------|
|
||||||
|
| tuple[TimeFrame, ...] | All the timeframes |
|
||||||
|
|
||||||
|
|
||||||
<a id="CopyTicks"></a>
|
<a id="CopyTicks"></a>
|
||||||
## CopyTicks
|
## CopyTicks
|
||||||
|
|||||||
+16
-12
@@ -1,21 +1,24 @@
|
|||||||
# Errors
|
# Errors
|
||||||
|
|
||||||
## Tabel of contents
|
## Tabel of contents
|
||||||
- [Error](#errors.Error)
|
- [Error](#errors.error)
|
||||||
- [is_connection_error](#errors.is_connection_error)
|
- [is_connection_error](#errors.is_connection_error)
|
||||||
|
|
||||||
<a id="errors.Error"></a>
|
|
||||||
|
<a id="errors.error"></a>
|
||||||
## Error
|
## Error
|
||||||
```python
|
```python
|
||||||
class Error()
|
class Error
|
||||||
```
|
```
|
||||||
Error class for handling errors from MetaTrader 5.
|
Error class for handling errors.
|
||||||
#### Attributes
|
|
||||||
| Name | Type | Description |
|
#### Attributes:
|
||||||
|----------------|--------|----------------------------------------------|
|
| Name | Type | Description |
|
||||||
| `code` | `int` | Error code |
|
|----------------|--------------|----------------------------------------------|
|
||||||
| `description` | `str` | Error description |
|
| `code` | `int` | Error code |
|
||||||
| `descriptions` | `dict` | A dictionary of error codes and descriptions |
|
| `description` | `str` | Error description |
|
||||||
|
| `descriptions` | `dict` | A dictionary of error codes and descriptions |
|
||||||
|
| `conn_errors` | `tuple[int]` | A tuple of connection errors |
|
||||||
|
|
||||||
|
|
||||||
<a id="errors.is_connection_error"></a>
|
<a id="errors.is_connection_error"></a>
|
||||||
@@ -23,8 +26,9 @@ Error class for handling errors from MetaTrader 5.
|
|||||||
```python
|
```python
|
||||||
def is_connection_error(self) -> bool
|
def is_connection_error(self) -> bool
|
||||||
```
|
```
|
||||||
Check if error is a connection error.
|
Check if an error is a connection error.
|
||||||
#### Returns
|
|
||||||
|
#### Returns:
|
||||||
| Type | Description |
|
| Type | Description |
|
||||||
|--------|------------------------------------------------------|
|
|--------|------------------------------------------------------|
|
||||||
| `bool` | True if error is a connection error, False otherwise |
|
| `bool` | True if error is a connection error, False otherwise |
|
||||||
+20
-8
@@ -2,36 +2,48 @@
|
|||||||
Exceptions for the aiomql package.
|
Exceptions for the aiomql package.
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
- [LoginError](#exceptions.LoginError)
|
- [LoginError](#exceptions.login_error)
|
||||||
- [VolumeError](#exceptions.VolumeError)
|
- [VolumeError](#exceptions.volume_error)
|
||||||
- [SymbolError](#exceptions.SymbolError)
|
- [SymbolError](#exceptions.symbol_error)
|
||||||
- [OrderError](#exceptions.OrderError)
|
- [OrderError](#exceptions.order_error)
|
||||||
|
- [StopTradingError](#exceptions.stop_trading_error)
|
||||||
|
|
||||||
|
|
||||||
<a id="exceptions.LoginError"></a>
|
<a id="exceptions.login_error"></a>
|
||||||
### LoginError
|
### LoginError
|
||||||
```python
|
```python
|
||||||
class LoginError(Exception)
|
class LoginError(Exception)
|
||||||
```
|
```
|
||||||
Raised when an error occurs when logging in.
|
Raised when an error occurs when logging in.
|
||||||
|
|
||||||
<a id="exceptions.VolumeError"></a>
|
|
||||||
|
<a id="exceptions.volume_error"></a>
|
||||||
### VolumeError
|
### VolumeError
|
||||||
```python
|
```python
|
||||||
class VolumeError(Exception)
|
class VolumeError(Exception)
|
||||||
```
|
```
|
||||||
Raised when a volume is not valid or out of range for a symbol.
|
Raised when a volume is not valid or out of range for a symbol.
|
||||||
|
|
||||||
<a id="exceptions.SymbolError"></a>
|
|
||||||
|
<a id="exceptions.symbol_error"></a>
|
||||||
### SymbolError
|
### SymbolError
|
||||||
```python
|
```python
|
||||||
class SymbolError(Exception)
|
class SymbolError(Exception)
|
||||||
```
|
```
|
||||||
Raised when a symbol is not provided where required or not available in the Market Watch.
|
Raised when a symbol is not provided where required or not available in the Market Watch.
|
||||||
|
|
||||||
<a id="exceptions.OrderError"></a>
|
|
||||||
|
<a id="exceptions.order_error"></a>
|
||||||
### OrderError
|
### OrderError
|
||||||
```python
|
```python
|
||||||
class OrderError(Exception)
|
class OrderError(Exception)
|
||||||
```
|
```
|
||||||
Raised when an error occurs when working with the order class.
|
Raised when an error occurs when working with the order class.
|
||||||
|
|
||||||
|
|
||||||
|
<a id="exceptions.Stop_trading_error"></a>
|
||||||
|
### StopTradingError
|
||||||
|
```python
|
||||||
|
class StopTradingError(Exception)
|
||||||
|
```
|
||||||
|
Raised when an error occurs when trying to stop trading.
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
# MetaBackTester
|
||||||
|
|
||||||
|
## Table of Contents
|
||||||
|
- [MetaBackTester](#metabacktester)
|
||||||
|
- [\__init\__](#metabacktester.__init__)
|
||||||
|
- [backtest_engine](#metabacktester.backtest_engine)
|
||||||
|
- [backtest_engine.setter](#metabacktester.backtest_engine.setter)
|
||||||
|
|
||||||
|
|
||||||
|
<a id="metabacktester.meta_back_tester"></a>
|
||||||
|
### MetaBackTester
|
||||||
|
```python
|
||||||
|
class MetaBackTester(MetaTrader)
|
||||||
|
```
|
||||||
|
A class for testing trading strategies in the MetaTrader 5 terminal. A subclass of MetaTrader.
|
||||||
|
|
||||||
|
#### Attributes:
|
||||||
|
| Name | Type | Description |
|
||||||
|
|-------------------|------------------|---------------------------------------------------------------|
|
||||||
|
| `backtest_engine` | `BackTestEngine` | The backtesting engine to use for testing trading strategies. |
|
||||||
|
|
||||||
|
|
||||||
|
<a id="metabacktester.__init__"></a>
|
||||||
|
### \__init\__
|
||||||
|
```python
|
||||||
|
def __init__(self, *, backtest_engine: BackTestEngine = None)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Parameters:
|
||||||
|
| Name | Type | Description |
|
||||||
|
|-------------------|------------------|--------------------------------------------------|
|
||||||
|
| `backtest_engine` | `BackTestEngine` | The backtesting engine to use for testing trades |
|
||||||
|
|
||||||
|
<a id="metabacktester.backtest_engine"></a>
|
||||||
|
```python
|
||||||
|
@property
|
||||||
|
def backtest_engine(self) -> BackTestEngine
|
||||||
|
```
|
||||||
|
Returns the backtest engine object.
|
||||||
|
|
||||||
|
|
||||||
|
<a id="metabacktester.backtest_engine.setter"></a>
|
||||||
|
```python
|
||||||
|
@backtest_engine.setter
|
||||||
|
def backtest_engine(self, value: BackTestEngine):
|
||||||
|
```
|
||||||
|
Sets the backtest engine object.
|
||||||
+86
-74
@@ -1,68 +1,71 @@
|
|||||||
# Models
|
# Models
|
||||||
This module contains the models used in the aiomql package. These models are used to represent the data returned from the MetaTrader 5 terminal.
|
|
||||||
They are all subclasses of the `Base` class.
|
This module contains the models used in the aiomql package. These models are used to represent the data returned from
|
||||||
|
the MetaTrader 5 terminal. They are all subclasses of the `Base` class.
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
- [AccountInfo](#AccountInfo)
|
- [AccountInfo](#models.account_info)
|
||||||
- [TerminalInfo](#TerminalInfo)
|
- [TerminalInfo](#models.terminal_info)
|
||||||
- [SymbolInfo](#SymbolInfo)
|
- [SymbolInfo](#models.symbol.info)
|
||||||
- [BookInfo](#BookInfo)
|
- [BookInfo](#models.book_info)
|
||||||
- [TradeOrder](#TradeOrder)
|
- [TradeOrder](#models.trade_order)
|
||||||
- [TradeRequest](#TradeRequest)
|
- [TradeRequest](#models_trade_request)
|
||||||
- [OrderCheckResult](#OrderCheckResult)
|
- [OrderCheckResult](#models.order_check_result)
|
||||||
- [OrderSendResult](#OrderSendResult)
|
- [OrderSendResult](#models.order_send_result)
|
||||||
- [TradePosition](#TradePosition)
|
- [TradePosition](#models.trade_position)
|
||||||
- [TradeDeal](#TradeDeal)
|
- [TradeDeal](#models.trade_deal)
|
||||||
|
|
||||||
<a id="AccountInfo"></a>
|
|
||||||
## AccountInfo
|
<a id="models.account_info"></a>
|
||||||
|
### AccountInfo
|
||||||
```python
|
```python
|
||||||
class AccountInfo(Base)
|
class AccountInfo(Base)
|
||||||
```
|
```
|
||||||
Account Information Class.
|
Account Information Class.
|
||||||
#### Attributes
|
#### Attributes:
|
||||||
| Name | Type | Description | Default |
|
| Name | Type | Description | Default |
|
||||||
|----------------------|--------------------|------------------------------------------|---------|
|
|----------------------|----------------------|------------------------------------------|---------|
|
||||||
| `login` | `int` | Account number | |
|
| `login` | `int` | Account number | |
|
||||||
| `password` | `str` | Account password | |
|
| `password` | `str` | Account password | |
|
||||||
| `server` | `str` | Trade server name | |
|
| `server` | `str` | Trade server name | |
|
||||||
| `trade_mode` | AccountTradeMode | Trade mode | |
|
| `trade_mode` | AccountTradeMode | Trade mode | |
|
||||||
| `balance` | `float` | Account balance | |
|
| `balance` | `float` | Account balance | |
|
||||||
| `leverage` | `float` | Account leverage | |
|
| `leverage` | `float` | Account leverage | |
|
||||||
| `profit` | `float` | Account profit | |
|
| `profit` | `float` | Account profit | |
|
||||||
| `point` | `float` | Point size | |
|
| `point` | `float` | Point size | |
|
||||||
| `amount` | `float` | Account amount | 0 |
|
| `amount` | `float` | Account amount | 0 |
|
||||||
| `equity` | `float` | Account equity | |
|
| `equity` | `float` | Account equity | |
|
||||||
| `credit` | `float` | Account credit | |
|
| `credit` | `float` | Account credit | |
|
||||||
| `margin` | `float` | Account margin | |
|
| `margin` | `float` | Account margin | |
|
||||||
| `margin_level` | `float` | Margin level | |
|
| `margin_level` | `float` | Margin level | |
|
||||||
| `margin_free` | `float` | Free margin | |
|
| `margin_free` | `float` | Free margin | |
|
||||||
| `margin_mode` | AccountMarginMode | Margin calculation mode | |
|
| `margin_mode` | `AccountMarginMode` | Margin calculation mode | |
|
||||||
| `margin_so_mode` | AccountStopoutMode | Stop out mode | |
|
| `margin_so_mode` | `AccountStopoutMode` | Stop out mode | |
|
||||||
| `margin_so_call` | `float` | Margin call level | |
|
| `margin_so_call` | `float` | Margin call level | |
|
||||||
| `margin_so_so` | `float` | Stop out level | |
|
| `margin_so_so` | `float` | Stop out level | |
|
||||||
| `margin_initial` | `float` | Initial margin | |
|
| `margin_initial` | `float` | Initial margin | |
|
||||||
| `margin_maintenance` | `float` | Maintenance margin | |
|
| `margin_maintenance` | `float` | Maintenance margin | |
|
||||||
| `fifo_close` | `bool` | FIFO close flag | |
|
| `fifo_close` | `bool` | FIFO close flag | |
|
||||||
| `limit_orders` | `float` | Limit orders | |
|
| `limit_orders` | `float` | Limit orders | |
|
||||||
| `currency` | `str` | Account currency | "USD" |
|
| `currency` | `str` | Account currency | "USD" |
|
||||||
| `trade_allowed` | `bool` | Trade allowed flag | True |
|
| `trade_allowed` | `bool` | Trade allowed flag | True |
|
||||||
| `trade_expert` | `bool` | Trade expert flag | True |
|
| `trade_expert` | `bool` | Trade expert flag | True |
|
||||||
| `currency_digits` | `int` | Number of digits after the decimal point | |
|
| `currency_digits` | `int` | Number of digits after the decimal point | |
|
||||||
| `assets` | `float` | Assets | |
|
| `assets` | `float` | Assets | |
|
||||||
| `liabilities` | `float` | Liabilities | |
|
| `liabilities` | `float` | Liabilities | |
|
||||||
| `commission_blocked` | `float` | Blocked commission | |
|
| `commission_blocked` | `float` | Blocked commission | |
|
||||||
| `name` | `str` | Account name | |
|
| `name` | `str` | Account name | |
|
||||||
| `company` | `str` | Company name | |
|
| `company` | `str` | Company name | |
|
||||||
|
|
||||||
<a id="TerminalInfo"></a>
|
|
||||||
## TerminalInfo
|
<a id="models.terminal_info"></a>
|
||||||
|
### TerminalInfo
|
||||||
```python
|
```python
|
||||||
class TerminalInfo(Base)
|
class TerminalInfo(Base)
|
||||||
```
|
```
|
||||||
Terminal information class. Holds information about the terminal.
|
Terminal information class. Holds information about the terminal.
|
||||||
|
|
||||||
#### Attributes
|
#### Attributes:
|
||||||
| Name | Type | Description | Default |
|
| Name | Type | Description | Default |
|
||||||
|-------------------------|---------|----------------------------|---------|
|
|-------------------------|---------|----------------------------|---------|
|
||||||
| `community_account` | `bool` | Community account flag | |
|
| `community_account` | `bool` | Community account flag | |
|
||||||
@@ -88,13 +91,14 @@ Terminal information class. Holds information about the terminal.
|
|||||||
| `data_path` | `str` | Data path | |
|
| `data_path` | `str` | Data path | |
|
||||||
| `commondata_path` | `str` | Common data path | |
|
| `commondata_path` | `str` | Common data path | |
|
||||||
|
|
||||||
<a id="SymbolInfo"></a>
|
|
||||||
## SymbolInfo
|
<a id="models.symbol_info"></a>
|
||||||
|
### SymbolInfo
|
||||||
```python
|
```python
|
||||||
class SymbolInfo(Base)
|
class SymbolInfo(Base)
|
||||||
```
|
```
|
||||||
Symbol Information Class. Symbols are financial instruments available for trading in the MetaTrader 5 terminal.
|
Symbol Information Class. Symbols are financial instruments available for trading in the MetaTrader 5 terminal.
|
||||||
#### Attributes
|
#### Attributes:
|
||||||
| Name | Type | Description | Default |
|
| Name | Type | Description | Default |
|
||||||
|------------------------------|------------------------|----------------------------|---------|
|
|------------------------------|------------------------|----------------------------|---------|
|
||||||
| `name` | `str` | Symbol name | |
|
| `name` | `str` | Symbol name | |
|
||||||
@@ -195,13 +199,14 @@ Symbol Information Class. Symbols are financial instruments available for tradin
|
|||||||
| `page` | `str` | Page | |
|
| `page` | `str` | Page | |
|
||||||
| `path` | `str` | Path | |
|
| `path` | `str` | Path | |
|
||||||
|
|
||||||
<a id="BookInfo"></a>
|
|
||||||
## BookInfo
|
<a id="models.book_info"></a>
|
||||||
|
### BookInfo
|
||||||
```python
|
```python
|
||||||
class BookInfo(Base)
|
class BookInfo(Base)
|
||||||
```
|
```
|
||||||
Book Information Class.
|
Book Information Class.
|
||||||
#### Attributes
|
#### Attributes:
|
||||||
| Name | Type | Description | Default |
|
| Name | Type | Description | Default |
|
||||||
|--------------|------------|-------------|---------|
|
|--------------|------------|-------------|---------|
|
||||||
| `symbol` | `str` | Symbol | |
|
| `symbol` | `str` | Symbol | |
|
||||||
@@ -210,13 +215,15 @@ Book Information Class.
|
|||||||
| `volume` | `float` | Volume | |
|
| `volume` | `float` | Volume | |
|
||||||
| `volume_dbl` | `float` | Volume dbl | |
|
| `volume_dbl` | `float` | Volume dbl | |
|
||||||
|
|
||||||
<a id="TradeOrder"></a>
|
|
||||||
## TradeOrder
|
<a id="models.trade_order"></a>
|
||||||
|
#### TradeOrder
|
||||||
```python
|
```python
|
||||||
class TradeOrder(Base)
|
class TradeOrder(Base)
|
||||||
```
|
```
|
||||||
Trade Order Class.
|
Trade Order Class.
|
||||||
#### Attributes
|
|
||||||
|
#### Attributes:
|
||||||
| Name | Type | Description | Default |
|
| Name | Type | Description | Default |
|
||||||
|-------------------|----------------|-----------------|---------|
|
|-------------------|----------------|-----------------|---------|
|
||||||
| `ticket` | `int` | Ticket | |
|
| `ticket` | `int` | Ticket | |
|
||||||
@@ -244,13 +251,14 @@ Trade Order Class.
|
|||||||
| `comment` | `str` | Comment | |
|
| `comment` | `str` | Comment | |
|
||||||
| `external_id` | `str` | External id | |
|
| `external_id` | `str` | External id | |
|
||||||
|
|
||||||
<a id="TradeRequest"></a>
|
|
||||||
|
<a id="models.trade_request"></a>
|
||||||
## TradeRequest
|
## TradeRequest
|
||||||
```python
|
```python
|
||||||
class TradeRequest(Base)
|
class TradeRequest(Base)
|
||||||
```
|
```
|
||||||
Trade Request Class.
|
Trade Request Class.
|
||||||
#### Attributes
|
#### Attributes:
|
||||||
| Name | Type | Description | Default |
|
| Name | Type | Description | Default |
|
||||||
|----------------|--------------|--------------|---------|
|
|----------------|--------------|--------------|---------|
|
||||||
| `action` | TradeAction | Action | |
|
| `action` | TradeAction | Action | |
|
||||||
@@ -272,13 +280,14 @@ Trade Request Class.
|
|||||||
| `magic` | `int` | Magic | |
|
| `magic` | `int` | Magic | |
|
||||||
| `deviation` | `int` | Deviation | |
|
| `deviation` | `int` | Deviation | |
|
||||||
|
|
||||||
<a id="OrderCheckResult"></a>
|
|
||||||
## OrderCheckResult
|
<a id="models.order_check_result"></a>
|
||||||
|
### OrderCheckResult
|
||||||
```python
|
```python
|
||||||
class OrderCheckResult(Base)
|
class OrderCheckResult(Base)
|
||||||
```
|
```
|
||||||
Order Check Result
|
Order Check Result
|
||||||
#### Attributes
|
#### Attributes:
|
||||||
| Name | Type | Description | Default |
|
| Name | Type | Description | Default |
|
||||||
|----------------|----------------|--------------|---------|
|
|----------------|----------------|--------------|---------|
|
||||||
| `retcode` | `int` | Retcode | |
|
| `retcode` | `int` | Retcode | |
|
||||||
@@ -291,14 +300,15 @@ Order Check Result
|
|||||||
| `comment` | `str` | Comment | |
|
| `comment` | `str` | Comment | |
|
||||||
| `request` | `TradeRequest` | Request | |
|
| `request` | `TradeRequest` | Request | |
|
||||||
|
|
||||||
<a id="OrderSendResult"></a>
|
|
||||||
## OrderSendResult
|
<a id="models.order_send_result"></a>
|
||||||
|
### OrderSendResult
|
||||||
```python
|
```python
|
||||||
class OrderSendResult(Base)
|
class OrderSendResult(Base)
|
||||||
```
|
```
|
||||||
Order Send Result
|
Order Send Result
|
||||||
|
|
||||||
#### Attributes
|
#### Attributes:
|
||||||
| Name | Type | Description | Default |
|
| Name | Type | Description | Default |
|
||||||
|--------------------|----------------|------------------|---------|
|
|--------------------|----------------|------------------|---------|
|
||||||
| `retcode` | `int` | Retcode | |
|
| `retcode` | `int` | Retcode | |
|
||||||
@@ -314,13 +324,14 @@ Order Send Result
|
|||||||
| `retcode_external` | `int` | Retcode external | |
|
| `retcode_external` | `int` | Retcode external | |
|
||||||
| `profit` | `float` | Profit | |
|
| `profit` | `float` | Profit | |
|
||||||
|
|
||||||
<a id="TradePosition"></a>
|
|
||||||
## TradePosition
|
<a id="models.trade_position"></a>
|
||||||
|
### TradePosition
|
||||||
```python
|
```python
|
||||||
class TradePosition(Base)
|
class TradePosition(Base)
|
||||||
```
|
```
|
||||||
Trade Position
|
Trade Position
|
||||||
#### Attributes
|
#### Attributes:
|
||||||
| Name | Type | Description | Default |
|
| Name | Type | Description | Default |
|
||||||
|-------------------|------------------|-----------------|---------|
|
|-------------------|------------------|-----------------|---------|
|
||||||
| `ticket` | `int` | Ticket | |
|
| `ticket` | `int` | Ticket | |
|
||||||
@@ -343,13 +354,14 @@ Trade Position
|
|||||||
| `comment` | `str` | Comment | |
|
| `comment` | `str` | Comment | |
|
||||||
| `external_id` | `str` | External id | |
|
| `external_id` | `str` | External id | |
|
||||||
|
|
||||||
<a id="TradeDeal"></a>
|
|
||||||
## TradeDeal
|
<a id="models.trade_deal"></a>
|
||||||
|
### TradeDeal
|
||||||
```python
|
```python
|
||||||
class TradeDeal(Base)
|
class TradeDeal(Base)
|
||||||
```
|
```
|
||||||
Trade Deal
|
Trade Deal
|
||||||
#### Attributes
|
#### Attributes:
|
||||||
| Name | Type | Description | Default |
|
| Name | Type | Description | Default |
|
||||||
|---------------|--------------|-------------|---------|
|
|---------------|--------------|-------------|---------|
|
||||||
| `ticket` | `int` | Ticket | |
|
| `ticket` | `int` | Ticket | |
|
||||||
|
|||||||
+4
-3
@@ -1,11 +1,11 @@
|
|||||||
# Account
|
# Account
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
- [Account](#account.Account)
|
- [Account](#account.account)
|
||||||
- [refresh](#account.refresh)
|
- [refresh](#account.refresh)
|
||||||
|
|
||||||
|
|
||||||
<a id="account.Account"></a>
|
<a id="account.account"></a>
|
||||||
### Account
|
### Account
|
||||||
```python
|
```python
|
||||||
class Account(_Base, AccountInfo)
|
class Account(_Base, AccountInfo)
|
||||||
@@ -13,11 +13,12 @@ class Account(_Base, AccountInfo)
|
|||||||
A singleton class for managing a trading account. A subclass of _Base and AccountInfo. It supports asynchronous context
|
A singleton class for managing a trading account. A subclass of _Base and AccountInfo. It supports asynchronous context
|
||||||
management protocol.
|
management protocol.
|
||||||
|
|
||||||
#### Attributes
|
#### Attributes:
|
||||||
| Name | Type | Description | Default |
|
| Name | Type | Description | Default |
|
||||||
|-------------|-------------------|------------------------------------------------------|---------|
|
|-------------|-------------------|------------------------------------------------------|---------|
|
||||||
| `connected` | `bool` | Status of connection to MetaTrader 5 Terminal | False |
|
| `connected` | `bool` | Status of connection to MetaTrader 5 Terminal | False |
|
||||||
|
|
||||||
|
|
||||||
<a id="account.refresh"></a>
|
<a id="account.refresh"></a>
|
||||||
### refresh
|
### refresh
|
||||||
```python
|
```python
|
||||||
|
|||||||
+14
-6
@@ -1,7 +1,7 @@
|
|||||||
# Bot
|
# Bot
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
- [Bot](#bot.Bot)
|
- [Bot](#bot.bot)
|
||||||
- [\_\_init\_\_](#bot.init)
|
- [\_\_init\_\_](#bot.init)
|
||||||
- [initialize](#bot.initialize)
|
- [initialize](#bot.initialize)
|
||||||
- [execute](#bot.execute)
|
- [execute](#bot.execute)
|
||||||
@@ -13,14 +13,14 @@
|
|||||||
- [add_strategy_all](#bot.add_strategy_all)
|
- [add_strategy_all](#bot.add_strategy_all)
|
||||||
- [process_pool](#bot.run_bots)
|
- [process_pool](#bot.run_bots)
|
||||||
|
|
||||||
<a id='bot.Bot'></a>
|
<a id='bot.bot'></a>
|
||||||
### Bot
|
### Bot
|
||||||
```python
|
```python
|
||||||
class Bot
|
class Bot
|
||||||
```
|
```
|
||||||
"""The bot class. Create a bot instance to run strategies.
|
"""The bot class. Create a bot instance to run strategies.
|
||||||
|
|
||||||
#### Attributes.
|
#### Attributes:
|
||||||
| Name | Type | Description | Default |
|
| Name | Type | Description | Default |
|
||||||
|--------------|--------------------|--------------------------------------------|--------------|
|
|--------------|--------------------|--------------------------------------------|--------------|
|
||||||
| `account` | `Account` | Account Object. | None |
|
| `account` | `Account` | Account Object. | None |
|
||||||
@@ -30,12 +30,13 @@ class Bot
|
|||||||
| `config` | `Config` | A Config instance | Config() |
|
| `config` | `Config` | A Config instance | Config() |
|
||||||
|
|
||||||
<a id='bot.init'></a>
|
<a id='bot.init'></a>
|
||||||
### \_\_init\_\_
|
### \__init\__
|
||||||
```python
|
```python
|
||||||
def __init__()
|
def __init__()
|
||||||
```
|
```
|
||||||
Initializes the Bot class.
|
Initializes the Bot class.
|
||||||
|
|
||||||
|
|
||||||
<a id='bot.initialize'></a>
|
<a id='bot.initialize'></a>
|
||||||
### initialize
|
### initialize
|
||||||
```python
|
```python
|
||||||
@@ -52,7 +53,6 @@ Note: *initialize_sync* is a synchronous version of this method.
|
|||||||
| `SystemExit` | If sign in was not successful |
|
| `SystemExit` | If sign in was not successful |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a id='bot.execute'></a>
|
<a id='bot.execute'></a>
|
||||||
### execute
|
### execute
|
||||||
```python
|
```python
|
||||||
@@ -61,6 +61,7 @@ def execute()
|
|||||||
Executes the bot. Use this method to run the bot in a synchronous manner.
|
Executes the bot. Use this method to run the bot in a synchronous manner.
|
||||||
This method is blocking and will not return until the bot is done running.
|
This method is blocking and will not return until the bot is done running.
|
||||||
|
|
||||||
|
|
||||||
<a id='bot.start'></a>
|
<a id='bot.start'></a>
|
||||||
### start
|
### start
|
||||||
```python
|
```python
|
||||||
@@ -68,13 +69,14 @@ async def start()
|
|||||||
```
|
```
|
||||||
Initialize the bot and execute it. Similar to calling **execute** method but is asynchronous.
|
Initialize the bot and execute it. Similar to calling **execute** method but is asynchronous.
|
||||||
|
|
||||||
|
|
||||||
<a id='bot.add_coroutine'></a>
|
<a id='bot.add_coroutine'></a>
|
||||||
### add_coroutine
|
### add_coroutine
|
||||||
```python
|
```python
|
||||||
def add_coroutine(self, coroutine: Coroutine, on_separate_thread=False, **kwargs)
|
def add_coroutine(self, coroutine: Coroutine, on_separate_thread=False, **kwargs)
|
||||||
```
|
```
|
||||||
Add a coroutine to the executor. By default, all coroutines added to the executor run on this same thread,
|
Add a coroutine to the executor. By default, all coroutines added to the executor run on this same thread,
|
||||||
using _asyncio.gather_, but if _on_separate_thread_ is true then the coroutine is given it's own thread.
|
using `asyncio.gather`, but if `on_separate_thread` is true then the coroutine is given it's own thread.
|
||||||
|
|
||||||
#### Parameters:
|
#### Parameters:
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
@@ -83,6 +85,7 @@ using _asyncio.gather_, but if _on_separate_thread_ is true then the coroutine i
|
|||||||
| `on_separate_thread` | `bool` | Run coroutine on a separate thread in the executor |
|
| `on_separate_thread` | `bool` | Run coroutine on a separate thread in the executor |
|
||||||
| `kwargs` | `Any` | Keyword arguments to pass to the coroutine |
|
| `kwargs` | `Any` | Keyword arguments to pass to the coroutine |
|
||||||
|
|
||||||
|
|
||||||
<a id='bot.add_function'></a>
|
<a id='bot.add_function'></a>
|
||||||
### add_function
|
### add_function
|
||||||
```python
|
```python
|
||||||
@@ -95,6 +98,7 @@ Add a function to the executor.
|
|||||||
| `function` | `Callable` | A function to run in the executor |
|
| `function` | `Callable` | A function to run in the executor |
|
||||||
| `kwargs` | `Any` | Keyword arguments to pass to the function |
|
| `kwargs` | `Any` | Keyword arguments to pass to the function |
|
||||||
|
|
||||||
|
|
||||||
<a id='bot.add_strategy'></a>
|
<a id='bot.add_strategy'></a>
|
||||||
### add_strategy
|
### add_strategy
|
||||||
```python
|
```python
|
||||||
@@ -107,23 +111,27 @@ Add a strategy to the list of strategies.
|
|||||||
|------------|------------|-----------------------------------|
|
|------------|------------|-----------------------------------|
|
||||||
| `strategy` | `Strategy` | A Strategy instance to run on bot |
|
| `strategy` | `Strategy` | A Strategy instance to run on bot |
|
||||||
|
|
||||||
|
|
||||||
<a id='bot.add_strategies'></a>
|
<a id='bot.add_strategies'></a>
|
||||||
### add_strategies
|
### add_strategies
|
||||||
```python
|
```python
|
||||||
def add_strategies(strategies: Iterable[Strategy])
|
def add_strategies(strategies: Iterable[Strategy])
|
||||||
```
|
```
|
||||||
Add multiple strategies at the same time
|
Add multiple strategies at the same time
|
||||||
|
|
||||||
#### Parameters:
|
#### Parameters:
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
|--------------|----------------------|-----------------------------------|
|
|--------------|----------------------|-----------------------------------|
|
||||||
| `strategies` | `Iterable[Strategy]` | An iterable of Strategy instances |
|
| `strategies` | `Iterable[Strategy]` | An iterable of Strategy instances |
|
||||||
|
|
||||||
|
|
||||||
<a id='bot.add_strategy_all'></a>
|
<a id='bot.add_strategy_all'></a>
|
||||||
### add_strategy_all
|
### add_strategy_all
|
||||||
```python
|
```python
|
||||||
def add_strategy_all(*, strategy: Type[Strategy], params: dict | None = None, symbols: list[Symbol] = None, **kwargs)
|
def add_strategy_all(*, strategy: Type[Strategy], params: dict | None = None, symbols: list[Symbol] = None, **kwargs)
|
||||||
```
|
```
|
||||||
Use this to run a single strategy on multiple symbols with the same parameters and keyword arguments.
|
Use this to run a single strategy on multiple symbols with the same parameters and keyword arguments.
|
||||||
|
|
||||||
#### Parameters:
|
#### Parameters:
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
|------------|------------------|---------------------------------------------|
|
|------------|------------------|---------------------------------------------|
|
||||||
|
|||||||
@@ -1,66 +0,0 @@
|
|||||||
# Utils
|
|
||||||
Utils is a collection of utility functions that are used throughout the codebase. It is a collection of functions.
|
|
||||||
|
|
||||||
## Table of Contents
|
|
||||||
- [round_off](#round_off)
|
|
||||||
- [find_bearish_fractal](#find_bearish_fractal)
|
|
||||||
- [find_bullish_fractal](#find_bullish_fractal)
|
|
||||||
- [dict_to_string](#dict_to_string)
|
|
||||||
|
|
||||||
<a id="round_off"></a>
|
|
||||||
```python
|
|
||||||
def round_off(value: float, step: float, round_down: bool = True) -> float:
|
|
||||||
```
|
|
||||||
Rounds off a value to the nearest step. If round_down is True, it will round down, otherwise it will round up.
|
|
||||||
#### Parameters
|
|
||||||
| Name | Type | Description | Default |
|
|
||||||
|------------|-------|--------------------------------------------|---------|
|
|
||||||
| value | float | The value to round off. | |
|
|
||||||
| step | float | The step to round off to. | |
|
|
||||||
| round_down | bool | Whether to round down. If False, round up. | True |
|
|
||||||
#### Returns
|
|
||||||
| Type | Description |
|
|
||||||
|-------|------------------------|
|
|
||||||
| float | The rounded off value. |
|
|
||||||
|
|
||||||
```python
|
|
||||||
def find_bearish_fractal(candles: Candles) -> Candle | None:
|
|
||||||
```
|
|
||||||
Finds the most recent bearish fractal in the candles.
|
|
||||||
#### Parameters
|
|
||||||
| Name | Type | Description | Default |
|
|
||||||
|---------|---------|----------------------------------|---------|
|
|
||||||
| candles | Candles | The candles to search for. | |
|
|
||||||
#### Returns
|
|
||||||
| Type | Description |
|
|
||||||
|--------|----------------------------------|
|
|
||||||
| Candle | The most recent bearish fractal. |
|
|
||||||
|
|
||||||
```python
|
|
||||||
def find_bullish_fractal(candles: Candles) -> Candle | None:
|
|
||||||
```
|
|
||||||
Finds the most recent bullish fractal in the candles.
|
|
||||||
#### Parameters
|
|
||||||
| Name | Type | Description | Default |
|
|
||||||
|---------|---------|----------------------------------|---------|
|
|
||||||
| candles | Candles | The candles to search for. | |
|
|
||||||
#### Returns
|
|
||||||
| Type | Description |
|
|
||||||
|--------|----------------------------------|
|
|
||||||
| Candle | The most recent bullish fractal. |
|
|
||||||
|
|
||||||
<a id="dict_to_string"></a>
|
|
||||||
```python
|
|
||||||
def dict_to_string(data: dict, multi=True) -> str:
|
|
||||||
```
|
|
||||||
Converts a dictionary to a string. If multi is True, it will return a multi-line string.
|
|
||||||
#### Parameters
|
|
||||||
| Name | Type | Description | Default |
|
|
||||||
|-------|------|----------------------------------------|---------|
|
|
||||||
| data | dict | The dictionary to convert to a string. | |
|
|
||||||
| multi | bool | Whether to return a multi-line string. | True |
|
|
||||||
|
|
||||||
#### Returns
|
|
||||||
| Type | Description |
|
|
||||||
|------|-----------------------------|
|
|
||||||
| str | The dictionary as a string. |
|
|
||||||
@@ -3,7 +3,7 @@ import pickle
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from datetime import datetime, UTC
|
from datetime import datetime, UTC
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from typing import Sequence, NamedTuple
|
from typing import NamedTuple, Iterable
|
||||||
|
|
||||||
import MetaTrader5
|
import MetaTrader5
|
||||||
from numpy import ndarray
|
from numpy import ndarray
|
||||||
@@ -95,8 +95,8 @@ class GetData:
|
|||||||
"""
|
"""
|
||||||
data: BackTestData
|
data: BackTestData
|
||||||
|
|
||||||
def __init__(self, *, start: datetime, end: datetime, symbols: Sequence[str],
|
def __init__(self, *, start: datetime, end: datetime, symbols: Iterable[str],
|
||||||
timeframes: Sequence[TimeFrame], name: str = ""):
|
timeframes: Iterable[TimeFrame], name: str = ""):
|
||||||
"""
|
"""
|
||||||
Get the backtesting data from the MetaTrader5 terminal.
|
Get the backtesting data from the MetaTrader5 terminal.
|
||||||
|
|
||||||
|
|||||||
@@ -39,10 +39,12 @@ class Config:
|
|||||||
force_shutdown (bool): A signal to force shut down the terminal, default is False
|
force_shutdown (bool): A signal to force shut down the terminal, default is False
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
By default, the config class looks for a file named aiomql.json.
|
By default, the config class looks for a file named aiomql.json. This can be changed by setting the filename
|
||||||
You can change this by passing the filename and/or the config_dir keyword argument(s) to the constructor
|
attribute to the desired file name. The root directory of the project can be set by passing the root argument
|
||||||
or the load_config method.
|
to the load_config method or during object instantiation. If not provided it is assumed to be the current working
|
||||||
By passing reload=True to the load_config method, you can reload and search again for the config file.
|
directory. All directories and files are assumed to be relative to the root directory except when an absolute path
|
||||||
|
is provided, this includes the config file, the records_dir and the backtest_dir attributes.
|
||||||
|
The root directory is used to locate the config file and to set the records_dir and backtest_dir attributes.
|
||||||
"""
|
"""
|
||||||
login: int
|
login: int
|
||||||
trade_record_mode: Literal["csv", "json"]
|
trade_record_mode: Literal["csv", "json"]
|
||||||
@@ -113,13 +115,13 @@ class Config:
|
|||||||
self._backtest_engine = value
|
self._backtest_engine = value
|
||||||
|
|
||||||
def set_attributes(self, **kwargs):
|
def set_attributes(self, **kwargs):
|
||||||
"""Set keyword arguments as object attributes, The root folder attribute can't be set here.
|
"""Set keyword arguments as object attributes. The root folder attribute can't be set here.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
**kwargs: Object attributes and values as keyword arguments
|
**kwargs: Object attributes and values as keyword arguments
|
||||||
"""
|
"""
|
||||||
if kwargs.pop("root", None) is not None:
|
if kwargs.pop("root", None) is not None:
|
||||||
logger.warning("Tried setting root from set_attributes. Use load_config to change project root")
|
logger.debug("Tried setting root from set_attributes. Use load_config to change project root")
|
||||||
[setattr(self, key, value) for key, value in kwargs.items()]
|
[setattr(self, key, value) for key, value in kwargs.items()]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -149,7 +151,7 @@ class Config:
|
|||||||
return
|
return
|
||||||
|
|
||||||
def load_config(self, *, file: str | Path = None, filename: str = None, root: str | Path = None, **kwargs) -> Self:
|
def load_config(self, *, file: str | Path = None, filename: str = None, root: str | Path = None, **kwargs) -> Self:
|
||||||
"""Load configuration settings from a file.
|
"""Load configuration settings from a file and reset the config object.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
file (str | Path): The absolute path to the config file.
|
file (str | Path): The absolute path to the config file.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class Error:
|
class Error:
|
||||||
"""Error class for handling errors from MetaTrader 5."""
|
"""Error class for handling errors"""
|
||||||
|
|
||||||
descriptions = {
|
descriptions = {
|
||||||
# common errors
|
# common errors
|
||||||
|
|||||||
Reference in New Issue
Block a user