Skip to content

PythonConsolidator

QuantConnect.Python.PythonConsolidator

PythonConsolidator()
PythonConsolidator(window_size: int)

Bases: WindowBase[IBaseData], IDataConsolidator

Provides a base class for python consolidators, necessary to use event handler. Inherits the built-in rolling window so custom Python consolidators can access their consolidated history through the indexer, Current, Previous and Window members.

Signature descriptions:

  • Initializes a new instance of the WindowBase{T} class.

  • Initializes the rolling window with the given size.

consolidated

consolidated: IBaseData

Gets the most recently consolidated piece of data. This will be null if this consolidator has not produced any data yet.

working_data

working_data: IBaseData

Gets a clone of the data being currently consolidated

input_type

input_type: Type

Gets the type consumed by this consolidator

output_type

output_type: Type

Gets the type produced by this consolidator

data_consolidated

data_consolidated: _EventContainer[
    Callable[[Object, IBaseData], Any], Any
]

Event handler that fires when a new piece of data is produced

DEFAULT_WINDOW_SIZE

DEFAULT_WINDOW_SIZE: int

The default number of values to keep in the rolling window history

window

window: RollingWindow[QuantConnect_Indicators_WindowBase_T]

A rolling window keeping a history of values. The most recent value is at index 0. Uses lazy initialization to support Python subclasses that do not call base constructors.

current

current: QuantConnect_Indicators_WindowBase_T

Gets the most recent value. The protected setter adds the value to the rolling window.

previous

previous: QuantConnect_Indicators_WindowBase_T

Gets the previous value, or default if fewer than two values have been produced.

dispose

dispose() -> None

on_data_consolidated

on_data_consolidated(
    consolidator: Any, data: IBaseData
) -> None

Function to invoke the event handler

Parameters:

Name Type Description Default
consolidator Any

Reference to the consolidator itself

required
data IBaseData

The finished data from the consolidator

required

reset

reset() -> None

Resets the consolidator

scan

scan(current_local_time: Union[datetime, date]) -> None

Scans this consolidator to see if it should emit a bar due to time passing

Parameters:

Name Type Description Default
current_local_time Union[datetime, date]

The current time in the local time zone (same as BaseData.time)

required

update

update(data: IBaseData) -> None

Updates this consolidator with the specified data

Parameters:

Name Type Description Default
data IBaseData

The new data for the consolidator

required

__getitem__

__getitem__(i: int) -> QuantConnect_Indicators_WindowBase_T

Indexes the history window, where index 0 is the most recent value.

Parameters:

Name Type Description Default
i int

The index

required

Returns:

Type Description
QuantConnect_Indicators_WindowBase_T

The ith most recent value.

__iter__

__iter__() -> (
    Iterator[QuantConnect_Indicators_WindowBase_T]
)

get_enumerator

get_enumerator() -> (
    IEnumerator[QuantConnect_Indicators_WindowBase_T]
)

Returns an enumerator that iterates through the history window.

reset_window

reset_window() -> None

Resets the rolling window, clearing all stored values.

This Class is protected.