BrokerageMultiWebSocketSubscriptionManager
QuantConnect.Brokerages.BrokerageMultiWebSocketSubscriptionManager
BrokerageMultiWebSocketSubscriptionManager(
web_socket_url: str,
maximum_symbols_per_web_socket: int,
maximum_web_socket_connections: int,
symbol_weights: Dictionary[Symbol, int],
web_socket_factory: Callable[
[], WebSocketClientWrapper
],
subscribe_func: Callable[[IWebSocket, Symbol], bool],
unsubscribe_func: Callable[[IWebSocket, Symbol], bool],
message_handler: Callable[[WebSocketMessage], Any],
web_socket_connection_duration: timedelta,
connection_rate_limiter: RateGate = None,
)
Bases: EventBasedDataQueueHandlerSubscriptionManager, IDisposable
Handles brokerage data subscriptions with multiple websocket connections, with optional symbol weighting
Initializes a new instance of the BrokerageMultiWebSocketSubscriptionManager class
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
web_socket_url
|
str
|
The URL for websocket connections |
required |
maximum_symbols_per_web_socket
|
int
|
The maximum number of symbols per websocket connection |
required |
maximum_web_socket_connections
|
int
|
The maximum number of websocket connections allowed (if zero, symbol weighting is disabled) |
required |
symbol_weights
|
Dictionary[Symbol, int]
|
A dictionary for the symbol weights |
required |
web_socket_factory
|
Callable[[], WebSocketClientWrapper]
|
A function which returns a new websocket instance |
required |
subscribe_func
|
Callable[[IWebSocket, Symbol], bool]
|
A function which subscribes a symbol |
required |
unsubscribe_func
|
Callable[[IWebSocket, Symbol], bool]
|
A function which unsubscribes a symbol |
required |
message_handler
|
Callable[[WebSocketMessage], Any]
|
The websocket message handler |
required |
web_socket_connection_duration
|
timedelta
|
The maximum duration of the websocket connection, TimeSpan.Zero for no duration limit |
required |
connection_rate_limiter
|
RateGate
|
The rate limiter for creating new websocket connections |
None
|
subscribers_by_channel
subscribers_by_channel: ConcurrentDictionary[Channel, int]
Counter
This codeEntityType is protected.
subscribe_impl
Subscription method implementation
unsubscribe_impl
Unsubscription method implementation
dispose
dispose() -> None
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
subscribe
unsubscribe
get_subscribed_symbols
get_subscribed_symbols() -> Iterable[Symbol]
Signature descriptions:
-
Returns subscribed symbols
-
Retrieves the list of unique Symbol instances that are currently subscribed for a specific TickType.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tick_type
|
Optional[TickType]
|
The type of tick data to filter subscriptions by. |
None
|
Returns:
| Type | Description |
|---|---|
Iterable[Symbol]
|
Depends on the signature used. Case 1: [list of Symbol currently subscribed.]; Case 2: [A collection of unique Symbol objects that match the specified tick_type.] |
channel_name_from_tick_type
channel_name_from_tick_type(tick_type: TickType) -> str
Channel name
This codeEntityType is protected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tick_type
|
TickType
|
Type of tick data |
required |
Returns:
| Type | Description |
|---|---|
str
|
Returns Socket channel name corresponding tick_type. |
is_subscribed
is_subscribed(
symbol: Union[Symbol, str, BaseContract],
tick_type: TickType,
) -> bool
Checks if there is existing subscriber for current channel
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
Union[Symbol, str, BaseContract]
|
Symbol |
required |
tick_type
|
TickType
|
Type of tick data |
required |
Returns:
| Type | Description |
|---|---|
bool
|
return true if there is one subscriber at least; otherwise false. |