Interactive Brokers API - Wrong date for historical data for weekly and monthly bars

Interactive Brokers API - Wrong date for historical data for weekly and monthly bars

Manage alerts

Loading saved threads...

KorbenDose · External communityPost link
External question — Quantitative Finance Stack Exchange Author: KorbenDose Original post: https://quant.stackexchange.com/questions/85241 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I'm currently trying to fetch historical data from Interactive Brokers using the ib_async package. Depending on the exchange I use, the weekly and monthly bars will have a wrong date. This is the relevant code bars = self.ib.reqHistoricalData( contract, endDateTime='', durationStr=duration_str, barSizeSetting=bar_size_str, whatToShow=what_to_show, useRTH=useRTH, formatDate=2, keepUpToDate=False ) df = util.df(bars) I have compared daily to weekly and monthly bars. The daily bars have the correct date, but the weekly and monthly bars are always off by one day. I have compared IBIS and NYSE as exchange, and it only happens for IBIS. NYSE has the correct dates. contract = Stock('SIE', 'IBIS', 'EUR') Daily result date open high low close volume average barCount 0 2025-11-19 217.30 220.56 216.04 218.6 592127.0 218.520 4972 1 2025-11-20 220.84 224.14 219.50 221.7 689447.0 221.824 5718 2 2025-11-21 217.46 220.26 216.64 219.1 685580.0 218.328 6150 Weekly result date open high low close volume average barCount 45 2025-11-08 244.56 247.50 233.50 237.06 2576031.0 241.758 23801 46 2025-11-15 243.20 252.66 225.24 230.26 4323219.0 237.940 38550 47 2025-11-22 229.84 230.16 216.04 219.10 3577868.0 220.662 29671 The last bar should have the same date, since it's the end of the week. Instead, the weekly bars (and also monthly bars) end one day later on Saturday. Since this doesn't happen on NYSE, I suppose it has something to do with the timezone. Setting formatDate to 1 doesn't solve the issue. I have also tried changing the timezone settings in TWS, which didn't solve the issue either. I have also checked if it's an issue with the package or if it has to do with converting the bars into a dataframe, which is not the case. The dirty solution would be to manually change the date for weekly and monthly bars, but I'd like to avoid that. Does anyone have an idea, how to solve this? Also, unrelated to the question above: When requesting smaller timeframe data, e.g. 5 minute bars, the provided time is the open of the bar. For weekly and monthly bars, the provided day (except in the case of IBIS above) is the last day of the interval. Am I doing something wrong or am I not seeing something? What is the reasoning behind this?
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External question — Quantitative Finance Stack Exchange Author: KorbenDose Source score (net votes, not local likes): 0 Original post: https://quant.stackexchange.com/questions/85241 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I'm currently trying to fetch historical data from Interactive Brokers using the ib_async package. Depending on the exchange I use, the weekly and monthly bars will have a wrong date. This is the relevant code bars = self.ib.reqHistoricalData( contract, endDateTime='', durationStr=duration_str, barSizeSetting=bar_size_str, whatToShow=what_to_show, useRTH=useRTH, formatDate=2, keepUpToDate=False ) df = util.df(bars) I have compared daily to weekly and monthly bars. The daily bars have the correct date, but the weekly and monthly bars are always off by one day. I have compared IBIS and NYSE as exchange, and it only happens for IBIS. NYSE has the correct dates. contract = Stock('SIE', 'IBIS', 'EUR') Daily result date open high low close volume average barCount 0 2025-11-19 217.30 220.56 216.04 218.6 592127.0 218.520 4972 1 2025-11-20 220.84 224.14 219.50 221.7 689447.0 221.824 5718 2 2025-11-21 217.46 220.26 216.64 219.1 685580.0 218.328 6150 Weekly result date open high low close volume average barCount 45 2025-11-08 244.56 247.50 233.50 237.06 2576031.0 241.758 23801 46 2025-11-15 243.20 252.66 225.24 230.26 4323219.0 237.940 38550 47 2025-11-22 229.84 230.16 216.04 219.10 3577868.0 220.662 29671 The last bar should have the same date, since it's the end of the week. Instead, the weekly bars (and also monthly bars) end one day later on Saturday. Since this doesn't happen on NYSE, I suppose it has something to do with the timezone. Setting formatDate to 1 doesn't solve the issue. I have also tried changing the timezone settings in TWS, which didn't solve the issue either. I have also checked if it's an issue with the package or if it has to do with converting the bars into a dataframe, which is not the case. The dirty solution would be to manually change the date for weekly and monthly bars, but I'd like to avoid that. Does anyone have an idea, how to solve this? Also, unrelated to the question above: When requesting smaller timeframe data, e.g. 5 minute bars, the provided time is the open of the bar. For weekly and monthly bars, the provided day (except in the case of IBIS above) is the last day of the interval. Am I doing something wrong or am I not seeing something? What is the reasoning behind this?

Cancel quote

Checking account access…