Files
Ichinga Samuel 4f0150a552 v3.23
2024-10-29 13:04:45 +01:00

6.7 KiB

Positions

Table of contents

Positions

class Positions

Get and handle Open positions.

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

__init__

def __init__(*, symbol: str = "", group: str = "", ticket: int = 0)

Get Open Positions.

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

positions_total

async def positions_total() -> int

Get the number of open positions.

Returns

Type Description
int Return total number of open positions

positions_get

async def positions_get(self, symbol: str = '', group: str = '', ticket: int = 0, retries=3) -> list[TradePosition]:

Get open positions with the ability to filter by symbol or ticket.

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

Returns

Type Description
list[TradePosition] A list of open trade positions

position_get

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

close

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.

close_by

async def close_by(self, pos: TradePosition):

Close a position by position object.

Arguments

Name Type Description
pos TradePosition Position object

close_position

async def close_position(self, *, position: TradePosition):

Close a position by position object.

Arguments

Name Type Description
position TradePosition Position object

close_all

async def close_all() -> int

Close all open positions for the trading account.

Returns

Type Description
int Return total number of closed trades