Skip to content

LevelOneServiceManager

QuantConnect.Brokerages.LevelOneOrderBook.LevelOneServiceManager

LevelOneServiceManager(
    data_aggregator: IDataAggregator,
    subscribe_callback: Callable[
        [List[Symbol], TickType], bool
    ],
    unsubscribe_callback: Callable[
        [List[Symbol], TickType], bool
    ],
)

Bases: Object, IDisposable

Manages subscriptions and real-time updates for multiple LevelOneMarketData instances. Facilitates routing of quote and trade data to a shared IDataAggregator in a thread-safe manner.

Initializes a new instance of the LevelOneServiceManager class.

Parameters:

Name Type Description Default
data_aggregator IDataAggregator

The aggregator to which all tick data will be published.

required
subscribe_callback Callable[[List[Symbol], TickType], bool]

Delegate used to perform symbol subscription logic.

required
unsubscribe_callback Callable[[List[Symbol], TickType], bool]

Delegate used to perform symbol unsubscription logic.

required

is_empty

is_empty: bool

Gets whether there are no active subscriptions.

count

count: int

Gets the number of currently subscribed symbols.

dispose

dispose() -> None

Releases all resources used by the LevelOneServiceManager.

get_subscribed_symbols

get_subscribed_symbols() -> Iterable[Symbol]

Returns subscribed symbols

Returns:

Type Description
Iterable[Symbol]

list of Symbol currently subscribed.

handle_last_trade

handle_last_trade(
    symbol: Union[Symbol, str, BaseContract],
    trade_date_time_utc: Optional[datetime],
    last_quantity: Optional[float],
    last_price: Optional[float],
    sale_condition: str = ...,
    exchange: str = ...,
) -> None

Handles incoming last trade data for a symbol and routes it to the corresponding LevelOneMarketData instance.

Parameters:

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

The symbol for which trade data is received.

required
trade_date_time_utc Optional[datetime]

The UTC timestamp of the trade.

required
last_quantity Optional[float]

The trade size.

required
last_price Optional[float]

The trade price.

required
sale_condition str

Optional sale condition string.

...
exchange str

Optional exchange identifier.

...

handle_open_interest

handle_open_interest(
    symbol: Union[Symbol, str, BaseContract],
    open_interest_date_time_utc: Optional[datetime],
    open_interest: Optional[float],
) -> None

Handles open interest updates for the specified symbol. If the symbol is subscribed, forwards the open interest data to the corresponding LevelOneMarketData instance for publishing.

Parameters:

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

The trading symbol associated with the open interest update.

required
open_interest_date_time_utc Optional[datetime]

The UTC timestamp when the open interest value was observed.

required
open_interest Optional[float]

The reported open interest value.

required

handle_quote

handle_quote(
    symbol: Union[Symbol, str, BaseContract],
    quote_date_time_utc: Optional[datetime],
    bid_price: Optional[float],
    bid_size: Optional[float],
    ask_price: Optional[float],
    ask_size: Optional[float],
) -> None

Handles incoming quote data for a symbol. Deduplicates updates and routes changes to the relevant LevelOneMarketData instance.

Parameters:

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

The symbol for which quote data is received.

required
quote_date_time_utc Optional[datetime]

The UTC timestamp of the quote.

required
bid_price Optional[float]

The bid price.

required
bid_size Optional[float]

The size at the bid price.

required
ask_price Optional[float]

The ask price.

required
ask_size Optional[float]

The size at the ask price.

required

set_ignore_zero_size_updates

set_ignore_zero_size_updates(
    symbol: Union[Symbol, str, BaseContract],
    ignore_zero_size_updates: bool,
) -> None

Sets the LevelOneMarketData.ignore_zero_size_updates flag for the specified symbol, controlling how zero-sized quote updates are handled for that symbol's market data stream.

Parameters:

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

The symbol whose quote update behavior should be configured.

required
ignore_zero_size_updates bool

If true, zero-sized bid or ask updates will be ignored for the given symbol, preserving existing book values. If false, zero sizes will be applied as valid updates.

required

subscribe

subscribe(data_config: SubscriptionDataConfig) -> None

Subscribes to the specified symbol based on the given SubscriptionDataConfig.

Parameters:

Name Type Description Default
data_config SubscriptionDataConfig

The subscription configuration containing symbol and type information.

required

unsubscribe

unsubscribe(data_config: SubscriptionDataConfig) -> None

Unsubscribes from the specified symbol and removes its associated service instance.

Parameters:

Name Type Description Default
data_config SubscriptionDataConfig

The subscription configuration used for unsubscription.

required