I've found some strange behavior while downloading historical currency data from IB. Sometimes a 1 day request such as:
dateTime2 = 04/24/2019 21:16:00.000
dateTime1 = 04/23/2019 21:16:00.000 (times in UTC)
Will return only 1 bar, despite there being many bars available for that date range. If I extend the size of my query I receive all the data for that original window. See the code and outputs below:
Code:
Console.WriteLine($"IBHistoricalDownloader::Requesting(IB, EURCHF, {dateTime1}, {dateTime2}, {BarType.Time}, 60)");
BarSeries barSeries = Framework.DataManager.GetHistoricalBars(ProviderManager.GetHistoricalDataProvider("IB"), EURCHF, dateTime1, dateTime2, BarType.Time, 60);
Console.WriteLine($"IBHistoricalDownloader::Recieved -> {barSeries.Count}, {barSeries.FirstDateTime}, {barSeries.LastDateTime}");
if (barSeries.Count < 100)
{
foreach(Bar bar in barSeries)
{
if ( bar.DateTime >= dateTime1 && bar.DateTime <= dateTime2)
{
Console.WriteLine(bar);
}
}
DateTime dateTime1Extended = dateTime1.AddDays(-3);
Console.WriteLine($"IBHistoricalDownloader::Requesting(IB, {instrument.Symbol}, {dateTime1Extended}, {dateTime2}, {BarType.Time}, 60)");
barSeries = Framework.DataManager.GetHistoricalBars(ProviderManager.GetHistoricalDataProvider("IB"), EURCHF, dateTime1Extended, dateTime2, BarType.Time, 60);
Console.WriteLine($"IBHistoricalDownloader::Recieved -> {barSeries.Count}, {barSeries.FirstDateTime}, {barSeries.LastDateTime}");
foreach (Bar bar in barSeries)
{
if (bar.DateTime >= dateTime1 && bar.DateTime <= dateTime2)
{
Console.WriteLine(bar);
}
}
}
OutPut:
Requesting: EURCHF, Bid, 60, 04/23/2019 21:16:00.000 - 04/24/2019 21:16:00.000
IBHistoricalDownloader::GetHistoricalBars(EURCHF, Bid, 60, 04/23/2019 21:16:00.000 - 04/24/2019 21:16:00.000)
IBHistoricalDownloader::Requesting(IB, EURCHF, 04/23/2019 21:16:00.000, 04/24/2019 21:16:00.000, Time, 60)
IBHistoricalDownloader::Recieved -> 1, 04/24/2019 21:16:00.000, 04/24/2019 21:16:00.000
Bar [04/24/2019 21:15:00.000 - 04/24/2019 21:16:00.000] Instrument=23 Type=Time Size=60 Open=1.13805 High=1.1381 Low=1.138 Close=1.13803 Volume=-1
// After extending date range:
IBHistoricalDownloader::Requesting(IB, EURCHF, 04/20/2019 21:16:00.000, 04/24/2019 21:16:00.000, Time, 60)
IBHistoricalDownloader::Recieved -> 4171, 04/21/2019 23:01:00.000, 04/24/2019 21:16:00.000
Bar [04/23/2019 21:15:00.000 - 04/23/2019 21:16:00.000] Instrument=23 Type=Time Size=60 Open=1.1447 High=1.1451 Low=1.1447 Close=1.1451 Volume=-1
Bar [04/23/2019 21:16:00.000 - 04/23/2019 21:17:00.000] Instrument=23 Type=Time Size=60 Open=1.1451 High=1.1451 Low=1.1451 Close=1.1451 Volume=-1
Bar [04/23/2019 21:17:00.000 - 04/23/2019 21:18:00.000] Instrument=23 Type=Time Size=60 Open=1.1451 High=1.1451 Low=1.1451 Close=1.1451 Volume=-1
.
.
.
Bar [04/24/2019 20:58:00.000 - 04/24/2019 20:59:00.000] Instrument=23 Type=Time Size=60 Open=1.13817 High=1.13819 Low=1.13812 Close=1.13814 Volume=-1
Bar [04/24/2019 20:59:00.000 - 04/24/2019 21:00:00.000] Instrument=23 Type=Time Size=60 Open=1.13814 High=1.13833 Low=1.13803 Close=1.13805 Volume=-1
Bar [04/24/2019 21:15:00.000 - 04/24/2019 21:16:00.000] Instrument=23 Type=Time Size=60 Open=1.13805 High=1.1381 Low=1.138 Close=1.13803 Volume=-1
So to summarize, my problem is that a request for the date range 04/23/2019 21:16:00.000 - 04/24/2019 21:16:00.000, returns only 1 bar, but if I extend the range to 04/20/2019 21:16:00.000 - 04/24/2019 21:16:00.000, I get plenty of data covering the original date range.
any help here?