Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live trading consolidation synchronization #8436

Conversation

jhonabreul
Copy link
Collaborator

@jhonabreul jhonabreul commented Dec 2, 2024

Description

Round time down to the nearest second before calling SubscriptionManager.ScanPastConsolidators in the AlgorithmManager to account for any offset between the consolidation time and the point where DateTime.UtcNow is called by the live time provider.

This small offset was causing SubscriptionManager.ScanPastConsolidators to scan consolidators (which would emit a consolidated bar) even when the time slice carried data that was supposed to be used to feed the consolidators for the current working bar.

Example:

  • Minute resolution subscription
  • 5 minute bar consolidator
  • A time slice carrying minute data for 9:59:00am-10:00:00am could have a time that is a few milliseconds (or even a few ticks) after 10:00:00am (becasue DateTime.UtcNow is called after the data is already in the subscriptions ready to be loaded to the time slice), which could cause SubscriptionManager.ScanPastConsolidators scan the consolidator which would emit the 9:55:00am-10:00:00am consolidated bar the last minute data was fed to the consolidator.

Related Issue

Closes #8363

Motivation and Context

Requires Documentation Change

How Has This Been Tested?

  • Unit tests
  • Manual live deployments (debugging and checking actual consolidated data)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change which improves implementation)
  • Performance (non-breaking change which improves performance. Please add associated performance test and results)
  • 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.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My branch follows the naming convention bug-<issue#>-<description> or feature-<issue#>-<description>

Adjust time slice to be driven by data, so that consolidators are update at the correct times.
Live trading uses DateTime.UtcNow which might be a few milliseconds after the latest data, causing some race conditions in consolidators scan times.
@jhonabreul jhonabreul changed the title Time slice time adjustment for live trading Live trading consolidation synchronization Dec 4, 2024
Copy link
Member

@Martin-Molinero Martin-Molinero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! 👍

@jhonabreul jhonabreul merged commit a1d0b6c into QuantConnect:master Dec 4, 2024
7 checks passed
@jhonabreul jhonabreul deleted the bug-8363-live-consolidation-skip-last branch December 4, 2024 15:15
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.

consolidator of 5m for live-data will always miss last minute trading bar, is it a bug?
2 participants