Skip to content
All library documents

Handling Time Zones in Interactive Brokers Forex History

Article Quant Q&A · Author: lostlostlostlostlost

Summary

The document explains why changing the time-zone argument in an Interactive Brokers historical-data request may not change returned forex bars. One answer says the bar time zone follows the setting chosen on the Trader Workstation login screen, which may explain why the request argument has no effect. The discussion includes differing AUD/NZD daily opening prices reported for Eastern and Japan time, while the questioner receives the same price across several requested zones.

A practical workaround is to accept the timestamp zone supplied by IB, localize the parsed time with a time-zone database, then convert it to the desired zone; using UTC internally is also suggested. This changes how timestamps are represented, rather than asking IB to recalculate the bar boundaries. The exchange is brief and does not establish the full API behavior across versions or bar types, so users should verify the configured TWS zone and interpret daily bar boundaries accordingly.

Key ideas

  • IB historical bar timestamps may use the time zone configured in Trader Workstation.
  • A request-level time-zone change may not alter the returned forex bar prices.
  • Convert returned timestamps by localizing them to IB’s supplied zone and then converting to the target zone.
  • Working internally in UTC can simplify time-zone handling.

Tags

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


# 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:

- 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'

- Using reqHistoricalData, get the daily opening price of the above contract with EST as the timezone for 23/6/2016.

- Now change the timezone by modifying the 3rd argument of reqHistoricalData to use JST as the timezone for 23/6/2016.

- 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:

- General usage and examples of reqHistoricalData

- List of accepted timezones

- Documentation of reqHistoricalData() function.

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.

## Answer by mementum (score 1)

https://quant.stackexchange.com/a/29636

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.

## Answer by David Toth (score 1)

https://quant.stackexchange.com/a/43071

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

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.