Also, out of curiosity, why aren't the Daily requests listed in the DataRequests.BarRequests collection?
I couldn't figure out why the code below wasn't printing anything (I only had Trade and Daily listed under Market Data), but then I threw in a 1-min bar request and got the output I was expecting (but the daily bar request still wasn't present).
Code:
foreach (BarRequest request in DataRequests.BarRequests)
Console.WriteLine("Need to preload bars of size " + request.BarSize);
// only the 1-min bar request is outputted
When I run the strategy for real, I always use daily bars but sometimes I'll use 1, 5, or 10-sec bars to test it on my paper trading account. So I don't have to modify the code each time I switch the bar size, I'm using the current code to handle the preloading.
Code:
private void PreloadHistoricalBars()
{
DateTime now = DateTime.Now;
DateTime then = now.AddDays(-290);
foreach (BarRequest request in DataRequests.BarRequests)
PreloadHistoricalBars(then, now, request.BarType, request.BarSize);
if (DataRequests.HasDailyRequest)
PreloadHistoricalBars(then, now, BarType.Time, 86400);
}
private void PreloadHistoricalBars(DateTime then, DateTime now, BarType barType, long barSize)
{
foreach (Bar bar in GetHistoricalBars(then, now, barType, barSize))
Bars.Add(bar);
}
Is there a way I can write that so I don't have to handle the "HasDailyRequest" separately from the DataRequests.BarRequests in the top method?