Skip to content

LiveTradingRealTimeHandler

QuantConnect.Lean.Engine.RealTime.LiveTradingRealTimeHandler

Bases: BacktestingRealTimeHandler

Live trading realtime event processing.

market_hours_database

market_hours_database: MarketHoursDatabase

Gets the current market hours database instance

This codeEntityType is protected.

symbol_properties_database

symbol_properties_database: SymbolPropertiesDatabase

Gets the current symbol properties database instance

This codeEntityType is protected.

time_provider

time_provider: ITimeProvider

Gets the time provider

This codeEntityType is protected.

is_active

is_active: bool

Boolean flag indicating thread state.

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.

exit

exit() -> None

Stop the real time thread

get_time_monitor_timeout

get_time_monitor_timeout() -> int

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

This codeEntityType is protected.

reset_market_hours_database

reset_market_hours_database() -> None

Resets the market hours database, forcing a reload when reused. Called in tests where multiple algorithms are run sequentially, and we need to guarantee that every test starts with the same environment.

This codeEntityType is protected.

reset_symbol_properties_database

reset_symbol_properties_database() -> None

Resets the symbol properties database, forcing a reload when reused.

This codeEntityType is protected.

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 current time. If the date changes re-start the realtime event setup routines.

Parameters:

Name Type Description Default
time Union[datetime, date]
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

wait_till_next_second

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

Helper method to wait until the second passes, useful to testing

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

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.

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