self.get_positions

lumibot.strategies.strategy.Strategy.get_positions(self, include_cash_positions: bool = False, broker_refresh: bool = True, broker_refresh_ttl_seconds: float = 0.0, *, max_age: float | None = None)

Get all positions for the account.

Parameters:
  • include_cash_positions (bool) – If True, include cash positions in the returned list. If False, exclude cash positions.

  • max_age (float, optional) – Live: 0 always reads the broker, even inside broker_refresh_ttl_seconds; a positive value accepts a read that many seconds old. The default (broker_refresh_ttl_seconds=0) is already a fresh read.

Returns:

A list of Position objects for the strategy if there are tracked positions or returns and empty list to indicate no tracked position.

Return type:

list

Example

>>> # Get all tracked positions
>>> positions = self.get_positions()
>>> for position in positions:
>>>     # Show the quantity of each position
>>>     self.log_message(position.quantity)
>>>     # Show the asset of each position
>>>     self.log_message(position.asset)