Some people learn best from examples.
Please checkout the QuantConnect University!
In OnData event handler, we receive subscribed data. It means we need to subscribe it using AddSecurity/AddEquity/AddForex/etc. You can find this information in the docs, under the "Initializing Algorithms" section:
// Complete Add Equity API - Including Default Parameters:
AddEquity(string ticker, Resolution resolution = Resolution.Minute, string market = Market.USA, bool fillDataForward = true, decimal leverage = 0m, bool extendedMarketHours = false)
//Complete Add Forex API - Including Default Parameters:
AddForex(string ticker, Resolution resolution = Resolution.Minute, string market = Market.FXCM, bool fillDataForward = true, decimal leverage = 0m)
AddEquity("AAPL"); //Add Apple 1 minute bars (minute by default).
AddForex("EURUSD", Resolution.Second); //Add EURUSD 1 second bars.
We can also subscribe to a series of symbols from a universe. Coarse Universe selection is the built in universe data provided by QuantConnect. Using financial data we generate a few key properties for each symbol and allow you to filter the universe of 16,400+ symbols to receive the symbols matching your filter criteria:
// Take the top 50 by dollar volume using coarse
AddUniverse(coarse => {
return (from c in coarse
where c.Price > 10
orderby c.DollarVolume descending
select c.Symbol).Take(50);
});
Using this code snippet in Initialize method will result in receiving 50 symbols in OnData.