This commit is contained in:
Ichinga Samuel
2024-11-15 21:13:19 +01:00
parent 2a55f49f78
commit 2e7aa73aec
19 changed files with 1400 additions and 1415 deletions
+34 -37
View File
@@ -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.
+39 -60
View File
@@ -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
+93 -116
View File
@@ -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 |
+231 -269
View File
@@ -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. |