Skip to content

BacktestingRealTimeHandler

QuantConnect.Lean.Engine.RealTime.BacktestingRealTimeHandler

Bases: BaseRealTimeHandler

Pseudo realtime event processing for backtesting to simulate realtime events in fast forward.

is_active

is_active: bool

Flag indicating the hander thread is completely finished and ready to dispose. this doesn't run as its own thread

scheduled_events

scheduled_events: ConcurrentDictionary[ScheduledEvent, int]

The scheduled events container

This codeEntityType is protected.

isolator_limit_provider

isolator_limit_provider: IIsolatorLimitResultProvider

The isolator limit result provider instance

This codeEntityType is protected.

algorithm

algorithm: IAlgorithm

The algorithm instance

This codeEntityType is protected.

time_monitor

time_monitor: TimeMonitor

The time monitor instance to use

This codeEntityType is protected.

add

add(scheduled_event: ScheduledEvent) -> None

Adds the specified event to the schedule

Parameters:

Name Type Description Default
scheduled_event ScheduledEvent

The event to be scheduled, including the date/times the event fires and the callback

required

remove

remove(scheduled_event: ScheduledEvent) -> None

Removes the specified event from the schedule

Parameters:

Name Type Description Default
scheduled_event ScheduledEvent

The event to be removed

required

scan_past_events

scan_past_events(time: Union[datetime, date]) -> None

Scan for past events that didn't fire because there was no data at the scheduled time.

Parameters:

Name Type Description Default
time Union[datetime, date]

Current time.

required

set_time

set_time(time: Union[datetime, date]) -> None

Set the time for the realtime event handler.

Parameters:

Name Type Description Default
time Union[datetime, date]

Current time.

required

setup

setup(
    algorithm: IAlgorithm,
    job: AlgorithmNodePacket,
    result_handler: IResultHandler,
    api: IApi,
    isolator_limit_provider: IIsolatorLimitResultProvider,
) -> None

Initializes the real time handler for the specified algorithm and job

sort_first_element

sort_first_element(
    scheduled_events: List[ScheduledEvent],
) -> None

Sorts the first element of the provided list and supposes the rest of the collection is sorted. Supposes the collection has at least 1 element

exit

exit() -> None

Stop the real time thread

on_securities_changed

on_securities_changed(changes: SecurityChanges) -> None

Event fired each time that we add/remove securities from the data feed

get_scheduled_event_unique_id

get_scheduled_event_unique_id() -> int

Gets a new scheduled event unique id

This codeEntityType is protected.

get_time_monitor_timeout

get_time_monitor_timeout() -> int

Get's the timeout the scheduled task time monitor should use

This codeEntityType is protected.