self.get_position#
- lumibot.strategies.strategy.Strategy.get_position(self, asset: str | Asset)
Get a tracked position given an asset for the current strategy.
Seeks out and returns the position object for the given asset in the current strategy. For continuous futures (CONT_FUTURE), automatically matches against active contract positions.
- Parameters:
asset (Asset or str) – Asset object who’s traded positions is sought.
- Returns:
A position object for the assset if there is a tracked position or returns None to indicate no tracked position. For continuous futures, returns the position for the most appropriate active contract (front-month priority).
- Return type:
Position or None
Example
>>> # Get the position for the TLT asset >>> position = self.get_position("TLT") >>> # Show the quantity of the TLT position >>> self.log_message(position.quantity)
>>> # Get position for continuous futures (matches active contract) >>> future_asset = Asset("MNQ", asset_type=Asset.AssetType.CONT_FUTURE) >>> position = self.get_position(future_asset) # Returns MNQU5 position if held