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

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

Manage alerts

Loading saved threads...

lostlostlostlostlost · External communityPost link
External question — Quantitative Finance Stack Exchange Author: lostlostlostlostlost Original post: https://quant.stackexchange.com/questions/27760 License: CC BY-SA 3.0 — https://creativecommons.org/licenses/by-sa/3.0/ Adaptation: HTML converted to plain text; contact email addresses removed. 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.
Quote
Report
mementum · External communityPost link
External answer — Quantitative Finance Stack Exchange Author: mementum Original post: https://quant.stackexchange.com/a/29636 License: CC BY-SA 3.0 — https://creativecommons.org/licenses/by-sa/3.0/ Adaptation: HTML converted to plain text; contact email addresses removed. 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.
Quote
Report
David Toth · External communityPost link
External answer — Quantitative Finance Stack Exchange Author: David Toth Original post: https://quant.stackexchange.com/a/43071 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. 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
Quote
Report

Post Reply

Checking account access…