Skip to content

PositionCollection

QuantConnect.Securities.Positions.PositionCollection

PositionCollection(
    positions: Dictionary[Symbol, IPosition],
)
PositionCollection(positions: List[IPosition])

Bases: Object, Iterable[IPosition]

Provides a collection type for IPosition aimed at providing indexing for common operations required by the resolver implementations.

Initializes a new instance of the PositionCollection class

Parameters:

Name Type Description Default
positions Dictionary[Symbol, IPosition] | List[IPosition]

The positions to include in this collection

required

count

count: int

Gets the number of elements in the collection.

__iter__

__iter__() -> Iterator[IPosition]

clear

clear() -> None

Clears this collection of all positions

get_enumerator

get_enumerator() -> IEnumerator[IPosition]

Returns an enumerator that iterates through the collection.

Returns:

Type Description
IEnumerator[IPosition]

An enumerator that can be used to iterate through the collection.

remove

remove(groups: List[IPositionGroup]) -> None

Removes the quantities in the provided groups from this position collection. This should be called following IPositionGroupResolver has resolved position groups in order to update the collection of positions for the next resolver, if one exists.

Parameters:

Name Type Description Default
groups List[IPositionGroup]

The resolved position groups

required

try_get_position

try_get_position(
    symbol: Union[Symbol, str, BaseContract],
    position: Optional[IPosition],
) -> Tuple[bool, IPosition]

Attempts to retrieve the position with the specified symbol from this collection

Parameters:

Name Type Description Default
symbol Union[Symbol, str, BaseContract]

The symbol

required
position Optional[IPosition]

The position

required

Returns:

Type Description
Tuple[bool, IPosition]

True if the position is found, otherwise false.