# Changing timezones with historic forex data (Interactive Brokers API IBPy)

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.

• This question appears to be off-topic for this site. Ask on Stack Overflow instead. – Matt Johnson Jun 23 '16 at 17:15
• Hi Matt, thanks for the response. Previously I've asked identical questions on SO and QF stack. I received a constructive reply here versus nothing on SO, hence I've posted it here instead. This link vs this link Also, I feel that I'm more likely to find persons with experience using IBPy here instead of SO. – lostlostlostlostlost Jun 23 '16 at 17:35
• Read the link I gave about what is on-topic for this site. Your post is about programming, and thus belongs on Stack Overflow. Your other question on Stack Overflow didn't get much traction because you didn't follow guidelines for that site. See How to ask a good question in the StackOverflow help center. – Matt Johnson Jun 23 '16 at 17:52
• @MattJohnson, Hi Matt. I've posted to SO following the guide you linked. If you have any advice, either with regard to my problem or how to ask better questions, I would appreciate it. Thanks. – lostlostlostlostlost Jun 30 '16 at 8:05

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.

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