开云体育

ctrl + shift + ? for shortcuts
© 2025 开云体育

reqHistoricalData returns live data with date in the future


 

Hi all

As topic title, have a bit of an unusual one. So sometimes IBKR returns live daily data with date in the future, has anyone come across this problem?

I can handle it easily by restarting Gateway, but it irks me to no end that it happens, and more importantly I'm concerned that I have missed something somewhere that will manifest in a much nastier way down the track.

To illustrate the problem, on this just past Friday (1st July):
Using IBC, I run my script at 845am AEST(Sydney), and using reqHistoricalData it backfills daily data correctly up to and including 30th of June, and then it sits quietly until 10am (AEST) for market open to update me with live data.

-------------------------------------------
2022-07-01 08:45:25.529 [GS] INFO? [JTS-PostAuthenticateS2-23] - Started on 20220630-22:45:25
2022-07-01 08:45:25.529 [GS] INFO? [JTS-PostAuthenticateS2-23] - Default timezone:Australia/Sydney name:Australian Eastern Standard Time (New South Wales) dst:3600000
/////////////////////TRUNCATED///////////////////////////////
2022-07-01 09:59:53.444 [GS] INFO? [JTS-CCPDispatcherS2-35] - CCP reported time: 2022-06-30 23:59:53.000 (GMT) [1656633593000], local time: 2022-06-30 23:59:53.442 (GMT), local time: 2022-07-01 09:59:53.442 (AEST), difference in seconds: -0.442, handling delta:0 [Msg1]
2022-07-01 10:00:11.010 [GS] INFO? [JTS-EServerSocketNotifier-93] - [1:157:157:1:0:90:-1:INFO] Sending historical data update [requestId: 2]...
2022-07-01 10:00:11.012 [GS] INFO? [JTS-EServerSocketNotifier-93] - [1:157:157:1:0:90:-1:DET] [90;2;541;20220702;40.830;40.740;40.840;40.710;40.82844666903462;413859]
-------------------------------------------

As a test, I sat and watched it feed me data from the '2nd of July' for more than an hour before manually handling it.

It seems that the Gateway reads my login screen settings correctly and knows that my computer is in AEST timezone, and gives me historical data correctly, but when it returns live data, it adds 1 day to the date which in this case, the 2nd of July being a Saturday and therefore not a trading day, makes no sense.

From my understanding of the IBKR github, with reqHistoricalData and keepUpToDate=True, there is no way to set a timezone as it just reads off the TWS login screen. I have checked my TWS login screen timezone, Windows timezone settings, combed through this group's topics as well as done a code review and nothing has come to mind.

If this wasn't an intermittent problem then I would just subtract 1 from the date to make it work properly or perhaps use reqRealTimeBars, but the fact that restarting Gateway can usually resolve this problem suggests to me the issue is somewhere else.

Has anyone else come across this or have any ideas/thoughts?

Cheers and thanks in advance


 

On Sun, Jul 3, 2022 at 10:16 PM, Dan L wrote:
Not sure if anyone else has had this issue, since it seems very niche, but since the recent daylight savings time adjustment in Australia, I've realized that my future date issue happens at 11am (AEST) instead of as previously at 10am (AEST), so its clearly a timezone issue and not something to do with the market opening as I previously assumed.

Does anyone know a way to get the daily bars in UTC/GMT Timezone or unix? The documentation () says you can use 'formatDate' for everything except Daily bars!

If no one has knows a way suppose I'll just have to request intraday bars and then aggregate them, thanks.


 

From in the TWS user guide:
The time zone of returned bars is the time zone chosen in TWS on the login screen.

One solution is to set your computer time to the required time zone. Works for me.

KH


 

Timezones handling has been recently updated.

According to the , starting from 10.18, the time zone used by all timestamps sent by TWS can be one of:

  • UTC
  • Instrument timezone
  • User timezone (i.e. the one selected at login)

Which of the three is used is set globally by the (slightly cryptically named) setting:

TWS -> Configuration -> API -> Settings -> "Send instrument-specific attributes for dual-mode API client in"


 

Thanks for the help everyone, unfortunately when I tried it the changes didn't work, but the problem seems to have resolved itself mysteriously... the only major change I've done is upgrade my EC2 server.