4

I would like to be able to change the timezone for my requests to the IB API, how can I do this? I am writing in Python, and thus use the IBPy wrapper found here.

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

Supposedly, the third argument of the function reqHistoricalData(...) controls the timezone. However, changing from EST to JST doesn't change my prices. I have been in contact with the API guys from IB. They obtain the following results for AUD.NZD:

With EST as timezone opening price for 23/6/16 is: 1.046185 With JST as timezone opening price for 23/6/16 is: 1.04598

I get: 1.046185 for all timezone I have tried (GMT, EST, JST).

I have approached the following resources:

How can I change the timezone in my historic data requests? Any help is greatly appreciated, and I promise to buy you a drink the next time you are in Singapore.

2 Answers2

1

I remember to have encountered similar problems with timezones and decided to approach the timezones in a different way with IB with my python platform (backtrader)

Instead of trying to force the hand of the platform I take whatever timezone information the platform gives me and work from there to my desired timezone.

The process:

  • IB gives you the EST timezone for your asset
  • Luckily this is a name recognized by pytz (which you should obviously install)
  • Once you have translated the IB timestamp to a datetime(naive) object named dt and have the timezone name in ibtzname

The code would roughly look like this:

ibtz = pytz.timezone(ibtzname)
eastern_dt = ibtz.localize(dt)
sing_tz = pytz.timezone('Asia/Singapore')
sing_dt = eastern_dt.astimezone(sing_tz)

Obviously you can cache the sing_tz and ibtz if they are always fixed values.

You may also wisth to work internally in UTC and only convert back to Asia/Singapore at the last moment. But your own needs should prevail.

mementum
  • 628
  • 6
  • 8
1

The time zone of returned bars is the time zone chosen in TWS on the login screen.

https://interactivebrokers.github.io/tws-api/historical_bars.html

David Toth
  • 11
  • 1