Skip to content

Title: [Feature Request] Expose brokerage reconnect to algorithm layer #9496

@violet-day

Description

@violet-day

Expected Behavior

Algorithms should be able to programmatically trigger a brokerage reconnect when they detect data-quality anomalies (e.g. consecutive zero-volume bars during market hours while the connection is technically alive). A method such as self.reconnect_brokerage() on QCAlgorithm would allow the algorithm to recover without human intervention or process restart.

Actual Behavior

There is no way for an algorithm to trigger a brokerage Disconnect/Connect cycle. QCAlgorithm holds an internal IBrokerage reference but does not expose it. The only workarounds are:

  • self.Quit() — exits the algorithm entirely, disrupting live positions
  • Out-of-process IPC (flag files, sockets) between the algorithm thread and the brokerage heartbeat thread — fragile and non-portable

This gap is particularly visible with IBKR, where the gateway can enter a state where heartbeats succeed but the market data feed silently freezes (bars arrive with Volume = 0). The algorithm layer can detect this condition but has no recourse.

Potential Solution

Add a single public method to QCAlgorithm:

public void ReconnectBrokerage()
{
    try { Brokerage.Disconnect(); } catch (Exception) { }
    Brokerage.Connect();
}

Python usage:

def on_consolidated_bar(self, bar):
    if self._is_data_frozen(bar):
        self.log("Data feed frozen, triggering reconnect")
        self.reconnect_brokerage()

The change is brokerage-agnostic and minimal — QCAlgorithm already holds the IBrokerage reference internally.

Open design questions we'd welcome feedback on before submitting a PR:

Should there be a built-in cooldown guard, or leave rate-limiting to the algorithm author?
Should the method emit a BrokerageMessageEvent before reconnecting so the live trading monitor is aware?
We are happy to contribute a PR if the team agrees on the API shape.

Checklist

  • I have completely filled out this template
  • I have confirmed that this issue exists on the current master branch
  • I have confirmed that this is not a duplicate issue by searching [issues]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions