Historical data in TWS API

Discussion in 'App Development' started by api, May 29, 2020.

  1. api

    api

    Hi everybody!
    I'm using Python API to request historical data.

    A typical statement is:
    client.reqHistoricalData( 1, contract, "20200522 00:29:59", '1800 S', '5 secs', 'TRADES', False, 1, False, [])

    I receive 360 barData objects and that's fine but they start from "20200521 19:30:00" (instead of "20200022 00:00:00"). Last data point is at 19:59:55 (instead of 00:29:59).
    Which timezone is used to report data?

    Also, if I request:
    client.reqHistoricalData( 1, contract, "20200522 00:59:59", '1800 S', '5 secs', 'TRADES', False, 1, False, [])
    I receive another set of data but still starting at "20200521 19:30:00".

    Obviously my time specification is bad. I tried to add "EST" timezone. Same result.

    What am I doing wrong?
     
    blueraincap likes this.
  2. jharmon likes this.
  3. api

    api

    @HobbyTrading Thanks for your suggestion but my local timezone (UTC-5:00) was already set in the login page.
    The manual state:
    "The time zone of returned bars is the time zone chosen in TWS on the login screen"
    and, elsewhere:
    - endDateTime: 20130701 23:59:59 GMT
    - durationStr: 3 D
    . . . will return three days of data counting backwards from July 1st 2013 at 23:59:59 GMT
    So there are 2 timezones involved and there's no explanation about the difference.

    I did some more experiments and I'm now closer to an answer to my own question.
    If I ask for data between 9h10 and 9:40 for a stock in NYSE, I will receive data points starting at 9:30.
    But if I ask for data between 0:00 and 2:00, it trigger a special condition where IB send a complete set of data with timestamp in GMT instead of the timezone requested. Looks like a bug.
    I will do further tests and report here.