Files
aiomql/docs/lib/positions.md
T
Ichinga Samuel f56d0c85b3 v4
2024-11-10 12:25:50 +01:00

4.6 KiB

Positions

Table of contents

Positions

class Positions

Get and handle Open positions.

Attributes

Name Type Description
positions tuple[TradePosition, ...] Financial instrument name.
mt5 MetaTrader MetaTrader instance.

__init__

def __init__()

Initialize a position instance

get_positions

async def get_positions(self) -> tuple[TradePosition, ...]:

Get open positions

Returns

Type Description
tuple[TradePosition, ...] A list of open trade positions

get_position_by_ticket

async def get_position_by_ticket(self, *, ticket: int) -> TradePosition

Get a position by ticket id.

Parameters:

Name Type Description
ticket int Position ticket

Returns:

Type Description
TradePosition Trade position

get_positions_by_symbol

async def get_positions_by_symbol(self, *, symbol: str) -> tuple[TradePosition, ...]

Filter positions by symbols

Parameters:

Name Type Description
symbol str Symbol

Returns:

Type Description
tuple[TradePosition, ...] Trade position

close

async def close(self, *, ticket: int, symbol: str, price: float, volume: float, order_type: OrderType) -> OrderSendResult:

Close a position using its details.

Parameters:

Name Type Description
ticket int Position ticket.
symbol str Financial instrument name.
price float Closing price.
volume float Volume to close.
order_type OrderType Order type.

Returns:

Type Description
OrderSendResult The result of the order sent to close the position

close_position

async def close_position(self, *, position: TradePosition) -> OrderSendResult:

Close a position by position object.

Parameters:

Name Type Description
position TradePosition Position object

Returns:

Type Description
OrderSendResult The result of the order sent to close the position

close_position_by_ticket

async def close_position_by_ticket(self, *, position: TradePosition) -> OrderSendResult:

Close a position by position object.

Parameters:

Name Type Description
position TradePosition Position object

Returns:

Type Description
OrderSendResult The result of the order sent to close the position

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