2024-02-12 21:09:28 +01:00
# Positions
2023-10-11 09:49:06 +01:00
2024-02-12 21:09:28 +01:00
## Table of contents
- [Positions ](#positions )
- [Attributes ](#attributes )
- [\_\_init\_\_ ](#__init__ )
- [positions_total ](#positions_total )
2024-05-05 00:08:57 +01:00
- [position_get ](#position_get )
2024-02-12 21:09:28 +01:00
- [positions_get ](#positions_get )
- [close ](#close )
- [close_by ](#close_by )
2024-05-05 00:08:57 +01:00
- [close_position ](#close_position )
2024-02-12 21:09:28 +01:00
- [close_all ](#close_all )
<a id="positions"></a>
### Positions
2023-10-11 09:49:06 +01:00
```python
class Positions
```
Get and handle Open positions.
2024-02-12 21:09:28 +01:00
#### Attributes
| Name | Type | Description | Default |
|----------|--------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|
| `symbol` | `str` | Financial instrument name. | "" |
| `group` | `str` | The filter for arranging a group of necessary symbols. Optional named parameter. If the group is specified, the function returns only positions meeting a specified criteria for a symbol name. | "" |
| `ticket` | `int` | Position ticket. | 0 |
| `mt5` | `MetaTrader` | MetaTrader instance. | None |
2023-10-11 09:49:06 +01:00
2024-02-12 21:09:28 +01:00
<a id="__init__"></a>
### \_\_init\_\_
2023-10-11 09:49:06 +01:00
```python
def __init__ ( * , symbol : str = "" , group : str = "" , ticket : int = 0 )
```
Get Open Positions.
2024-02-12 21:09:28 +01:00
#### Arguments
| Name | Type | Description | Default |
|----------|-------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|
| `symbol` | `str` | Financial instrument name. | "" |
| `group` | `str` | The filter for arranging a group of symbols. Optional named parameter. If the group is specified, the function returns only positions meeting a specified criteria for a symbol name. | "" |
| `ticket` | `int` | Position ticket. | 0 |
2023-10-11 09:49:06 +01:00
2024-02-12 21:09:28 +01:00
<a id="positions_total"></a>
### positions_total
2023-10-11 09:49:06 +01:00
```python
async def positions_total () -> int
```
Get the number of open positions.
2024-02-12 21:09:28 +01:00
#### Returns
| Type | Description |
|-------|---------------------------------------|
| `int` | Return total number of open positions |
2023-10-11 09:49:06 +01:00
2024-02-12 21:09:28 +01:00
<a id="positions_get"></a>
### positions_get
2023-10-11 09:49:06 +01:00
```python
2024-02-12 21:09:28 +01:00
async def positions_get ( self , symbol : str = '' , group : str = '' , ticket : int = 0 , retries = 3 ) -> list [ TradePosition ]:
2023-10-11 09:49:06 +01:00
```
Get open positions with the ability to filter by symbol or ticket.
2024-02-12 21:09:28 +01:00
#### Arguments
| Name | Type | Description | Default |
|----------|--------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|
| `symbol` | `str` | Financial instrument name. | "" |
| `group` | `str` | The filter for arranging a group of symbols. Optional named parameter. If the group is specified, the function returns only positions meeting a specified criteria for a symbol name. | "" |
| `ticket` | `int` | Position ticket. | 0 |
2023-10-11 09:49:06 +01:00
2024-02-12 21:09:28 +01:00
#### Returns
| Type | Description |
|-----------------------|--------------------------------|
| `list[TradePosition]` | A list of open trade positions |
2023-10-11 09:49:06 +01:00
2024-05-05 00:08:57 +01:00
<a id="position_get"></a>
### position_get
```python
async def position_get ( self , * , ticket : int ) -> TradePosition
```
Get a position by ticket number.
#### Arguments
| Name | Type | Description |
|----------|-------|-----------------|
| `ticket` | `int` | Position ticket |
#### Returns
| Type | Description |
|-----------------|----------------|
| `TradePosition` | Trade position |
2023-10-11 09:49:06 +01:00
2024-02-12 21:09:28 +01:00
<a id="close"></a>
### close
```python
async def close ( self , * , ticket : int , symbol : str , price : float , volume : float , order_type : OrderType ):
```
Close a position by ticket number.
#### Arguments
| Name | Type | Description | Default |
|--------------|-------------|----------------------------|---------|
| `ticket` | `int` | Position ticket. | |
| `symbol` | `str` | Financial instrument name. | |
| `price` | `float` | Closing price. | |
| `volume` | `float` | Volume to close. | |
| `order_type` | `OrderType` | Order type. | |
2023-10-11 09:49:06 +01:00
2024-02-12 21:09:28 +01:00
<a id="close_by"></a>
### close_by
```python
async def close_by ( self , pos : TradePosition ):
```
2024-05-05 00:08:57 +01:00
2024-02-12 21:09:28 +01:00
Close a position by position object.
#### Arguments
| Name | Type | Description |
|-------|-----------------|-----------------|
| `pos` | `TradePosition` | Position object |
2023-10-11 09:49:06 +01:00
2024-05-05 00:08:57 +01:00
<a id='close_position'></a>
### close_position
```python
async def close_position ( self , * , position : TradePosition ):
```
Close a position by position object.
#### Arguments
| Name | Type | Description |
|------------|-----------------|-----------------|
| `position` | `TradePosition` | Position object |
2024-02-12 21:09:28 +01:00
<a id="close_all"></a>
### close_all
2023-10-11 09:49:06 +01:00
```python
async def close_all () -> int
```
Close all open positions for the trading account.
2024-02-12 21:09:28 +01:00
#### Returns
| Type | Description |
|-------|--------------------------------------|
| `int` | Return total number of closed trades |