Skip to content

Use the current ticker for the algorithm holdings - #9738

Open
AlexCatarino wants to merge 1 commit into
QuantConnect:masterfrom
AlexCatarino:bug-live-holdings-outdated-ticker
Open

Use the current ticker for the algorithm holdings#9738
AlexCatarino wants to merge 1 commit into
QuantConnect:masterfrom
AlexCatarino:bug-live-holdings-outdated-ticker

Conversation

@AlexCatarino

Copy link
Copy Markdown
Member

Description

A Symbols ticker is set when it's created and never updated afterwards, but the SecurityIdentifier does not change, it holds the first ticker in the map file. This means the ticker we use for holdings can be outdated:

  • Symbols deserialized from the live-holdings brokerage data keep the ticker they were serialized with, SymbolJsonConverter takes the value as 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.Symbol is 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 to RequiresMapping(), 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 subscriptions ContractDepthOffset.

Note that deserialized option symbols can be missing their underlying, the security identifier has one but SymbolJsonConverter leaves the property null when the JSON has no underlying node. The mapping is resolved through the underlying, so MapToCurrentTicker() 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-holdings could 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 DefaultBrokerageTests and LiveTradingResultHandlerTests covering 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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Non-functional change (xml comments/documentation/etc)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant