ranaroussi / ezibpy

ezIBpy, a Pythonic Client for Interactive Brokers API
Apache License 2.0
324 stars 116 forks source link

Hardcoded formatDate forces TZ to UTC on forex historical data requests #10

Closed othyro closed 7 years ago

othyro commented 7 years ago

With formatDate hardcoded to "2", historical data requests for forex pairs return in UTC, no matter if you have TZ set in end_datetime. Hardcoding this to "1" will throw this error:

ValueError: invalid literal for int() with base 10: '20170221 19:39:00'

Therefore, attached is a patch which retains the default functionality while allowing the user to avoid forcing all output data to UTC, if desired. Note: there might be a better way to accomplish the same. I'm not a python programmer.

If you're unconvinced of this bug, pull a day of historical data for USD.NOK with 1 min candles and see the start time for the day as 22:15:00 instead of 17:15:00, as defined for IDEAL PRO.

ezibpy_ezibpy_py.patch.txt

ranaroussi commented 7 years ago

Setting the TZ in end_datetime is used by IB for calculating the timeframe for the historical data - it does not control the timezone of the returned data, which is always returned as UTC.

I'll add the option to set format_date=1 on the next release, but bear in mind, this only controls the format, not the timezone.