Search code examples
pythontimezoneinteractive-brokersibpy

Failing to change timezones of price data using IBPy


I would like to be able to get price data of a security with EST (New York) as the timezone. My broker is Interactive Brokers. I am using python 3.5 with the IBPy library. My problem is that when I modify the 3rd argument of reqHistoricalData which controls the timezone of the data, the prices I get back are exactly the same.

How to reproduce the problem:

  1. Create the contract to be queried by specifying contract.m_symbol = 'AUD', contract.m_secType = 'CASH', contract.m_exchange = 'IDEALPRO', contract.m_primaryExch = 'IDEALPRO', contract.m_currency = 'NZD'
  2. Using reqHistoricalData, get the daily opening price of the above contract with EST as the timezone for 23/6/2016.
  3. Now change the timezone by modifying the 3rd argument of reqHistoricalData to use JST as the timezone for 23/6/2016.
  4. Compare the opening prices from step 2 and 3

Appreciate any help.


Solution

  • The TZ just tells the IB server when to end the request. The responses will always be in GMT if you use 2 for formatDate param, or in your local time zone if you use 1.

    So by using JST you tell the server to end the request about 12 hours earlier, ie. when that was the time in Japan.

    In your example, I don't get the same data back. The times and prices are the same but using JST I get 12 hours less data. It's as if it converts the ending time to JST but leaves the calculated starting time in my own timezone.

    Needless to say, I never use time zones and try for GMT timestamps whenever possible.