Fix duplicate OnData when dynamically adding an at-expiry contract#9575
Fix duplicate OnData when dynamically adding an at-expiry contract#9575jonathanwu906 wants to merge 1 commit into
Conversation
Adding a delistable contract (e.g. via AddOptionContract) at or after its delisting date from inside a scheduled event caused DelistingEventProvider to emit a stale delisting warning immediately, producing a spurious extra slice and a second OnData call at the same time (GH QuantConnect#9279). CorporateEventEnumeratorFactory now only attaches a DelistingEventProvider when the subscription starts before the delisting date. Adds a regression algorithm that fails without the fix and passes with it.
|
@Martin-Molinero this implements a fix for #9279, based on the cause you identified — a stale The fix is in One design question: a subscription added at/after its delisting date now receives no delisting events (both Would appreciate a review when you have a chance — thanks! |
Description
Adding a delistable contract (e.g.
AddOptionContract) at/after its delisting date from inside a scheduled event causedOnDatato fire twice at the same timestamp — the second slice carrying only aDelisting.Warning. This makes it fire once per period as expected.Related Issue
Closes #9279
Motivation and Context
CorporateEventEnumeratorFactoryalways attaches aDelistingEventProviderfor aCanBeDelisted()security. When the subscription starts on/after the delisting date (a near/at-expiry contract added dynamically, e.g. in aSchedule.Oncallback), the provider emits aDelistingType.Warningon its first tradable date, which arrives as a separate slice at the same time → the duplicateOnData.The provider's date-based emission is intentional (covered by
DelistingEnumeratorTests), so the fix is in the factory: skip the provider when the subscription starts on/after the delisting date.Requires Documentation Change
No.
How Has This Been Tested?
AddOptionContractInScheduledEventRegressionAlgorithm: fails without the fix (throws →RuntimeError), passes with it.DelistingEnumeratorTestspass (provider unchanged); existing option/future delisting regressions produce identicalOrderListHash.Types of changes
Checklist:
bug-<issue#>-<description>Note for reviewers
A subscription starting on/after its delisting date now receives no delisting events (both
WarningandDelisted). This looks correct for an already-expired asset — happy to only skip theWarningif you prefer.