Skip to content

UniverseManager

QuantConnect.Securities.UniverseManager

UniverseManager()

Bases: BaseExtendedDictionary[Symbol, Universe, ConcurrentDictionary[Symbol, Universe]]

Manages the algorithm's collection of universes

Initializes a new instance of the UniverseManager class

collection_changed

collection_changed: _EventContainer[
    Callable[[Object, UniverseManagerChanged], Any], Any
]

Event fired when a universe is added or removed

active_securities

Read-only dictionary containing all active securities. An active security is a security that is currently selected by the universe or has holdings or open orders.

count

count: int

Gets the number of elements contained in the dictionary

get_keys

get_keys: Iterable[
    QuantConnect_Util_BaseExtendedDictionary_TKey
]

Gets a collection containing the keys in the dictionary

This Property is protected.

get_values

get_values: Iterable[
    QuantConnect_Util_BaseExtendedDictionary_TValue
]

Gets a collection containing the values in the dictionary

This Property is protected.

is_read_only

is_read_only: bool

Gets a value indicating whether the dictionary is read-only

dictionary

dictionary: (
    QuantConnect_Util_BaseExtendedDictionary_TDictionary
)

The dictionary instance

This Property is protected.

__getitem__

__getitem__(
    symbol: Union[Symbol, str, BaseContract, Security],
) -> Universe
__getitem__(
    key: Union[Symbol, str, BaseContract, Security],
) -> Universe

Signature descriptions:

  • Gets or sets the element with the specified key

  • Gets or sets the value associated with the specified key

Parameters:

Name Type Description Default
key Optional[Union[Symbol, str, BaseContract, Security]]

The key of the value to get or set

None

Returns:

Type Description
Universe

The value associated with the specified key.

__setitem__

__setitem__(
    symbol: Union[Symbol, str, BaseContract, Security],
    value: Universe,
) -> None
__setitem__(
    key: Union[Symbol, str, BaseContract, Security],
    value: Universe,
) -> None

Signature descriptions:

  • Gets or sets the element with the specified key

  • Gets or sets the value associated with the specified key

Parameters:

Name Type Description Default
key Optional[Union[Symbol, str, BaseContract, Security]]

The key of the value to get or set

None

Returns:

Type Description
Optional[None]

The value associated with the specified key.

__contains__

__contains__(
    key: Union[Symbol, str, BaseContract, Security],
) -> bool

Determines whether the dictionary contains the specified key

Parameters:

Name Type Description Default
key Union[Symbol, str, BaseContract, Security]

The key to locate in the dictionary

required

Returns:

Type Description
bool

true if the dictionary contains an element with the specified key; otherwise, false.

add

add(
    key: Union[Symbol, str, BaseContract, Security],
    value: Universe,
) -> None

Adds an element with the provided key and value to the dictionary

contains_key

contains_key(
    key: Union[Symbol, str, BaseContract, Security],
) -> bool

Determines whether the dictionary contains the specified key

Parameters:

Name Type Description Default
key Union[Symbol, str, BaseContract, Security]

The key to locate in the dictionary

required

Returns:

Type Description
bool

true if the dictionary contains an element with the specified key; otherwise, false.

on_collection_changed

on_collection_changed(e: UniverseManagerChanged) -> None

Event invocator for the collection_changed event

This Class is protected.

process_changes

process_changes() -> None

Will trigger collection changed event if required

remove

remove(
    key: Union[Symbol, str, BaseContract, Security],
) -> bool

Removes the element with the specified key from the dictionary

try_get_value

try_get_value(
    key: Union[Symbol, str, BaseContract, Security],
    value: Optional[Universe],
) -> Tuple[bool, Universe]

Gets the value associated with the specified key

Parameters:

Name Type Description Default
key Union[Symbol, str, BaseContract, Security]

The key whose value to get

required
value Optional[Universe]

When this method returns, the value associated with the specified key

required

Returns:

Type Description
Tuple[bool, Universe]

true if the key was found; otherwise, false.

update

update(
    key: Union[Symbol, str, BaseContract, Security],
    value: Universe,
    action: NotifyCollectionChangedAction,
) -> None

Updates an element with the provided key and value to the dictionary

fromkeys

