Use the current ticker for the algorithm holdings - #9738
Open
AlexCatarino wants to merge 1 commit into
Open
Conversation
A symbols ticker is set when it's created and does not get updated if the security is renamed, and deserialized symbols keep the ticker they were serialized with, while the security identifier never changes. Add the Symbol.MapToCurrentTicker() extension method and use it for the holdings sourced from the provided brokerage data and from the algorithm securities. The live holdings being sent now use their subscriptions symbol, which is kept up to date on renames, and are ordered by the ticker we are sending. Co-Authored-By: Claude Opus 5 (1M context) <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
A
Symbols ticker is set when it's created and never updated afterwards, but theSecurityIdentifierdoes not change, it holds the first ticker in the map file. This means the ticker we use for holdings can be outdated:live-holdingsbrokerage data keep the ticker they were serialized with,SymbolJsonConvertertakes thevalueas is. If the security is not already in the algorithm,GetOrAddUnrequestedSecurity()re-adds it by ticker, so a wrong ticker ends up creating a different security than the security identifier asks for.Security.Symbolis get only, so if a security is renamed during a live deployment only its subscriptions get updated, and the holdings we send out keep the old ticker.This adds the
Symbol.MapToCurrentTicker()extension method, next toRequiresMapping(), which resolves the ticker for the given symbols security identifier and applies it. It's used when sourcing holdings from the provided brokerage data and from the algorithm securities. Symbols which do not require mapping are returned as they are and any failure to resolve the mapping is logged and ignored, the security identifier is what matters.For the live holdings being sent,
LiveTradingResultHandler.GetHoldings()now takes the symbol from the securities subscription, which is kept up to date on renames by the data feed, and orders the holdings by the ticker being sent. Continuous futures are skipped there, their subscriptions symbol is the contract they are currently mapped to, which depends on each subscriptionsContractDepthOffset.Note that deserialized option symbols can be missing their underlying, the security identifier has one but
SymbolJsonConverterleaves the property null when the JSON has nounderlyingnode. The mapping is resolved through the underlying, soMapToCurrentTicker()restores it before resolving, else the resolve date used is the options expiry and it lands on the wrong map file.Related Issue
N/A
Motivation and Context
Holdings restored from
live-holdingscould be assigned to the wrong security and holdings sent out for renamed securities showed a ticker that no longer exists.Requires Documentation Change
N/A
How Has This Been Tested?
New unit tests in
DefaultBrokerageTestsandLiveTradingResultHandlerTestscovering the outdated, current and unrelated ticker cases for equities, the option underlying case, securities which do not require mapping, and the holdings ordering.Types of changes
Checklist:
🤖 Generated with Claude Code