Skip to content

MarketHourAwareConsolidator

QuantConnect.Data.Consolidators.MarketHourAwareConsolidator

MarketHourAwareConsolidator(
    daily_strict_end_time_enabled: bool,
    resolution: Resolution,
    data_type: Type,
    tick_type: TickType,
    extended_market_hours: bool,
)
MarketHourAwareConsolidator(
    daily_strict_end_time_enabled: bool,
    period: timedelta,
    data_type: Type,
    tick_type: TickType,
    extended_market_hours: bool,
)

Bases: ConsolidatorBase

Consolidator for open markets bar only, extended hours bar are not consolidated.

Signature descriptions:

  • Initializes a new instance of the MarketHourAwareConsolidator class.

  • Initializes a new instance of the MarketHourAwareConsolidator class for an arbitrary period. Intraday periods are anchored to the market open without extending past the close.

Parameters:

Name Type Description Default
resolution Optional[Resolution]

The resolution.

None
data_type Type

The target data type

required
tick_type TickType

The target tick type

required
extended_market_hours bool

True if extended market hours should be consolidated

required
daily_strict_end_time_enabled bool

True if daily strict end times should be enabled

required
period Optional[timedelta]

The consolidation period

None

period

period: timedelta

The consolidation period requested

This Property is protected.

consolidator

consolidator: IDataConsolidator

The consolidator instance

This Property is protected.

exchange_hours

exchange_hours: SecurityExchangeHours

The associated security exchange hours instance

This Property is protected.

data_time_zone

data_time_zone: Any

The associated data time zone

This Property is protected.

input_type

input_type: Type

Gets the type consumed by this consolidator

working_data

working_data: IBaseData

Gets a clone of the data being currently consolidated

output_type

output_type: Type

Gets the type produced by this consolidator

consolidated

consolidated: IBaseData

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

data_consolidated

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

Event handler that fires when a new piece of data is produced. This is the single subscription point, shared by the IDataConsolidator interface and by derived consolidators whose output is a base data bar, so subscribing and unsubscribing always target the same handler list.

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.

create_consolidator

create_consolidator(
    resolution: Resolution,
    data_type: Type,
    tick_type: TickType,
) -> IDataConsolidator
create_consolidator(
    calendar: Callable[[datetime], CalendarInfo],
    data_type: Type,
    tick_type: TickType,
) -> IDataConsolidator

Signature descriptions:

  • Creates the inner consolidator that produces the requested data_type output.

  • Creates the underlying calendar based consolidator for the given data type, used for arbitrary periods

daily_strict_end_time

daily_strict_end_time(
    date_time: Union[datetime, date],
) -> CalendarInfo

Determines a bar start time and period

This Class is protected.

dispose

dispose() -> None

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

forward_consolidated_bar

forward_consolidated_bar(
    sender: Any, consolidated: IBaseData
) -> None

Will forward the underlying consolidated bar to consumers on this object. This wrapper keeps its own rolling window in addition to the inner consolidator's window.

This Class is protected.

initialize

initialize(data: IBaseData) -> None

Perform late initialization based on the datas symbol

This Class is protected.

intraday_calendar

intraday_calendar(
    date_time: Union[datetime, date],
) -> CalendarInfo

Determines a bar start time and period for intraday consolidation, anchored to the market open without extending past the market close so a bar never spans across closed market hours

This Class is protected.

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 QuantConnect.Data.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

use_strict_end_time

use_strict_end_time(
    symbol: Union[Symbol, str, BaseContract, Security],
) -> bool

Useful for testing

This Class is protected.

__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.

fire_data_consolidated

fire_data_consolidated(consolidated: IBaseData) -> None

Raises the strongly typed DataConsolidated event exposed by derived consolidators that produce a more specific bar type. Invoked after the rolling window is populated and before the shared event so every handler sees the same window. Consolidators whose output is a base data bar do not need to override this, the shared data_consolidated event already carries their bar.

This Class is protected.

Parameters:

Name Type Description Default
consolidated IBaseData

The newly consolidated data

required

on_data_consolidated

on_data_consolidated(consolidated: IBaseData) -> None

Event invocator for the DataConsolidated event. Populates the rolling window, raises the strongly typed and interface events, and finally updates the consolidated property.

This Class is protected.