mirror of
https://github.com/Ichinga-Samuel/aiomql.git
synced 2026-08-03 15:27:44 +00:00
v4
This commit is contained in:
+54
-29
@@ -1,30 +1,55 @@
|
||||
# Table of Contents
|
||||
- [MetaTrader](core/meta_trader.md)
|
||||
- [Config](core/config.md)
|
||||
- [Base](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/core/base.md)
|
||||
- [Constants](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/core/constants.md)
|
||||
- [TaskQueue](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/core/task_queue.md)
|
||||
- [Models](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/core/models.md)
|
||||
- [Bot_Builder](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/bot_builder.md)
|
||||
- [Account](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/account.md)
|
||||
- [Candle](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/candle.md)
|
||||
- [Candles](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/candle.md)
|
||||
- [Executor](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/executor.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)
|
||||
- [Positions](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/postions.md)
|
||||
- [RAM](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/ram.md)
|
||||
- [Records](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/records.md)
|
||||
- [TradeRecords](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/trade_records.md)
|
||||
- [Result](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/result.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)
|
||||
- [Symbol](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/symbol.md)
|
||||
- [Strategy](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/stategy.md)
|
||||
- [Terminal](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/terminal.md)
|
||||
- [Tick](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/ticks.md)
|
||||
- [Ticks](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/ticks.md)
|
||||
- [Trader](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/trader.md)
|
||||
- [utils](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/utils.md)
|
||||
- [Errors](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/core/errors.md)
|
||||
- [Exceptions](https://github.com/Ichinga-Samuel/aiomql/blob/master/docs/core/exceptions.md)
|
||||
|
||||
- [Core](core)
|
||||
- [MetaTrader](core/meta_trader.md)
|
||||
- [Config](core/config.md)
|
||||
- [Base](core/base.md)
|
||||
- [Constants](core/constants.md)
|
||||
- [TaskQueue](core/task_queue.md)
|
||||
- [Models](core/models.md)
|
||||
- [Errors](core/errors.md)
|
||||
- [Exceptions](core/exceptions.md)
|
||||
- [MetaBackTester](core/meta_backtester.md)
|
||||
|
||||
- [BackTesting](core/backtesting)
|
||||
- [BackTestAccount](core/backtesting/backtest_account.md)
|
||||
- [BackTestEngine](core/backtesting/backtest_engine.md)
|
||||
- [GetData](core/backtesting/get_data.md)
|
||||
- [TradesManager](core/backtesting/trades_manager.md)
|
||||
- [BackTestController](core/backtesting/backtest_controller.md)
|
||||
|
||||
- [Lib](lib)
|
||||
- [Account](lib/account.md)
|
||||
- [Bot](lib/bot.md)
|
||||
- [Candle](lib/candle.md)
|
||||
- [Candles](lib/candle.md)
|
||||
- [History](lib/history.md)
|
||||
- [Order](lib/order.md)
|
||||
- [Positions](lib/positions.md)
|
||||
- [RAM](lib/ram.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)
|
||||
* [BackTestAccount](#backtest_account.BackTestAccount)
|
||||
* [get\_dict](#backtest_account.BackTestAccount.get_dict)
|
||||
* [asdict](#backtest_account.BackTestAccount.asdict)
|
||||
* [set\_attrs](#backtest_account.BackTestAccount.set_attrs)
|
||||
## Table of Contents
|
||||
- [BackTestAccount](#back_test_account.back_test_account)
|
||||
- [get_dict](#back_test_account.back_test_account.get_dict)
|
||||
- [asdict](#back_test_account.asdict)
|
||||
- [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
|
||||
@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
|
||||
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
|
||||
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
|
||||
def set_attrs(**kwargs)
|
||||
```
|
||||
|
||||
Se the attributes of the account data to the instance
|
||||
|
||||
Sets multiple attributes at once by passing key-value pairs as keyword arguments.
|
||||
|
||||
@@ -1,125 +1,104 @@
|
||||
# Table of Contents
|
||||
# BackTestController
|
||||
|
||||
* [backtest\_controller](#backtest_controller)
|
||||
* [BackTestController](#backtest_controller.BackTestController)
|
||||
* [backtest\_engine](#backtest_controller.BackTestController.backtest_engine)
|
||||
* [add\_tasks](#backtest_controller.BackTestController.add_tasks)
|
||||
* [set\_parties](#backtest_controller.BackTestController.set_parties)
|
||||
* [parties](#backtest_controller.BackTestController.parties)
|
||||
* [control](#backtest_controller.BackTestController.control)
|
||||
* [stop\_backtesting](#backtest_controller.BackTestController.stop_backtesting)
|
||||
* [wait](#backtest_controller.BackTestController.wait)
|
||||
* [abort](#backtest_controller.BackTestController.abort)
|
||||
## Table of Contents
|
||||
- [BackTestController](#backtest_controller.back_test_controller)
|
||||
- [backtest_engine](#backtest_controller.backtest_engine)
|
||||
- [add_tasks](#backtest_controller.add_tasks)
|
||||
- [set_parties](#backtest_controller.set_parties)
|
||||
- [parties](#backtest_controller.parties)
|
||||
- [control](#backtest_controller.control)
|
||||
- [stop_backtesting](#backtest_controller.stop_backtesting)
|
||||
- [wait](#backtest_controller.wait)
|
||||
- [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
|
||||
class BackTestController()
|
||||
class BackTestController
|
||||
```
|
||||
|
||||
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 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
|
||||
@property
|
||||
def 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
|
||||
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
|
||||
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.
|
||||
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
|
||||
|
||||
```python
|
||||
@property
|
||||
def parties()
|
||||
```
|
||||
|
||||
Returns the number of parties for the barrier
|
||||
|
||||
<a id="backtest_controller.BackTestController.control"></a>
|
||||
|
||||
<a id="backtest_controller.control"></a>
|
||||
#### control
|
||||
|
||||
```python
|
||||
async def control()
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
<a id="backtest_controller.BackTestController.stop_backtesting"></a>
|
||||
|
||||
#### stop\_backtesting
|
||||
|
||||
<a id="backtest_controller.stop_backtesting"></a>
|
||||
#### stop_backtesting
|
||||
```python
|
||||
def stop_backtesting()
|
||||
```
|
||||
|
||||
Stop the backtester, and shutdown the executor
|
||||
|
||||
<a id="backtest_controller.BackTestController.wait"></a>
|
||||
|
||||
<a id="backtest_controller.wait"></a>
|
||||
#### wait
|
||||
|
||||
```python
|
||||
def wait()
|
||||
```
|
||||
|
||||
Called by individual tasks to indicate completion of their cycle
|
||||
|
||||
<a id="backtest_controller.BackTestController.abort"></a>
|
||||
|
||||
<a id="backtest_controller.abort"></a>
|
||||
#### abort
|
||||
|
||||
```python
|
||||
def abort()
|
||||
```
|
||||
|
||||
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)
|
||||
* [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)
|
||||
## Table of Contents
|
||||
|
||||
<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
|
||||
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
|
||||
@dataclass
|
||||
class BackTestData()
|
||||
class BackTestData
|
||||
```
|
||||
|
||||
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
|
||||
def set_attrs(**kwargs)
|
||||
```
|
||||
|
||||
Set the attributes of the class on the instance.
|
||||
|
||||
<a id="get_data.BackTestData.fields"></a>
|
||||
|
||||
<a id="get_data.fields"></a>
|
||||
#### fields
|
||||
|
||||
```python
|
||||
@property
|
||||
def fields()
|
||||
```
|
||||
|
||||
A list of the fields of the class.
|
||||
|
||||
<a id="get_data.GetData"></a>
|
||||
|
||||
## GetData Objects
|
||||
|
||||
<a id="get_data.getdata"></a>
|
||||
### GetData
|
||||
```python
|
||||
class GetData()
|
||||
class GetData
|
||||
```
|
||||
|
||||
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
|
||||
def __init__(*,
|
||||
start: datetime,
|
||||
end: datetime,
|
||||
symbols: Sequence[str],
|
||||
timeframes: Sequence[TimeFrame],
|
||||
name: str = "")
|
||||
def __init__(*, start: datetime, end: datetime, symbols: Sequence[str],
|
||||
timeframes: Sequence[TimeFrame], name: str = "")
|
||||
```
|
||||
|
||||
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
|
||||
@classmethod
|
||||
def pickle_data(cls, *, data: BackTestData, name: str | Path)
|
||||
```
|
||||
|
||||
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
|
||||
@classmethod
|
||||
def load_data(cls, *, name: str | Path) -> BackTestData
|
||||
```
|
||||
|
||||
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
|
||||
def save_data(*, name: str | Path = "")
|
||||
```
|
||||
|
||||
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
|
||||
async def get_data(workers: int = None)
|
||||
```
|
||||
|
||||
Use the task queue to get the data from the MetaTrader5 terminal.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `workers` _int_ - The number of workers to use in the task queue. If not provided, the default number of workers
|
||||
is used.
|
||||
|
||||
#### Parameters:
|
||||
| Name | Type | Description |
|
||||
|-----------|-------|------------------------------------------------|
|
||||
| `workers` | `int` | The number of workers to use in the task queue |
|
||||
|
||||
@@ -1,410 +1,374 @@
|
||||
# Table of Contents
|
||||
# TradesManager
|
||||
|
||||
* [trades\_manager](#trades_manager)
|
||||
* [TradeManager](#trades_manager.TradeManager)
|
||||
* [update](#trades_manager.TradeManager.update)
|
||||
* [values](#trades_manager.TradeManager.values)
|
||||
* [keys](#trades_manager.TradeManager.keys)
|
||||
* [items](#trades_manager.TradeManager.items)
|
||||
* [to\_dict](#trades_manager.TradeManager.to_dict)
|
||||
* [PositionsManager](#trades_manager.PositionsManager)
|
||||
* [\_\_init\_\_](#trades_manager.PositionsManager.__init__)
|
||||
* [margin](#trades_manager.PositionsManager.margin)
|
||||
* [close](#trades_manager.PositionsManager.close)
|
||||
* [get\_margin](#trades_manager.PositionsManager.get_margin)
|
||||
* [delete\_margin](#trades_manager.PositionsManager.delete_margin)
|
||||
* [set\_margin](#trades_manager.PositionsManager.set_margin)
|
||||
* [positions\_get](#trades_manager.PositionsManager.positions_get)
|
||||
* [positions\_total](#trades_manager.PositionsManager.positions_total)
|
||||
* [open\_positions](#trades_manager.PositionsManager.open_positions)
|
||||
* [OrdersManager](#trades_manager.OrdersManager)
|
||||
* [get\_orders\_range](#trades_manager.OrdersManager.get_orders_range)
|
||||
* [history\_orders\_get](#trades_manager.OrdersManager.history_orders_get)
|
||||
* [history\_orders\_total](#trades_manager.OrdersManager.history_orders_total)
|
||||
* [DealsManager](#trades_manager.DealsManager)
|
||||
* [get\_deals\_range](#trades_manager.DealsManager.get_deals_range)
|
||||
* [history\_deals\_get](#trades_manager.DealsManager.history_deals_get)
|
||||
* [history\_deals\_total](#trades_manager.DealsManager.history_deals_total)
|
||||
## Table of Contents
|
||||
- [trades_manager](#trades_manager.trades_manager)
|
||||
- [TradesManager](#trades_manager.trades_manager)
|
||||
- [update](#trades_manager.trade_manager.update)
|
||||
- [values](#trades_manager.trade_manager.values)
|
||||
- [keys](#trades_manager.trade_manager.keys)
|
||||
- [items](#trades_manager.trade_manager.items)
|
||||
- [to_dict](#trades_manager.trade_manager.to_dict)
|
||||
- [PositionsManager](#trades_manager.positions_manager)
|
||||
- [\__init\__](#positions_manager.__init__)
|
||||
- [margin](#positions_manager.margin)
|
||||
- [close](#positions_manager.close)
|
||||
- [get_margin](#positions_manager.get_margin)
|
||||
- [delete_margin](#positions_manager.delete_margin)
|
||||
- [set_margin](#positions_manager.set_margin)
|
||||
- [positions_get](#positions_manager.positions_get)
|
||||
- [positions_total](#positions_manager.positions_total)
|
||||
- [open_positions](#positions_manager.open_positions)
|
||||
- [OrdersManager](#trades_manager.orders_manager)
|
||||
- [get_orders_range](#orders_manager.get_orders_range)
|
||||
- [history_orders_get](#orders_manager.history_orders_get)
|
||||
- [history_orders_total](#orders_manager.history_orders_total)
|
||||
- [DealsManager](#trades_manager.deals_manager)
|
||||
- [get_deals_range](#deals_manager.get_deals_range)
|
||||
- [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
|
||||
class TradeManager(Generic[TradeData])
|
||||
```
|
||||
|
||||
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.
|
||||
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:
|
||||
```python
|
||||
>>> manager = TradeManager()
|
||||
>>> manager[123456] = TradePosition(ticket=123456, symbol="EURUSD", volume=0.1)
|
||||
>>> manager.update(ticket=123456, symbol="EURUSD", volume=0.1)
|
||||
>>> manager[123456]
|
||||
TradePosition(ticket=123456, symbol='EURUSD', volume=0.1)
|
||||
>>> manager.values()
|
||||
(TradePosition(ticket=123456, symbol='EURUSD', volume=0.1),)
|
||||
>>> manager.keys()
|
||||
(123456,)
|
||||
>>> manager.items()
|
||||
((123456, TradePosition(ticket=123456, symbol='EURUSD', volume=0.1)),)
|
||||
>>> manager.to_dict()
|
||||
{'123456' - {'ticket': 123456, 'symbol': 'EURUSD', 'volume': 0.1}}
|
||||
>>> pos = manager.get(123456)
|
||||
>>> pos
|
||||
TradePosition(ticket=123456, symbol='EURUSD', volume=0.1)
|
||||
>>> pos in manager
|
||||
True
|
||||
>>> len(manager)
|
||||
1
|
||||
>>> pos in manager
|
||||
False
|
||||
```
|
||||
|
||||
|
||||
**Examples**:
|
||||
|
||||
>>> manager = TradeManager()
|
||||
>>> manager[123456] = TradePosition(ticket=123456, symbol="EURUSD", volume=0.1)
|
||||
>>> manager.update(ticket=123456, symbol="EURUSD", volume=0.1)
|
||||
>>> manager[123456]
|
||||
TradePosition(ticket=123456, symbol='EURUSD', volume=0.1)
|
||||
>>> manager.values()
|
||||
(TradePosition(ticket=123456, symbol='EURUSD', volume=0.1),)
|
||||
>>> manager.keys()
|
||||
(123456,)
|
||||
>>> manager.items()
|
||||
((123456, TradePosition(ticket=123456, symbol='EURUSD', volume=0.1)),)
|
||||
>>> manager.to_dict()
|
||||
- `{123456` - {'ticket': 123456, 'symbol': 'EURUSD', 'volume': 0.1}}
|
||||
>>> pos = manager.get(123456)
|
||||
>>> pos
|
||||
TradePosition(ticket=123456, symbol='EURUSD', volume=0.1)
|
||||
>>> pos in manager
|
||||
True
|
||||
>>> len(manager)
|
||||
1
|
||||
>>> pos in manager
|
||||
False
|
||||
|
||||
<a id="trades_manager.TradeManager.update"></a>
|
||||
|
||||
<a id="trades_manager.update"></a>
|
||||
#### update
|
||||
|
||||
```python
|
||||
def update(*, ticket: int, **kwargs)
|
||||
```
|
||||
|
||||
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
|
||||
def values() -> tuple[TradeData, ...]
|
||||
```
|
||||
|
||||
Returns the values of the data.
|
||||
|
||||
<a id="trades_manager.TradeManager.keys"></a>
|
||||
|
||||
#### keys
|
||||
|
||||
<a id="trades_manager.keys"></a>
|
||||
### keys
|
||||
```python
|
||||
def keys() -> tuple[int, ...]
|
||||
```
|
||||
|
||||
Returns the keys of the data.
|
||||
|
||||
<a id="trades_manager.TradeManager.items"></a>
|
||||
|
||||
#### items
|
||||
|
||||
<a id="trades_manager.items"></a>
|
||||
### items
|
||||
```python
|
||||
def items() -> tuple[tuple[int, TradeData], ...]
|
||||
```
|
||||
|
||||
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
|
||||
def to_dict()
|
||||
```
|
||||
|
||||
Convert the data to a dictionary.
|
||||
|
||||
<a id="trades_manager.PositionsManager"></a>
|
||||
|
||||
## PositionsManager Objects
|
||||
|
||||
<a id="trades_manager.positions_manager"></a>
|
||||
```python
|
||||
class PositionsManager(TradeManager)
|
||||
```
|
||||
|
||||
A class to manage the open positions during a backtest. It is a subclass of TradeManager. It has an additional
|
||||
A class to manage the open positions during a backtest. It is a subclass of It has an 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.
|
||||
|
||||
**Attributes**:
|
||||
|
||||
- `_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\_\_
|
||||
#### 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. |
|
||||
|
||||
|
||||
<a id="positions_manager.__init__"></a>
|
||||
#### \__init\__
|
||||
```python
|
||||
def __init__(*,
|
||||
data: dict = None,
|
||||
open_positions: set[int] = None,
|
||||
margins: dict = None)
|
||||
def __init__(*, 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 TradeManager. It has an
|
||||
Positions manager manages the open positions during a backtest. It is a subclass of It has an
|
||||
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.
|
||||
|
||||
**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
|
||||
@property
|
||||
def margin()
|
||||
```
|
||||
|
||||
Returns the total margin of all open positions
|
||||
|
||||
<a id="trades_manager.PositionsManager.close"></a>
|
||||
|
||||
#### close
|
||||
|
||||
<a id="positions_manager.close"></a>
|
||||
### close
|
||||
```python
|
||||
def close(*, ticket: int) -> bool
|
||||
```
|
||||
|
||||
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
|
||||
def get_margin(*, ticket: int) -> float
|
||||
```
|
||||
|
||||
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
|
||||
def delete_margin(*, ticket: int)
|
||||
```
|
||||
|
||||
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
|
||||
def set_margin(*, ticket: int, margin: float)
|
||||
```
|
||||
|
||||
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
|
||||
def positions_get(*,
|
||||
ticket: int = None,
|
||||
symbol: str = None,
|
||||
group: None = None) -> tuple[TradePosition, ...]
|
||||
def positions_get(*, ticket: int = None, symbol: str = None, group: None = None) -> tuple[TradePosition, ...]
|
||||
```
|
||||
|
||||
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.
|
||||
- `symbol` _str_ - The symbol of the position.
|
||||
- `group` _str_ - The group
|
||||
|
||||
#### Returns:
|
||||
| Type | Description |
|
||||
|------------------------|-----------------------------|
|
||||
| `tuple[TradePosition]` | The positions. |
|
||||
|
||||
**Returns**:
|
||||
#### Returns:
|
||||
| Type | Description |
|
||||
|-----------------------------|-----------------------------|
|
||||
| `tuple[TradePosition, ...]` | The positions. |
|
||||
|
||||
tuple[TradePosition, ...]: The positions
|
||||
|
||||
<a id="trades_manager.PositionsManager.positions_total"></a>
|
||||
|
||||
#### positions\_total
|
||||
|
||||
<a id="positions_manager.positions_total"></a>
|
||||
### positions_total
|
||||
```python
|
||||
def positions_total() -> int
|
||||
```
|
||||
|
||||
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
|
||||
@property
|
||||
def open_positions() -> tuple[TradePosition, ...]
|
||||
```
|
||||
|
||||
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
|
||||
class OrdersManager(TradeManager)
|
||||
```
|
||||
|
||||
Managers orders data during a backtest. It is a subclass of TradeManager. It manages access to the historical
|
||||
Managers orders data during a backtest. It is a subclass of It manages access to the historical
|
||||
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
|
||||
def get_orders_range(*, date_from: float,
|
||||
date_to: float) -> tuple[TradeData, ...]
|
||||
def get_orders_range(*, date_from: float, date_to: float) -> tuple[TradeData, ...]
|
||||
```
|
||||
|
||||
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.
|
||||
- `date_to` _float_ - The end date of the range.
|
||||
|
||||
#### Returns:
|
||||
| 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
|
||||
def history_orders_get(*,
|
||||
date_from: float | datetime = None,
|
||||
date_to: float | datetime = None,
|
||||
group: str = "",
|
||||
ticket: int = None,
|
||||
position: int = None) -> tuple[TradeOrder, ...]
|
||||
def history_orders_get(*, date_from: float | datetime = None, 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
|
||||
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.
|
||||
- `date_to` _float, datetime_ - 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.
|
||||
|
||||
#### Returns:
|
||||
| Type | Description |
|
||||
|---------------------|------------------------|
|
||||
| `tuple[TradeOrder]` | The historical orders. |
|
||||
|
||||
**Returns**:
|
||||
|
||||
tuple[TradeOrder, ...]: The historical orders.
|
||||
|
||||
<a id="trades_manager.OrdersManager.history_orders_total"></a>
|
||||
|
||||
#### history\_orders\_total
|
||||
|
||||
<a id="orders_manager.history_orders_total"></a>
|
||||
### history_orders_total
|
||||
```python
|
||||
def history_orders_total(*, date_from: datetime | float,
|
||||
date_to: datetime | float) -> int
|
||||
```
|
||||
|
||||
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
|
||||
class DealsManager(TradeManager)
|
||||
```
|
||||
|
||||
<a id="trades_manager.DealsManager.get_deals_range"></a>
|
||||
|
||||
#### get\_deals\_range
|
||||
|
||||
<a id="deals_manager.get_deals_range"></a>
|
||||
#### get_deals_range
|
||||
```python
|
||||
def get_deals_range(*, date_from: float,
|
||||
date_to: float) -> tuple[TradeData, ...]
|
||||
def get_deals_range(*, date_from: float, date_to: float) -> tuple[TradeData, ...]
|
||||
```
|
||||
|
||||
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.
|
||||
- `date_to` _float_ - The end date of the range.
|
||||
|
||||
#### Returns:
|
||||
| Type | Description |
|
||||
|--------------------|-----------------------------------|
|
||||
| `tuple[TradeData]` | The deals within the date range. |
|
||||
|
||||
**Returns**:
|
||||
|
||||
tuple[TradeData, ...]: The deals within the date range.
|
||||
|
||||
<a id="trades_manager.DealsManager.history_deals_get"></a>
|
||||
|
||||
#### history\_deals\_get
|
||||
|
||||
<a id="deals_manager.history_deals_get"></a>
|
||||
### history_deals_get
|
||||
```python
|
||||
def history_deals_get(*,
|
||||
date_from: float | datetime = None,
|
||||
@@ -413,35 +377,33 @@ def history_deals_get(*,
|
||||
ticket: int = None,
|
||||
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.
|
||||
|
||||
**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
|
||||
def history_deals_total(*, date_from: datetime | float,
|
||||
date_to: datetime | float) -> int
|
||||
```
|
||||
|
||||
Get the total number of historical deals. Given the start and end date of the range
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `date_from` _datetime, float_ - The start date of the range.
|
||||
- `date_to` _datetime, float_ - The end date of the range.
|
||||
|
||||
|
||||
**Returns**:
|
||||
|
||||
- `int` - The total number of historical deals.
|
||||
#### Parameters:
|
||||
| Name | Type | Description |
|
||||
|-------------|---------|------------------------------|
|
||||
| `date_from` | `float` | The start date of the range. |
|
||||
| `date_to` | `float` | The end date of the range. |
|
||||
|
||||
#### Returns:
|
||||
| Type | Description |
|
||||
|-------|---------------------------------------|
|
||||
| `int` | The total number of historical deals. |
|
||||
|
||||
+91
-52
@@ -1,72 +1,111 @@
|
||||
# Config
|
||||
|
||||
## Table of Contents
|
||||
- [Config](#config.Config)
|
||||
- [account\_info](#config.account_info)
|
||||
- [load\_config](#config.load_config)
|
||||
- [create\_records\_dir](#config.create_records_dir)
|
||||
- [Config](#config.config)
|
||||
- [account_info](#config.account_info)
|
||||
- [backtest_engine](#config.backtest_engine)
|
||||
- [set_attributes](#config.set_attributes)
|
||||
- [load_config](#config.load_config)
|
||||
|
||||
|
||||
<a id="config.Config"></a>
|
||||
<a id="config.config"></a>
|
||||
```python
|
||||
class Config
|
||||
```
|
||||
A class for handling configuration settings for the aiomql package. A single instance of this class is created and used
|
||||
per bot instance.
|
||||
### Class Attributes
|
||||
| Name | Type | Description | Default |
|
||||
|------------------|--------------|-----------------------------------------------------|-----------------------------------------------------|
|
||||
| `record\_trades` | `bool` | Whether to keep record of trades or not. | True |
|
||||
| `filename` | `str` | Name of the config file | aiomql.json |
|
||||
| `records\_dir` | `str\| Path` | Path to the directory where trade records are saved | Should be relative to the project root |
|
||||
| `login` | `str` | Trading account number | |
|
||||
| `password` | `str` | Trading account password | |
|
||||
| `server` | `str` | Broker server | |
|
||||
| `path` | `str\|Path` | Path to terminal file | Absolute |
|
||||
| `timeout` | `int` | Timeout for terminal connection | |
|
||||
| `config_dir` | `str` | Directory where the config file is located | Optional. Should be relative to the root directory |
|
||||
| `state` | `dict` | A global state object | |
|
||||
| `task_queue` | `Queue` | A global queue for handling tasks | |
|
||||
| `bot` | `Bot` | The bot instance | Added to the config object after bot initialization |
|
||||
| `root_dir` | `str` | Root directory of the project | |
|
||||
The global config object. It is a singleton class for handling configuration settings for the aiomql package.
|
||||
A single instance of this class is created and used per bot instance.
|
||||
|
||||
#### Attributes:
|
||||
| Name | Type | Description |
|
||||
|--------------------------------|-------------------------------|-------------------------------------------------------------------------|
|
||||
| `login` | `int` | The account login number |
|
||||
| `trade_record_mode` | `Literal["csv", "json"]` | The mode for recording trades |
|
||||
| `password` | `str` | The account password |
|
||||
| `server` | `str` | The account server |
|
||||
| `path` | `str \| Path` | The path to the terminal |
|
||||
| `timeout` | `int` | The timeout argument for the terminal |
|
||||
| `filename` | `str` | The filename of the config file |
|
||||
| `state` | `dict` | The state of the configuration |
|
||||
| `root` | `Path` | The root directory of the project |
|
||||
| `record_trades` | `bool` | To record trades or not. Default is True |
|
||||
| `records_dir` | `Path` | The directory to store trade records, relative to the root directory |
|
||||
| `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>
|
||||
### account\_info
|
||||
### account_info
|
||||
```python
|
||||
def account_info() -> dict['login', 'password', 'server']
|
||||
```
|
||||
Returns Account login details as found in the config object if available
|
||||
#### Returns
|
||||
| Type | Description |
|
||||
|--------|-------------------------------------------------------|
|
||||
| `dict` | A dictionary with login, password, and server details |
|
||||
|
||||
#### Returns:
|
||||
| Type | Description |
|
||||
|---------------------------------------|-------------------------------------------------------|
|
||||
| `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>
|
||||
### load\_config
|
||||
### load_config
|
||||
```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.
|
||||
#### 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 |
|
||||
Load configuration settings from a file and reset the config object.
|
||||
|
||||
<a id="config.create_records_dir"></a>
|
||||
### create_records_dir
|
||||
```python
|
||||
def create_records_dir(self, *, records_dir: str | Path = 'records'):
|
||||
```
|
||||
Create a directory for saving trade records.
|
||||
#### Parameters
|
||||
| Name | Type | Description |
|
||||
|----------------|-------------|-------------------------------------------------------------------|
|
||||
| `records\_dir` | `str\|Path` | The directory where trade records are saved. Default is 'records' |
|
||||
#### Parameters:
|
||||
| Name | Type | Description |
|
||||
|------------|---------------|----------------------------------------------------------------------------------------------------|
|
||||
| `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. |
|
||||
| `root` | `str` | The root directory of the project. |
|
||||
| `**kwargs` | `dict` | Additional keyword arguments to be set on the config object. |
|
||||
|
||||
+31
-28
@@ -9,8 +9,9 @@ MetaTrader 5 constants defined as Enums.
|
||||
- [opposite](#ordertype.opposite)
|
||||
- [BookType](#BookType)
|
||||
- [TimeFrame](#TimeFrame)
|
||||
- [time](#timeframe.time)
|
||||
- [get](#timeframe.get)
|
||||
- [get_timeframe](#timeframe.get_timeframe)
|
||||
- [seconds](#timeframe.seconds)
|
||||
- [all](#timeframe.all)
|
||||
- [CopyTicks](#CopyTicks)
|
||||
- [PositionType](#PositionType)
|
||||
- [PositionReason](#PositionReason)
|
||||
@@ -156,41 +157,43 @@ TIMEFRAME Enum.
|
||||
| `W1` | 604800 | One Week |
|
||||
| `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>
|
||||
### time
|
||||
<a id="timeframe.seconds"></a>
|
||||
### seconds
|
||||
```python
|
||||
@property
|
||||
def time()
|
||||
def seconds() -> int
|
||||
```
|
||||
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
|
||||
t = TimeFrame.H1
|
||||
print(t.seconds) # 3600
|
||||
@property
|
||||
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>
|
||||
## CopyTicks
|
||||
|
||||
+17
-13
@@ -1,21 +1,24 @@
|
||||
# Errors
|
||||
|
||||
## Tabel of contents
|
||||
- [Error](#errors.Error)
|
||||
- [Error](#errors.error)
|
||||
- [is_connection_error](#errors.is_connection_error)
|
||||
|
||||
<a id="errors.Error"></a>
|
||||
|
||||
<a id="errors.error"></a>
|
||||
## Error
|
||||
```python
|
||||
class Error()
|
||||
class Error
|
||||
```
|
||||
Error class for handling errors from MetaTrader 5.
|
||||
#### Attributes
|
||||
| Name | Type | Description |
|
||||
|----------------|--------|----------------------------------------------|
|
||||
| `code` | `int` | Error code |
|
||||
| `description` | `str` | Error description |
|
||||
| `descriptions` | `dict` | A dictionary of error codes and descriptions |
|
||||
Error class for handling errors.
|
||||
|
||||
#### Attributes:
|
||||
| Name | Type | Description |
|
||||
|----------------|--------------|----------------------------------------------|
|
||||
| `code` | `int` | Error code |
|
||||
| `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>
|
||||
@@ -23,8 +26,9 @@ Error class for handling errors from MetaTrader 5.
|
||||
```python
|
||||
def is_connection_error(self) -> bool
|
||||
```
|
||||
Check if error is a connection error.
|
||||
#### Returns
|
||||
Check if an error is a connection error.
|
||||
|
||||
#### Returns:
|
||||
| Type | Description |
|
||||
|--------|------------------------------------------------------|
|
||||
| `bool` | True if error is a connection error, False otherwise |
|
||||
| `bool` | True if error is a connection error, False otherwise |
|
||||
|
||||
+21
-9
@@ -2,36 +2,48 @@
|
||||
Exceptions for the aiomql package.
|
||||
|
||||
## Table of Contents
|
||||
- [LoginError](#exceptions.LoginError)
|
||||
- [VolumeError](#exceptions.VolumeError)
|
||||
- [SymbolError](#exceptions.SymbolError)
|
||||
- [OrderError](#exceptions.OrderError)
|
||||
- [LoginError](#exceptions.login_error)
|
||||
- [VolumeError](#exceptions.volume_error)
|
||||
- [SymbolError](#exceptions.symbol_error)
|
||||
- [OrderError](#exceptions.order_error)
|
||||
- [StopTradingError](#exceptions.stop_trading_error)
|
||||
|
||||
|
||||
<a id="exceptions.LoginError"></a>
|
||||
<a id="exceptions.login_error"></a>
|
||||
### LoginError
|
||||
```python
|
||||
class LoginError(Exception)
|
||||
```
|
||||
Raised when an error occurs when logging in.
|
||||
|
||||
<a id="exceptions.VolumeError"></a>
|
||||
|
||||
<a id="exceptions.volume_error"></a>
|
||||
### VolumeError
|
||||
```python
|
||||
class VolumeError(Exception)
|
||||
```
|
||||
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
|
||||
```python
|
||||
class SymbolError(Exception)
|
||||
```
|
||||
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
|
||||
```python
|
||||
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
|
||||
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
|
||||
- [AccountInfo](#AccountInfo)
|
||||
- [TerminalInfo](#TerminalInfo)
|
||||
- [SymbolInfo](#SymbolInfo)
|
||||
- [BookInfo](#BookInfo)
|
||||
- [TradeOrder](#TradeOrder)
|
||||
- [TradeRequest](#TradeRequest)
|
||||
- [OrderCheckResult](#OrderCheckResult)
|
||||
- [OrderSendResult](#OrderSendResult)
|
||||
- [TradePosition](#TradePosition)
|
||||
- [TradeDeal](#TradeDeal)
|
||||
- [AccountInfo](#models.account_info)
|
||||
- [TerminalInfo](#models.terminal_info)
|
||||
- [SymbolInfo](#models.symbol.info)
|
||||
- [BookInfo](#models.book_info)
|
||||
- [TradeOrder](#models.trade_order)
|
||||
- [TradeRequest](#models_trade_request)
|
||||
- [OrderCheckResult](#models.order_check_result)
|
||||
- [OrderSendResult](#models.order_send_result)
|
||||
- [TradePosition](#models.trade_position)
|
||||
- [TradeDeal](#models.trade_deal)
|
||||
|
||||
<a id="AccountInfo"></a>
|
||||
## AccountInfo
|
||||
|
||||
<a id="models.account_info"></a>
|
||||
### AccountInfo
|
||||
```python
|
||||
class AccountInfo(Base)
|
||||
```
|
||||
Account Information Class.
|
||||
#### Attributes
|
||||
| Name | Type | Description | Default |
|
||||
|----------------------|--------------------|------------------------------------------|---------|
|
||||
| `login` | `int` | Account number | |
|
||||
| `password` | `str` | Account password | |
|
||||
| `server` | `str` | Trade server name | |
|
||||
| `trade_mode` | AccountTradeMode | Trade mode | |
|
||||
| `balance` | `float` | Account balance | |
|
||||
| `leverage` | `float` | Account leverage | |
|
||||
| `profit` | `float` | Account profit | |
|
||||
| `point` | `float` | Point size | |
|
||||
| `amount` | `float` | Account amount | 0 |
|
||||
| `equity` | `float` | Account equity | |
|
||||
| `credit` | `float` | Account credit | |
|
||||
| `margin` | `float` | Account margin | |
|
||||
| `margin_level` | `float` | Margin level | |
|
||||
| `margin_free` | `float` | Free margin | |
|
||||
| `margin_mode` | AccountMarginMode | Margin calculation mode | |
|
||||
| `margin_so_mode` | AccountStopoutMode | Stop out mode | |
|
||||
| `margin_so_call` | `float` | Margin call level | |
|
||||
| `margin_so_so` | `float` | Stop out level | |
|
||||
| `margin_initial` | `float` | Initial margin | |
|
||||
| `margin_maintenance` | `float` | Maintenance margin | |
|
||||
| `fifo_close` | `bool` | FIFO close flag | |
|
||||
| `limit_orders` | `float` | Limit orders | |
|
||||
| `currency` | `str` | Account currency | "USD" |
|
||||
| `trade_allowed` | `bool` | Trade allowed flag | True |
|
||||
| `trade_expert` | `bool` | Trade expert flag | True |
|
||||
| `currency_digits` | `int` | Number of digits after the decimal point | |
|
||||
| `assets` | `float` | Assets | |
|
||||
| `liabilities` | `float` | Liabilities | |
|
||||
| `commission_blocked` | `float` | Blocked commission | |
|
||||
| `name` | `str` | Account name | |
|
||||
| `company` | `str` | Company name | |
|
||||
#### Attributes:
|
||||
| Name | Type | Description | Default |
|
||||
|----------------------|----------------------|------------------------------------------|---------|
|
||||
| `login` | `int` | Account number | |
|
||||
| `password` | `str` | Account password | |
|
||||
| `server` | `str` | Trade server name | |
|
||||
| `trade_mode` | AccountTradeMode | Trade mode | |
|
||||
| `balance` | `float` | Account balance | |
|
||||
| `leverage` | `float` | Account leverage | |
|
||||
| `profit` | `float` | Account profit | |
|
||||
| `point` | `float` | Point size | |
|
||||
| `amount` | `float` | Account amount | 0 |
|
||||
| `equity` | `float` | Account equity | |
|
||||
| `credit` | `float` | Account credit | |
|
||||
| `margin` | `float` | Account margin | |
|
||||
| `margin_level` | `float` | Margin level | |
|
||||
| `margin_free` | `float` | Free margin | |
|
||||
| `margin_mode` | `AccountMarginMode` | Margin calculation mode | |
|
||||
| `margin_so_mode` | `AccountStopoutMode` | Stop out mode | |
|
||||
| `margin_so_call` | `float` | Margin call level | |
|
||||
| `margin_so_so` | `float` | Stop out level | |
|
||||
| `margin_initial` | `float` | Initial margin | |
|
||||
| `margin_maintenance` | `float` | Maintenance margin | |
|
||||
| `fifo_close` | `bool` | FIFO close flag | |
|
||||
| `limit_orders` | `float` | Limit orders | |
|
||||
| `currency` | `str` | Account currency | "USD" |
|
||||
| `trade_allowed` | `bool` | Trade allowed flag | True |
|
||||
| `trade_expert` | `bool` | Trade expert flag | True |
|
||||
| `currency_digits` | `int` | Number of digits after the decimal point | |
|
||||
| `assets` | `float` | Assets | |
|
||||
| `liabilities` | `float` | Liabilities | |
|
||||
| `commission_blocked` | `float` | Blocked commission | |
|
||||
| `name` | `str` | Account name | |
|
||||
| `company` | `str` | Company name | |
|
||||
|
||||
<a id="TerminalInfo"></a>
|
||||
## TerminalInfo
|
||||
|
||||
<a id="models.terminal_info"></a>
|
||||
### TerminalInfo
|
||||
```python
|
||||
class TerminalInfo(Base)
|
||||
```
|
||||
Terminal information class. Holds information about the terminal.
|
||||
|
||||
#### Attributes
|
||||
#### Attributes:
|
||||
| Name | Type | Description | Default |
|
||||
|-------------------------|---------|----------------------------|---------|
|
||||
| `community_account` | `bool` | Community account flag | |
|
||||
@@ -88,13 +91,14 @@ Terminal information class. Holds information about the terminal.
|
||||
| `data_path` | `str` | Data path | |
|
||||
| `commondata_path` | `str` | Common data path | |
|
||||
|
||||
<a id="SymbolInfo"></a>
|
||||
## SymbolInfo
|
||||
|
||||
<a id="models.symbol_info"></a>
|
||||
### SymbolInfo
|
||||
```python
|
||||
class SymbolInfo(Base)
|
||||
```
|
||||
Symbol Information Class. Symbols are financial instruments available for trading in the MetaTrader 5 terminal.
|
||||
#### Attributes
|
||||
#### Attributes:
|
||||
| Name | Type | Description | Default |
|
||||
|------------------------------|------------------------|----------------------------|---------|
|
||||
| `name` | `str` | Symbol name | |
|
||||
@@ -195,13 +199,14 @@ Symbol Information Class. Symbols are financial instruments available for tradin
|
||||
| `page` | `str` | Page | |
|
||||
| `path` | `str` | Path | |
|
||||
|
||||
<a id="BookInfo"></a>
|
||||
## BookInfo
|
||||
|
||||
<a id="models.book_info"></a>
|
||||
### BookInfo
|
||||
```python
|
||||
class BookInfo(Base)
|
||||
```
|
||||
Book Information Class.
|
||||
#### Attributes
|
||||
#### Attributes:
|
||||
| Name | Type | Description | Default |
|
||||
|--------------|------------|-------------|---------|
|
||||
| `symbol` | `str` | Symbol | |
|
||||
@@ -210,13 +215,15 @@ Book Information Class.
|
||||
| `volume` | `float` | Volume | |
|
||||
| `volume_dbl` | `float` | Volume dbl | |
|
||||
|
||||
<a id="TradeOrder"></a>
|
||||
## TradeOrder
|
||||
|
||||
<a id="models.trade_order"></a>
|
||||
#### TradeOrder
|
||||
```python
|
||||
class TradeOrder(Base)
|
||||
```
|
||||
Trade Order Class.
|
||||
#### Attributes
|
||||
|
||||
#### Attributes:
|
||||
| Name | Type | Description | Default |
|
||||
|-------------------|----------------|-----------------|---------|
|
||||
| `ticket` | `int` | Ticket | |
|
||||
@@ -244,13 +251,14 @@ Trade Order Class.
|
||||
| `comment` | `str` | Comment | |
|
||||
| `external_id` | `str` | External id | |
|
||||
|
||||
<a id="TradeRequest"></a>
|
||||
|
||||
<a id="models.trade_request"></a>
|
||||
## TradeRequest
|
||||
```python
|
||||
class TradeRequest(Base)
|
||||
```
|
||||
Trade Request Class.
|
||||
#### Attributes
|
||||
#### Attributes:
|
||||
| Name | Type | Description | Default |
|
||||
|----------------|--------------|--------------|---------|
|
||||
| `action` | TradeAction | Action | |
|
||||
@@ -272,13 +280,14 @@ Trade Request Class.
|
||||
| `magic` | `int` | Magic | |
|
||||
| `deviation` | `int` | Deviation | |
|
||||
|
||||
<a id="OrderCheckResult"></a>
|
||||
## OrderCheckResult
|
||||
|
||||
<a id="models.order_check_result"></a>
|
||||
### OrderCheckResult
|
||||
```python
|
||||
class OrderCheckResult(Base)
|
||||
```
|
||||
Order Check Result
|
||||
#### Attributes
|
||||
#### Attributes:
|
||||
| Name | Type | Description | Default |
|
||||
|----------------|----------------|--------------|---------|
|
||||
| `retcode` | `int` | Retcode | |
|
||||
@@ -291,14 +300,15 @@ Order Check Result
|
||||
| `comment` | `str` | Comment | |
|
||||
| `request` | `TradeRequest` | Request | |
|
||||
|
||||
<a id="OrderSendResult"></a>
|
||||
## OrderSendResult
|
||||
|
||||
<a id="models.order_send_result"></a>
|
||||
### OrderSendResult
|
||||
```python
|
||||
class OrderSendResult(Base)
|
||||
```
|
||||
Order Send Result
|
||||
|
||||
#### Attributes
|
||||
#### Attributes:
|
||||
| Name | Type | Description | Default |
|
||||
|--------------------|----------------|------------------|---------|
|
||||
| `retcode` | `int` | Retcode | |
|
||||
@@ -314,13 +324,14 @@ Order Send Result
|
||||
| `retcode_external` | `int` | Retcode external | |
|
||||
| `profit` | `float` | Profit | |
|
||||
|
||||
<a id="TradePosition"></a>
|
||||
## TradePosition
|
||||
|
||||
<a id="models.trade_position"></a>
|
||||
### TradePosition
|
||||
```python
|
||||
class TradePosition(Base)
|
||||
```
|
||||
Trade Position
|
||||
#### Attributes
|
||||
#### Attributes:
|
||||
| Name | Type | Description | Default |
|
||||
|-------------------|------------------|-----------------|---------|
|
||||
| `ticket` | `int` | Ticket | |
|
||||
@@ -343,13 +354,14 @@ Trade Position
|
||||
| `comment` | `str` | Comment | |
|
||||
| `external_id` | `str` | External id | |
|
||||
|
||||
<a id="TradeDeal"></a>
|
||||
## TradeDeal
|
||||
|
||||
<a id="models.trade_deal"></a>
|
||||
### TradeDeal
|
||||
```python
|
||||
class TradeDeal(Base)
|
||||
```
|
||||
Trade Deal
|
||||
#### Attributes
|
||||
#### Attributes:
|
||||
| Name | Type | Description | Default |
|
||||
|---------------|--------------|-------------|---------|
|
||||
| `ticket` | `int` | Ticket | |
|
||||
|
||||
+4
-3
@@ -1,11 +1,11 @@
|
||||
# Account
|
||||
|
||||
## Table of Contents
|
||||
- [Account](#account.Account)
|
||||
- [Account](#account.account)
|
||||
- [refresh](#account.refresh)
|
||||
|
||||
|
||||
<a id="account.Account"></a>
|
||||
<a id="account.account"></a>
|
||||
### Account
|
||||
```python
|
||||
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
|
||||
management protocol.
|
||||
|
||||
#### Attributes
|
||||
#### Attributes:
|
||||
| Name | Type | Description | Default |
|
||||
|-------------|-------------------|------------------------------------------------------|---------|
|
||||
| `connected` | `bool` | Status of connection to MetaTrader 5 Terminal | False |
|
||||
|
||||
|
||||
<a id="account.refresh"></a>
|
||||
### refresh
|
||||
```python
|
||||
|
||||
+14
-6
@@ -1,7 +1,7 @@
|
||||
# Bot
|
||||
|
||||
## Table of Contents
|
||||
- [Bot](#bot.Bot)
|
||||
- [Bot](#bot.bot)
|
||||
- [\_\_init\_\_](#bot.init)
|
||||
- [initialize](#bot.initialize)
|
||||
- [execute](#bot.execute)
|
||||
@@ -13,14 +13,14 @@
|
||||
- [add_strategy_all](#bot.add_strategy_all)
|
||||
- [process_pool](#bot.run_bots)
|
||||
|
||||
<a id='bot.Bot'></a>
|
||||
<a id='bot.bot'></a>
|
||||
### Bot
|
||||
```python
|
||||
class Bot
|
||||
```
|
||||
"""The bot class. Create a bot instance to run strategies.
|
||||
|
||||
#### Attributes.
|
||||
#### Attributes:
|
||||
| Name | Type | Description | Default |
|
||||
|--------------|--------------------|--------------------------------------------|--------------|
|
||||
| `account` | `Account` | Account Object. | None |
|
||||
@@ -30,12 +30,13 @@ class Bot
|
||||
| `config` | `Config` | A Config instance | Config() |
|
||||
|
||||
<a id='bot.init'></a>
|
||||
### \_\_init\_\_
|
||||
### \__init\__
|
||||
```python
|
||||
def __init__()
|
||||
```
|
||||
Initializes the Bot class.
|
||||
|
||||
|
||||
<a id='bot.initialize'></a>
|
||||
### initialize
|
||||
```python
|
||||
@@ -52,7 +53,6 @@ Note: *initialize_sync* is a synchronous version of this method.
|
||||
| `SystemExit` | If sign in was not successful |
|
||||
|
||||
|
||||
|
||||
<a id='bot.execute'></a>
|
||||
### execute
|
||||
```python
|
||||
@@ -61,6 +61,7 @@ def execute()
|
||||
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.
|
||||
|
||||
|
||||
<a id='bot.start'></a>
|
||||
### start
|
||||
```python
|
||||
@@ -68,13 +69,14 @@ async def start()
|
||||
```
|
||||
Initialize the bot and execute it. Similar to calling **execute** method but is asynchronous.
|
||||
|
||||
|
||||
<a id='bot.add_coroutine'></a>
|
||||
### add_coroutine
|
||||
```python
|
||||
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,
|
||||
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:
|
||||
| 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 |
|
||||
| `kwargs` | `Any` | Keyword arguments to pass to the coroutine |
|
||||
|
||||
|
||||
<a id='bot.add_function'></a>
|
||||
### add_function
|
||||
```python
|
||||
@@ -95,6 +98,7 @@ Add a function to the executor.
|
||||
| `function` | `Callable` | A function to run in the executor |
|
||||
| `kwargs` | `Any` | Keyword arguments to pass to the function |
|
||||
|
||||
|
||||
<a id='bot.add_strategy'></a>
|
||||
### add_strategy
|
||||
```python
|
||||
@@ -107,23 +111,27 @@ Add a strategy to the list of strategies.
|
||||
|------------|------------|-----------------------------------|
|
||||
| `strategy` | `Strategy` | A Strategy instance to run on bot |
|
||||
|
||||
|
||||
<a id='bot.add_strategies'></a>
|
||||
### add_strategies
|
||||
```python
|
||||
def add_strategies(strategies: Iterable[Strategy])
|
||||
```
|
||||
Add multiple strategies at the same time
|
||||
|
||||
#### Parameters:
|
||||
| Name | Type | Description |
|
||||
|--------------|----------------------|-----------------------------------|
|
||||
| `strategies` | `Iterable[Strategy]` | An iterable of Strategy instances |
|
||||
|
||||
|
||||
<a id='bot.add_strategy_all'></a>
|
||||
### add_strategy_all
|
||||
```python
|
||||
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.
|
||||
|
||||
#### Parameters:
|
||||
| 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 datetime import datetime, UTC
|
||||
from logging import getLogger
|
||||
from typing import Sequence, NamedTuple
|
||||
from typing import NamedTuple, Iterable
|
||||
|
||||
import MetaTrader5
|
||||
from numpy import ndarray
|
||||
@@ -95,8 +95,8 @@ class GetData:
|
||||
"""
|
||||
data: BackTestData
|
||||
|
||||
def __init__(self, *, start: datetime, end: datetime, symbols: Sequence[str],
|
||||
timeframes: Sequence[TimeFrame], name: str = ""):
|
||||
def __init__(self, *, start: datetime, end: datetime, symbols: Iterable[str],
|
||||
timeframes: Iterable[TimeFrame], name: str = ""):
|
||||
"""
|
||||
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
|
||||
|
||||
Notes:
|
||||
By default, the config class looks for a file named aiomql.json.
|
||||
You can change this by passing the filename and/or the config_dir keyword argument(s) to the constructor
|
||||
or the load_config method.
|
||||
By passing reload=True to the load_config method, you can reload and search again for the config file.
|
||||
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.
|
||||
"""
|
||||
login: int
|
||||
trade_record_mode: Literal["csv", "json"]
|
||||
@@ -113,13 +115,13 @@ class Config:
|
||||
self._backtest_engine = value
|
||||
|
||||
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:
|
||||
**kwargs: Object attributes and values as keyword arguments
|
||||
"""
|
||||
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()]
|
||||
|
||||
@staticmethod
|
||||
@@ -149,7 +151,7 @@ class Config:
|
||||
return
|
||||
|
||||
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:
|
||||
file (str | Path): The absolute path to the config file.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Error:
|
||||
"""Error class for handling errors from MetaTrader 5."""
|
||||
"""Error class for handling errors"""
|
||||
|
||||
descriptions = {
|
||||
# common errors
|
||||
|
||||
Reference in New Issue
Block a user