TradesManager
Table of Contents
TradesManager
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.
Parameters:
| Name |
Type |
Description |
_data |
dict[int, TradeData] |
The data to store the trades |
Examples:
update
Update the data of a trade. Given the ticket of the trade and the new data to update.
Parameters:
| Name |
Type |
Description |
ticket |
int |
The ticket of the trade to update. |
**kwargs |
|
The new data to update. |
values
Returns the values of the data.
keys
Returns the keys of the data.
items
Returns the items of the data.
to_dict
Convert the data to a dictionary.
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:
| 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. |
_init_
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.
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. |
margin
Returns the total margin of all open positions
close
Close a position. Given the ticket of the position to close.
Parameters:
| Name |
Type |
Description |
ticket |
int |
The ticket of the position to close. |
get_margin
Get the margin of a position. Given the ticket of the position.
Parameters:
| Name |
Type |
Description |
ticket |
int |
The ticket of the position. |
Returns:
| Type |
Description |
float |
The margin of the position. |
delete_margin
Delete the margin of a position. Given the ticket of the position.
Parameters:
| Name |
Type |
Description |
ticket |
int |
The ticket of the position. |
set_margin
Set the margin of a position. Given the ticket of the position and the margin.
Parameters:
| Name |
Type |
Description |
ticket |
int |
The ticket of the position. |
margin |
float |
The margin of the position. |
positions_get
Get positions. Given the ticket, symbol, or group of the positions.
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. |
Returns:
| Type |
Description |
tuple[TradePosition] |
The positions. |
Returns:
| Type |
Description |
tuple[TradePosition, ...] |
The positions. |
positions_total
Get the total number of open positions.
Returns:
| Type |
Description |
int |
The total number of open positions. |
open_positions
Returns the open positions.
Parameters:
| Name |
Type |
Description |
ticket |
int |
The ticket of the position. |
OrdersManager
Managers orders data during a backtest. It is a subclass of It manages access to the historical
orders data
get_orders_range
Get orders within a date range. Given the start and end date of the range.
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 |
tuple[TradeData] |
The orders within the date range. |
Returns:
| Type |
Description |
tuple[TradeData] |
The orders within the date range. |
history_orders_get
Get historical orders. Given the start and end date of the range, the group, ticket, or position of the
orders.
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. |
Returns:
| Type |
Description |
tuple[TradeOrder] |
The historical orders. |
history_orders_total
Get the total number of historical orders. Given the start and end date of the range.
Parameters:
| Name |
Type |
Description |
date_from |
float |
The start date of the range. |
date_to |
float |
The end date of the range. |
DealsManager
get_deals_range
Get deals within a date range. Given the start and end date of the range.
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 |
tuple[TradeData] |
The deals within the date range. |
history_deals_get
History deals get. Given the start and end date of the range, the group, ticket, or position of the deals.
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. |
history_deals_total
Get the total number of historical deals. Given the start and end date of the range
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. |