erdewit / ib_insync

Python sync/async framework for Interactive Brokers API
BSD 2-Clause "Simplified" License
2.81k stars 744 forks source link

sample code in README.rst fails... #607

Closed bitblitz closed 1 year ago

bitblitz commented 1 year ago

On a clean python install, I did pip install ib_insync, which installed without error along with some additional packages.

When I try to run the sample in the README.rst file, I encounter the following issues:

First, there seems to be timeout communicating with the TWSAPI client, though the client works otherwise, and if I change the duration to 1 D instead of 30 D the timeout does not occur.

output:

'C:\dev\ib\ibinsynctest.py'
Error handling fields: ['17', '3', '20230528 11:44:42 US/Eastern', '20230627 11:44:42 US/Eastern', '715', '20230516 17:15:00 US/Eastern', '1.08640', '1.08655', '1.08615', '1.08625', '-1', '-1', '-1', '20230516 18:00:00 US/Eastern', '1.08625', '1.08640', '1.08615', '1.08625', '-1', '-1', '-1', '20230516 19:00:00 US/Eastern', '1.08625', '1.08660', '1.08610', '1.08655', '-1', '-1', '-1', '20230516 20:00:00 US/Eastern', '1.08655', '1.08720', '1.08640', '1.08705', '-1', '-1', '-1', '20230516 21:00:00 US/Eastern', '1.08705', '1.08715', '1.08620', '1.08700', '-1', '-1', '-1', '20230516 22:00:00 US/Eastern', '1.08700', '1.08735', '1.08685', '1.08700', '-1', '-1', '-1', '20230516 23:00:00 US/Eastern', '1.08700', '1.08715', '1.08645', '1.08655', '-1', '-1', '-1', '20230517 00:00:00 US/Eastern', '1.08655', '1.08680', '1.08635', '1.08650', '-1', '-1', '-1', '20230517 01:00:00 US/Eastern', '1.08650', '1.08655', '1.08525', '1.08535', '-1', '-1', '-1', '20230517 02:00:00 US/Eastern', '1.08535', '1.08645', '1.08500', '1.08540', '-1', '-1', '-1', '20230517 03:00:00 US/Eastern', '1.08540', '1.08640', '1.08315', '1.08320', '-1', '-1', '-1', '20230517 04:00:00 US/Eastern', '1.08320', '1.08480', '1.08275', '1.08290', '-1', '-1', '-1', '20230517 05:00:00 US/Eastern', '1.08290', '1.08325', '1.08205', '1.08310', '-1', '-1', '-1', '20230517 06:00:00 US/Eastern', '1.08310', '1.08330', '1.08245', '1.08305', '-1', '-1', '-1', '20230517 07:00:00 US/Eastern', '1.08305', '1.08415', '1.08250', '1.08255', '-1', '-1', '-1', '20230517 08:00:00 US/Eastern', '1.08255', '1.08320', '1.08135', '1.08240', '-1', '-1', '-1', '20230517 09:00:00 US/Eastern', '1.08240', '1.08390', '1.08150', '1.08155', '-1', '-1', '-1', '20230517 10:00:00 US/Eastern', '1.08155', '1.08330', '1.08105', '1.08210', '-1', '-1', '-1', '20230517 11:00:00 US/Eastern', '1.08210', '1.08365', '1.08175', '1.08295', '-1', '-1', '-1', '20230517 12:00:00 US/Eastern', '1.08295', '1.08455', '1.08290', '1.08420', '-1', '-1', '-1', '20230517 13:00:00 US/Eastern', '1.08420', '1.08490', '1.08415', '1.08440', '-1', '-1', '-1', '20230517 14:00:00 US/Eastern', '1.08440', '1.08455', '1.08365', '1.08375', '-1', '-1', '-1', '20230517 15:00:00 US/Eastern', '1.08375', '1.08430', '1.08370', '1.08400', '-1', '-1', '-1', '20230517 16:00:00 US/Eastern', '1.08400', '1.08400', '1.08370', '1.08395', '-1', '-1', '-1', '20230517 17:15:00 US/Eastern', '1.08400', '1.08460', '1.08395', '1.08405', '-1', '-1', '-1', '20230517 18:00:00 US/Eastern', '1.08405', '1.08425', '1.08380', '1.08385', '-1', '-1', '-1', '20230517 19:00:00 US/Eastern', '1.08385', '1.08385', '1.08350', '1.08380', '-1', '-1', '-1', '20230517 20:00:00 US/Eastern', '1.08380', '1.08435', '1.08350', '1.08425', '-1', '-1', '-1', '20230517 21:00:00 US/Eastern', '1.08425', '1.08480', '1.08380', '1.08450', '-1', '-1', '-1', '20230517 22:00:00 US/Eastern', '1.08450', '1.08480', '1.08440', '1.08465', '-1', '-1', '-1', '20230517 23:00:00 US/Eastern', '1.08465', '1.08470', '1.08375', '1.08400', '-1', '-1', '-1', '20230518 00:00:00 US/Eastern', '1.08400', '1.08405', '1.08325', '1.08330', '-1', '-1', '-1', '20230518 01:00:00 US/Eastern', '1.08330', '1.08360', '1.08270', '1.08305', '-1', '-1', '-1', '20230518 02:00:00 US/Eastern', '1.08305', '1.08345', '1.08235', '1.08260', '-1', '-1', '-1', '20230518 03:00:00 US/Eastern', '1.08260', '1.08310', '1.08090', '1.08165', '-1', '-1', '-1', '20230518 04:00:00 US/Eastern', '1.08165', '1.08220', '1.08125', '1.08165', '-1', '-1', '-1', '20230518 05:00:00 US/Eastern', '1.08165', '1.08200', '1.08075', '1.08185', '-1', '-1', '-1', '20230518 06:00:00 US/Eastern', '1.08185', '1.08195', '1.08055', '1.08150', '-1', '-1', '-1', '20230518 07:00:00 US/Eastern', '1.08150', '1.08180', '1.08085', '1.08150', '-1', '-1', '-1', '20230518 08:00:00 US/Eastern', '1.08150', '1.08180', '1.07855', '1.07900', '-1', '-1', '-1', '20230518 09:00:00 US/Eastern', '1.07900', '1.07950', '1.07750', '1.07780', '-1', '-1', '-1', '20230518 10:00:00 US/Eastern', '1.07780', '1.07865', '1.07670', '1.07695', '-1', '-1', '-1', '20230518 11:00:00 US/Eastern', '1.07695', '1.07785', '1.07635', '1.07755', '-1', '-1', '-1', '20230518 12:00:00 US/Eastern', '1.07755', '1.07810', '1.07630', '1.07630', '-1', '-1', '-1', '20230518 13:00:00 US/Eastern', '1.07630', '1.07670', '1.07625', '1.07665', '-1', '-1', '-1', '20230518 14:00:00 US/Eastern', '1.07665', '1.07690', '1.07640', '1.07670', '-1', '-1', '-1', '20230518 15:00:00 US/Eastern', '1.07670', '1.07745', '1.07660', '1.07740', '-1', '-1', '-1', '20230518 16:00:00 US/Eastern', '1.07740', '1.07750', '1.07700', '1.07700', '-1', '-1', '-1', '20230518 17:15:00 US/Eastern', '1.07705', '1.07725', '1.07700', '1.07705', '-1', '-1', '-1', '20230518 18:00:00 US/Eastern', '1.07705', '1.07770', '1.07700', '1.07765', '-1', '-1', '-1', '20230518 19:00:00 US/Eastern', '1.07765', '1.07765', '1.07735', '1.07750', '-1', '-1', '-1', '20230518 20:00:00 US/Eastern', '1.07750', '1.07800', '1.07725', '1.07740', '-1', '-1', '-1', '20230518 21:00:00 US/Eastern', '1.07740', '1.07760', '1.07600', '1.07635', '-1', '-1', '-1', '20230518 22:00:00 US/Eastern', '1.07635', '1.07740', '1.07610', '1.07720', '-1', '-1', '-1', '20230518 23:00:00 US/Eastern', '1.07720', '1.07725', '1.07670', '1.07685', '-1', '-1', '-1', '20230519 00:00:00 US/Eastern', '1.07685', '1.07695', '1.07605', '1.07635', '-1', '-1', '-1', '20230519 01:00:00 US/Eastern', '1.07635', '1.07710', '1.07615', '1.07690', '-1', '-1', '-1', '20230519 02:00:00 US/Eastern', '1.07690', '1.07920', '1.07670', '1.07815', '-1', '-1', '-1', '20230519 03:00:00 US/Eastern', '1.07815', '1.07900', '1.07740', '1.07775', '-1', '-1', '-1', '20230519 04:00:00 US/Eastern', '1.07775', '1.07945', '1.07710', '1.07880', '-1', '-1', '-1', '20230519 05:00:00 US/Eastern', '1.07880', '1.08045', '1.07875', '1.08025', '-1', '-1', '-1', '20230519 06:00:00 US/Eastern', '1.08025', '1.08030', '1.07905', '1.07945', '-1', '-1', '-1', '20230519 07:00:00 US/Eastern', '1.07945', '1.08090', '1.07925', '1.08090', '-1', '-1', '-1', '20230519 08:00:00 US/Eastern', '1.08090', '1.08240', '1.08055', '1.08060', '-1', '-1', '-1', '20230519 09:00:00 US/Eastern', '1.08060', '1.08080', '1.07895', '1.07955', '-1', '-1', '-1', '20230519 10:00:00 US/Eastern', '1.07955', '1.07960', '1.07845', '1.07860', '-1', '-1', '-1', '20230519 11:00:00 US/Eastern', '1.07860', '1.08270', '1.07825', '1.08190', '-1', '-1', '-1', '20230519 12:00:00 US/Eastern', '1.08190', '1.08250', '1.08115', '1.08210', '-1', '-1', '-1', '20230519 13:00:00 US/Eastern', '1.08210', '1.08290', '1.08180', '1.08195', '-1', '-1', '-1', '20230519 14:00:00 US/Eastern', '1.08195', '1.08205', '1.08080', '1.08085', '-1', '-1', '-1', '20230519 15:00:00 US/Eastern', '1.08085', '1.08095', '1.07975', '1.08060', '-1', '-1', '-1', '20230519 16:00:00 US/Eastern', '1.08060', '1.08085', '1.08015', '1.08025', '-1', '-1', '-1', '20230521 17:15:00 US/Eastern', '1.08055', '1.08085', '1.08055', '1.08075', '-1', '-1', '-1', '20230521 18:00:00 US/Eastern', '1.08075', '1.08200', '1.08075', '1.08175', '-1', '-1', '-1', '20230521 19:00:00 US/Eastern', '1.08175', '1.08245', '1.08170', '1.08220', '-1', '-1', '-1', '20230521 20:00:00 US/Eastern', '1.08220', '1.08250', '1.08165', '1.08235', '-1', '-1', '-1', '20230521 21:00:00 US/Eastern', '1.08235', '1.08300', '1.08210', '1.08255', '-1', '-1', '-1', '20230521 22:00:00 US/Eastern', '1.08255', '1.08255', '1.08185', '1.08230', '-1', '-1', '-1', '20230521 23:00:00 US/Eastern', '1.08230', '1.08255', '1.08200', '1.08210', '-1', '-1', '-1', '20230522 00:00:00 US/Eastern', '1.08210', '1.08240', '1.08180', '1.08185', '-1', '-1', '-1', '20230522 01:00:00 US/Eastern', '1.08185', '1.08195', '1.08100', '1.08105', '-1', '-1', '-1', '20230522 02:00:00 US/Eastern', '1.08105', '1.08245', '1.08070', '1.08110', '-1', '-1', '-1', '20230522 03:00:00 US/Eastern', '1.08110', '1.08130', '1.07955', '1.08070', '-1', '-1', '-1', '20230522 04:00:00 US/Eastern', '1.08070', '1.08130', '1.07990', '1.08105', '-1', '-1', '-1', '20230522 05:00:00 US/Eastern', '1.08105', '1.08235', '1.08080', '1.08195', '-1', '-1', '-1', '20230522 06:00:00 US/Eastern', '1.08195', '1.08295', '1.08175', '1.08220', '-1', '-1', '-1', '20230522 07:00:00 US/Eastern', '1.08220', '1.08235', '1.08125', '1.08220', '-1', '-1', '-1', '20230522 08:00:00 US/Eastern', '1.08220', '1.08315', '1.08160', '1.08195', '-1', '-1', '-1', '20230522 09:00:00 US/Eastern', '1.08195', '1.08215', '1.08085', '1.08125', '-1', '-1', '-1', '20230522 10:00:00 US/Eastern', '1.08125', '1.08245', '1.07975', '1.07985', '-1', '-1', '-1', '20230522 11:00:00 US/Eastern', '1.07985', '1.08080', '1.07965', '1.08055', '-1', '-1', '-1', '20230522 12:00:00 US/Eastern', '1.08055', '1.08170', '1.08030', '1.08100', '-1', '-1', '-1', '20230522 1reqHistoricalData: Timeout for Forex('EURUSD', exchange='IDEALPRO')

Second, once the timeout fires (or without a timeout with fewer bars), the code fails to run because there is no pandas package.

Exception has occurred: ModuleNotFoundError
No module named 'pandas'
  File "C:\dev\ib\ibinsynctest.py", line 13, in <module>
    df = util.df(bars)
         ^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'pandas'

Recommend adding pandas as a required package to run samples.

Also, any suggestion about how to solve the timeout would be greatly appreciated.

bitblitz commented 1 year ago

update: after adding Pandas - the timeout vanished... any idea why?

erdewit commented 1 year ago

Pandas is too large to be added to the dependencies, but I've added a comment to the code sample to (optionally) install it.

erdewit commented 1 year ago

Btw, the timeout can occur when too much bars are requested.