Trade mapped contract for canonical Future order requests#9467
Open
AlexCatarino wants to merge 2 commits intoQuantConnect:masterfrom
Open
Trade mapped contract for canonical Future order requests#9467AlexCatarino wants to merge 2 commits intoQuantConnect:masterfrom
AlexCatarino wants to merge 2 commits intoQuantConnect:masterfrom
Conversation
Route order requests on a canonical (continuous) Future symbol to the currently mapped contract via IContinuousSecurity.Mapped, falling back to the canonical security when no contract is mapped. Closes QuantConnect#9463
jaredbroad
reviewed
May 7, 2026
| if (isCanonical && security is IContinuousSecurity { Mapped: not null } continuousSecurity && | ||
| Securities.TryGetValue(continuousSecurity.Mapped, out var mappedSecurity)) | ||
| { | ||
| return mappedSecurity; |
jaredbroad
approved these changes
May 7, 2026
When the target symbol is a canonical (continuous) Future, base the buying-power math and the resulting target on the currently mapped contract. If no contract is mapped, surface a dedicated error message instead of silently returning a zero-quantity result. Adds a unit test asserting SetHoldings on a canonical Future submits an order against the mapped contract sized off the mapped contract's price.
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
Routes order requests submitted with a canonical (continuous) Future Symbol to the currently mapped contract. The redirection happens in
QCAlgorithm.GetSecurityForOrder: when the requested symbol is canonical and the security implementsIContinuousSecuritywith a non-nullMapped, the corresponding contract security inSecuritiesis used instead of the canonical. IfMappedis unset (or the mapped contract isn't inSecurities), behavior falls back to the previous path (the canonical security is returned, leading to aNonTradableSecurityrejection).The Continuous Future and Future Rollover basic templates (C# and Python) were updated to demonstrate the simpler API by passing the canonical
Symboldirectly to the trading method.Related Issue
Closes #9463
Motivation and Context
Today, calling
set_holdings(future.Symbol, ...)(or any other trading method) with the canonical Future Symbol fails withThe security with symbol '/GC' is marked as non-tradable.Users were forced to manually look upfuture.Mappedand pass that contract symbol. With this change, the canonical Symbol is automatically routed to the active contract, matching the behavior users intuitively expect.Requires Documentation Change
No public API change; existing docs/examples remain valid. The basic Continuous Future and Future Rollover templates were updated to use the canonical
Symbolso that the documentation generated from them reflects the simpler pattern.How Has This Been Tested?
Tests/Algorithm/AlgorithmTradingTests.cs:OrdersOnCanonicalFutureSymbolAreRoutedToMappedContract— verifiesMarketOrder(canonical.Symbol, 1)produces an order targeting the mapped contract.OrdersOnCanonicalFutureSymbolAreRejectedWhenNoMappedContract— verifies fallback behavior still rejects withNonTradableSecuritywhenMappedis null.QuantConnect.Algorithm,QuantConnect.Algorithm.CSharp, andQuantConnect.Tests— no errors.Types of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>