Documentation icon indicating copy to clipboard operation
Documentation copied to clipboard

Document OnData

Open DavidThielen opened this issue 4 years ago • 1 comments

Document in detail when OnData is called, and with what data. Getting this right is key to a developer writing a correct algo.

Items that need to be covered:

  1. What causes it to be called and when.
  2. Will it always be a single call at a given time with all stocks in the data? Or can it be called multiple times, each call with a different subset of the data.
  3. If it is being called every minute, and the processing one time takes 2 minutes to complete, will it then be called again twice in quick succession? Or does it throw away the intermediate call as we're now 2 minutes later?
  4. How does one insure that all data is updated before it is called?
  5. Can it have cases where some of the stocks are updated but others are not?
  6. For the daily call (after market close, before next market open), is there a time window it will be called in? Or is it just any time from 1 second after close to 2 minutes before open?
  7. How does it handle daily on stocks on other markets (London, etc.)

And I'm sure I've missed items as I'm new to all this. But the above is a good start I think.

DavidThielen avatar Dec 04 '21 20:12 DavidThielen

We will answer these questions one-by-one throughout the docs.

For 1, 2, and 4, see Event Flow.

Specifically for 2 and 4,

LEAN receives the data from the subscriptions, synchronizes the data to create a timeslice

It means that the engine ensures the data is updated.

For 5, to only receive updated data, disable fill forward

For 6 and 7, see Daily Periods.

LEAN emits daily bars at midnight.

DerekMelchin avatar Jul 22 '22 23:07 DerekMelchin

https://www.quantconnect.com/docs/v2/writing-algorithms/key-concepts/event-handlers

jaredbroad avatar Feb 03 '23 03:02 jaredbroad