Document OnData
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:
- What causes it to be called and when.
- 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.
- 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?
- How does one insure that all data is updated before it is called?
- Can it have cases where some of the stocks are updated but others are not?
- 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?
- 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.
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.
https://www.quantconnect.com/docs/v2/writing-algorithms/key-concepts/event-handlers