Skip to content

BaseDataExchange

QuantConnect.Lean.Engine.DataFeeds.BaseDataExchange

BaseDataExchange(name: str)

Bases: Object

Provides a means of distributing output from enumerators from a dedicated separate thread

Initializes a new instance of the BaseDataExchange

Parameters:

Name Type Description Default
name str

A name for this exchange

required

sleep_interval

sleep_interval: int

Gets or sets how long this thread will sleep when no data is available

name

name: str

Gets a name for this exchange

EnumeratorHandler

EnumeratorHandler(
    symbol: Union[Symbol, str, BaseContract],
    enumerator: IEnumerator[BaseData],
    should_move_next: Callable[[], bool] = None,
    handle_data: Callable[[BaseData], Any] = None,
)

Bases: Object

Handler used to manage a single enumerator's move next/end of stream behavior

Initializes a new instance of the EnumeratorHandler class

Parameters:

Name Type Description Default
symbol Union[Symbol, str, BaseContract]

The symbol to identify this enumerator

required
enumerator IEnumerator[BaseData]

The enumeator this handler handles

required
should_move_next Callable[[], bool]

Predicate function used to determine if we should call move next on the symbol's enumerator

None
handle_data Callable[[BaseData], Any]

Handler for data if HandlesData=true

None

enumerator_finished

enumerator_finished: _EventContainer[
    Callable[[Object, EnumeratorHandler], Any], Any
]

Event fired when MoveNext returns false

symbol

symbol: Symbol

A unique symbol used to identify this enumerator

enumerator

enumerator: IEnumerator[BaseData]

The enumerator this handler handles

handle_data

handle_data(data: BaseData) -> None

Handles the specified data.

Parameters:

Name Type Description Default
data BaseData

The data to be handled

required

on_enumerator_finished

on_enumerator_finished() -> None

Event invocator for the enumerator_finished event

should_move_next

should_move_next() -> bool

Returns true if this enumerator should move next

add_enumerator

add_enumerator(handler: EnumeratorHandler) -> None
add_enumerator(
    symbol: Union[Symbol, str, BaseContract],
    enumerator: IEnumerator[BaseData],
    should_move_next: Callable[[], bool] = None,
    enumerator_finished: Callable[
        [EnumeratorHandler], Any
    ] = None,
    handle_data: Callable[[BaseData], Any] = None,
) -> None

Adds the enumerator to this exchange. If it has already been added then it will remain registered in the exchange only once

Parameters:

Name Type Description Default
handler Optional[EnumeratorHandler]

The handler to use when this symbol's data is encountered

None
symbol Optional[Union[Symbol, str, BaseContract]]

A unique symbol used to identify this enumerator

None
enumerator Optional[IEnumerator[BaseData]]

The enumerator to be added

None
should_move_next Optional[Callable[[], bool]]

Function used to determine if move next should be called on this

None
enumerator_finished Optional[Callable[[EnumeratorHandler], Any]]

Delegate called when the enumerator move next returns false

None
handle_data Optional[Callable[[BaseData], Any]]

Handler for data if HandlesData=true

None

remove_enumerator

remove_enumerator(
    symbol: Union[Symbol, str, BaseContract],
) -> EnumeratorHandler

Removes and returns enumerator handler with the specified symbol. The removed handler is returned, null if not found

set_error_handler

set_error_handler(
    is_fatal_error: Callable[[Exception], bool],
) -> None

Sets the specified function as the error handler. This function returns true if it is a fatal error and queue consumption should cease.

Parameters:

Name Type Description Default
is_fatal_error Callable[[Exception], bool]

The error handling function to use when an error is encountered during queue consumption. Returns true if queue consumption should be stopped, returns false if queue consumption should continue

required

start

start() -> None

Begins consumption of the wrapped IDataQueueHandler on a separate thread

stop

stop() -> None

Ends consumption of the wrapped IDataQueueHandler