fromkeys(
    sequence: List[QuantConnect_ExtendedDictionary_TKey],
) -> Dict[
    QuantConnect_ExtendedDictionary_TKey,
    QuantConnect_ExtendedDictionary_TValue,
]
fromkeys(
    sequence: List[QuantConnect_ExtendedDictionary_TKey],
    value: QuantConnect_ExtendedDictionary_TValue,
) -> Dict[
    QuantConnect_ExtendedDictionary_TKey,
    QuantConnect_ExtendedDictionary_TValue,
]

Signature descriptions:

  • Creates a new dictionary from the given sequence of elements.

  • Creates a new dictionary from the given sequence of elements with a value provided by the user.

Parameters:

Name Type Description Default
sequence List[QuantConnect_ExtendedDictionary_TKey]

Sequence of elements which is to be used as keys for the new dictionary

required
value Optional[QuantConnect_ExtendedDictionary_TValue]

Value which is set to each element of the dictionary

None

Returns:

Type Description
Dict[QuantConnect_ExtendedDictionary_TKey, QuantConnect_ExtendedDictionary_TValue]

Returns a new dictionary with the given sequence of elements as the keys of the dictionary.

get

get(
    key: QuantConnect_ExtendedDictionary_TKey,
) -> QuantConnect_ExtendedDictionary_TValue
get(
    key: QuantConnect_ExtendedDictionary_TKey,
    default_value: QuantConnect_ExtendedDictionary_TValue,
) -> QuantConnect_ExtendedDictionary_TValue

Returns the value for the specified key if key is in dictionary.

Parameters:

Name Type Description Default
key QuantConnect_ExtendedDictionary_TKey

key to be searched in the dictionary

required
default_value Optional[QuantConnect_ExtendedDictionary_TValue]

Value to be returned if the key is not found or if the key is None.

None

Returns:

Type Description
QuantConnect_ExtendedDictionary_TValue

The value for the specified key if key is in dictionary.

pop

pop(
    key: QuantConnect_ExtendedDictionary_TKey,
) -> QuantConnect_ExtendedDictionary_TValue
pop(
    key: QuantConnect_ExtendedDictionary_TKey,
    default_value: QuantConnect_ExtendedDictionary_TValue,
) -> QuantConnect_ExtendedDictionary_TValue

Removes and returns an element from a dictionary having the given key.

Parameters:

Name Type Description Default
key QuantConnect_ExtendedDictionary_TKey

Key which is to be searched for removal

required
default_value Optional[QuantConnect_ExtendedDictionary_TValue]

Value which is to be returned when the key is not in the dictionary

None

Returns:

Type Description
QuantConnect_ExtendedDictionary_TValue

If key is found - removed/popped element from the dictionary

setdefault

setdefault(
    key: QuantConnect_ExtendedDictionary_TKey,
) -> QuantConnect_ExtendedDictionary_TValue
setdefault(
    key: QuantConnect_ExtendedDictionary_TKey,
    default_value: QuantConnect_ExtendedDictionary_TValue,
) -> QuantConnect_ExtendedDictionary_TValue

Returns the value of a key (if the key is in dictionary). If not, it inserts key with a value to the dictionary.

Parameters:

Name Type Description Default
key QuantConnect_ExtendedDictionary_TKey

Key with null/None value is inserted to the dictionary if key is not in the dictionary.

required
default_value Optional[QuantConnect_ExtendedDictionary_TValue]

Default value

None

Returns:

Type Description
QuantConnect_ExtendedDictionary_TValue

The value of the key if it is in the dictionary

clear

clear() -> None

Removes all items from the dictionary

copy

copy() -> Dict[
    QuantConnect_ExtendedDictionary_TKey,
    QuantConnect_ExtendedDictionary_TValue,
]

Creates a shallow copy of the IExtendedDictionary{TKey, TValue}.

Returns:

Type Description
Dict[QuantConnect_ExtendedDictionary_TKey, QuantConnect_ExtendedDictionary_TValue]

Returns a shallow copy of the dictionary. It doesn't modify the original dictionary.

items

items() -> List[
    Tuple[
        QuantConnect_ExtendedDictionary_TKey,
        QuantConnect_ExtendedDictionary_TValue,
    ]
]

