feat: add CreateOAuthTokenHandler factory to Brokerage base class#9330
Open
Romazes wants to merge 1 commit intoQuantConnect:masterfrom
Open
feat: add CreateOAuthTokenHandler factory to Brokerage base class#9330Romazes wants to merge 1 commit intoQuantConnect:masterfrom
Romazes wants to merge 1 commit intoQuantConnect:masterfrom
Conversation
Introduce AuthenticationFailed event on TokenHandler raised when all retry attempts are exhausted. Add CreateOAuthTokenHandler<TRequest,TResponse> protected factory method on Brokerage that wires the event to OnMessage (BrokerageMessageType.Error), triggering graceful Lean shutdown on OAuth token refresh failure without requiring per-brokerage error logic. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
AuthenticationFailedevent toTokenHandlerbase class, raised when all retry attempts are exhausted after a failed token fetchprotected CreateOAuthTokenHandler<TRequest, TResponse>()factory method toBrokeragebase class that creates anOAuthTokenHandlerand automatically subscribes toAuthenticationFailed, routing it toOnMessage(BrokerageMessageType.Error)to trigger graceful Lean shutdownRelated PRs
Related Issue
Motivation and Context
When a live brokerage fails to refresh its OAuth access token (e.g.
"Error refreshing access token."), the error was only logged and the algorithm continued running in a broken state. The root cause is thatOAuthTokenHandler.GetAccessTokenthrows anInvalidOperationExceptionwhich propagates through the HTTP stack but never reaches Lean's shutdown mechanism.This change introduces a single centralized point -
Brokerage.CreateOAuthTokenHandler- where the wiring between OAuth failure and Lean termination is defined. Individual brokerage implementations pass this factory when constructing their API clients; no per-brokerage error handling logic is needed.Requires Documentation Change
No
How Has This Been Tested?
AuthenticationFailedevent =>OnMessage(BrokerageMessageType.Error)=>DefaultBrokerageMessageHandler=>algorithm.SetRuntimeError()=> graceful Engine shutdownTypes of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>