Profile Picture

IB historical futures data 1 day off

Posted By alpha23 3 Years Ago
Posted Thursday April 02 2015
The historical data downloaded from IB is one day off, e.g. 3/24 data in RightEdge is actually 3/25 data per TWS.
Why and how to fix?

Thanks, Duane
Posted Thursday April 02 2015
RightEdge uses the bar start time to identify bars.  Is it possible that TWS is displaying the end of bar time, and that it's midnight so it displays as the next day?

Posted Friday April 03 2015
In the above example, TWS will display the data as 3/25 which is correct.  It is true that the extended trading hours starts the day before, on 3/24 (TWS still uses the 3/25 when displaying extended hours data); however, I selected to download only regular trading hours (per the TWS settings) which is 8:30 AM to 15:15 PM CST of 3/25.

It sounds like the RightEdge TWS plugin uses a bar start time different than the actual data returned?  If yes, what is the best way to fix this?

Thanks, Duane
Posted Monday April 20 2015
I looked into this and it turns out it's a timezone issue.  IB sends bar times either as the number of seconds since 1/1/1970 GMT, or in the format YYYYMMDD.  When it sends it with the YYYYMMDD format, that was being interpreted as a GMT date/time and then converted to local time, which depending on what timezone you were in could mean that it ended up being sometime in the evening of the previous day.

This code has been in the KRS ib-csharp library for a very long time, so it's possible that IB recently changed the date format it uses for daily bars.

This will be fixed in the next version.  If you'd like to fix this yourself, you can use the following in IBClient.cs (near "case IncomingMessage.HistoricalData:"):

if (longDate < 30000000)
    timeStamp = new DateTime(Int32.Parse(date.Substring(0, 4)), Int32.Parse(date.Substring(4, 2)), Int32.Parse(date.Substring(6, 2)), 0, 0, 0, DateTimeKind.Local);
    timeStamp = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(longDate).ToLocalTime();


Similar Topics

Reading This Topic

2005-2018 © RightEdge Systems