Returns a view object that displays a list of dictionary's (key, value) tuple pairs.

Returns:

Type Description
List[Tuple[QuantConnect_ExtendedDictionary_TKey, QuantConnect_ExtendedDictionary_TValue]]

Returns a view object that displays a list of a given dictionary's (key, value) tuple pair.

keys

keys() -> List[QuantConnect_ExtendedDictionary_TKey]

Returns a view object that displays a list of all the key objects in the dictionary

Returns:

Type Description
List[QuantConnect_ExtendedDictionary_TKey]

Returns a view object that displays a list of all the key objects. When the dictionary is changed, the view object also reflect these changes.

popitem

popitem() -> Tuple[
    QuantConnect_ExtendedDictionary_TKey,
    QuantConnect_ExtendedDictionary_TValue,
]

Returns and removes an arbitrary element (key, value) pair from the dictionary.

Returns:

Type Description
Tuple[QuantConnect_ExtendedDictionary_TKey, QuantConnect_ExtendedDictionary_TValue]

Returns an arbitrary element (key, value) pair from the dictionary removes an arbitrary element(the same element which is returned) from the dictionary. Note: Arbitrary elements and random elements are not same.The popitem() doesn't return a random element.

values

values() -> List[QuantConnect_ExtendedDictionary_TValue]

Returns a view object that displays a list of all the values in the dictionary.

Returns:

Type Description
List[QuantConnect_ExtendedDictionary_TValue]

Returns a view object that displays a list of all values in a given dictionary.

__len__

__len__() -> int

check_for_implicitly_created_symbol

check_for_implicitly_created_symbol(
    symbol: Union[Symbol, str, BaseContract, Security],
) -> None

Checks if the symbol is implicitly created from a string, in which case it is not in the symbol cache, and throws a KeyNotFoundException.

This Class is protected.

get_items

get_items() -> Sequence[
    KeyValuePair[
        QuantConnect_Util_BaseExtendedDictionary_TKey,
        QuantConnect_Util_BaseExtendedDictionary_TValue,
    ]
]

Gets all the items in the dictionary

Returns:

Type Description
Sequence[KeyValuePair[QuantConnect_Util_BaseExtendedDictionary_TKey, QuantConnect_Util_BaseExtendedDictionary_TValue]]

All the items in the dictionary.

__iter__

__iter__() -> Iterator[
    KeyValuePair[
        QuantConnect_Util_BaseExtendedDictionary_TKey,
        QuantConnect_Util_BaseExtendedDictionary_TValue,
    ]
]

contains

contains(
    item: KeyValuePair[
        QuantConnect_Util_BaseExtendedDictionary_TKey,
        QuantConnect_Util_BaseExtendedDictionary_TValue,
    ],
) -> bool

Determines whether the dictionary contains a specific key-value pair

Parameters:

Name Type Description Default
item KeyValuePair[QuantConnect_Util_BaseExtendedDictionary_TKey, QuantConnect_Util_BaseExtendedDictionary_TValue]

The key-value pair to locate

required

Returns:

Type Description
bool

true if the key-value pair was found; otherwise, false.

copy_to

copy_to(
    array: List[
        KeyValuePair[
            QuantConnect_Util_BaseExtendedDictionary_TKey,
            QuantConnect_Util_BaseExtendedDictionary_TValue,
        ]
    ],
    array_index: int,
) -> None

Copies the elements of the dictionary to an array, starting at a particular array index

Parameters:

Name Type Description Default
array List[KeyValuePair[QuantConnect_Util_BaseExtendedDictionary_TKey, QuantConnect_Util_BaseExtendedDictionary_TValue]]

The array to copy to

required
array_index int

The starting index in the array

required

get_enumerator

get_enumerator() -> IEnumerator[
    KeyValuePair[
        QuantConnect_Util_BaseExtendedDictionary_TKey,
        QuantConnect_Util_BaseExtendedDictionary_TValue,
    ]
]

Returns an enumerator that iterates through the dictionary

Returns:

Type Description
IEnumerator[KeyValuePair[QuantConnect_Util_BaseExtendedDictionary_TKey, QuantConnect_Util_BaseExtendedDictionary_TValue]]

An enumerator for the dictionary.