Dinosaur Technology and Trading » Interactive Brokers C# Client

RequestHistoricalData method question

(3 posts)

  1. Alex
    Member

    Hi,

    I'm tryig to pull 30 one day bars by calling

    client.RequestHistoricalData(12, Symbol, DateTime.Now, new TimeSpan(30, 0, 0, 0), BarSize.OneDay, HistoricalDataType.Trades, 1);

    As the result I'm getting only 20 one day bars and all the bars have same date 8/21/1970

    O:124.63 H:127.5 L:120.81 C:121.43 T:292300 D:8/21/1970 2:51:46 AM V:508869 Total:20 R:17
    O:120.41 H:122.98 L:119.05 C:122.41 T:263684 D:8/21/1970 2:51:47 AM V:422194 Total:20 R:18
    O:121.98 H:123.46 L:120.6 C:120.6 T:101529 D:8/21/1970 2:51:50 AM V:169209 Total:20 R:19

    Am I specifying some incorrect input parameter values?

    Posted 7 months ago #
  2. Hey Alex,

    It turns out that when you request bar data, IB returns the date code as a date (20080612) instead of the number of seconds since 1/1/1970, as it does when you request hours or lower time frames.

    I have fixed this bug in my internal release, and will push something out shortly.

    Thanks,

    -Karl

    Posted 6 months ago #
  3. Alex
    Member

    Hey Karl,

    Thank you for the help.

    I came up with the temporarily work around. Here is the code fix in IBClient.cs:

    for (int ctr = 0; ctr < itemCount; ctr++)
    {
    //Comes in as seconds
    //2 - dates are returned as a long integer specifying the number of seconds since 1/1/1970 GMT.
    String date = ReadStr();
    DateTime timeStamp;
    if (date.Length == 10)
    {
    long longDate = Int64.Parse(date, CultureInfo.InvariantCulture);
    timeStamp = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(longDate).ToLocalTime();
    }
    else
    timeStamp = new DateTime(Convert.ToInt32(date.Substring(0, 4)), Convert.ToInt32(date.Substring(4, 2)),
    Convert.ToInt32(date.Substring(6, 2)));

    I'm still trying to figure out why IB is returning less numbers of one day bars as was requested. For example:

    requested returned
    10 5
    20 15
    30 20
    40 20
    50 40
    60 40
    70 40
    80 60

    -Alex

    Posted 6 months ago #

RSS feed for this topic

Reply

You must log in to post.