erdewit / ib_insync

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

asyncio.exceptions.TimeoutError on mac #620

Closed 430scud closed 1 year ago

430scud commented 1 year ago

im on macbook m1 with TWS running

Last week I was able to run the example code on your project README.

Now I am unable to run it. I am able to connect to the port via telnet.

I also see in the verbose logs that it is able to connect

im really not sure how to continue here.

from ib_insync import *
# util.startLoop()  # uncomment this line when in a notebook

ib = IB()
ib.connect('127.0.0.1', 7497, clientId=1)

contract = Forex('EURUSD')
bars = ib.reqHistoricalData(
    contract, endDateTime='', durationStr='30 D',
    barSizeSetting='1 hour', whatToShow='MIDPOINT', useRTH=True)

# convert to pandas dataframe (pandas needs to be installed):
df = util.df(bars)
print(df)
(ibkr) user@MacBook-Pro ibkr % python3 test.py 
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/tasks.py", line 456, in wait_for
    return fut.result()
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/user/ib/ibkr/test.py", line 5, in <module>
    ib.connect('127.0.0.1', 7497, clientId=1)
  File "/Users/user/ib/ibkr/lib/python3.10/site-packages/ib_insync/ib.py", line 279, in connect
    return self._run(self.connectAsync(
  File "/Users/user/ib/ibkr/lib/python3.10/site-packages/ib_insync/ib.py", line 318, in _run
    return util.run(*awaitables, timeout=self.RequestTimeout)
  File "/Users/user/ib/ibkr/lib/python3.10/site-packages/ib_insync/util.py", line 341, in run
    result = loop.run_until_complete(task)
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "/Users/user/ib/ibkr/lib/python3.10/site-packages/ib_insync/ib.py", line 1782, in connectAsync
    await asyncio.wait_for(self.reqExecutionsAsync(), timeout)
  File "/opt/homebrew/Cellar/python@3.10/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/tasks.py", line 458, in wait_for
    raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError
(ibkr) user@MacBook-Pro ibkr % 
430scud commented 1 year ago

heres the beginning and the last part of the debug log

2023-08-08 23:52:28,583 ib_insync.client INFO Connecting to 127.0.0.1:7497 with clientId 3... 2023-08-08 23:52:28,584 ib_insync.client INFO Connected 2023-08-08 23:52:28,588 ib_insync.client DEBUG <<< 176,20230808 23:52:27 PST 2023-08-08 23:52:28,588 ib_insync.client DEBUG >>> 71,2,3, 2023-08-08 23:52:28,588 ib_insync.client INFO Logged on to server version 176 2023-08-08 23:52:28,591 ib_insync.client DEBUG <<< 15,1,UXXXXXXXX, 2023-08-08 23:52:28,591 ib_insync.client DEBUG <<< 9,1,1 2023-08-08 23:52:28,592 ib_insync.client DEBUG <<< 4,2,-1,2104,Market data farm connection is OK:usfuture, 2023-08-08 23:52:28,592 ib_insync.wrapper INFO Warning 2104, reqId -1: Market data farm connection is OK:usfuture 2023-08-08 23:52:28,592 ib_insync.client DEBUG <<< 4,2,-1,2104,Market data farm connection is OK:cafarm, 2023-08-08 23:52:28,592 ib_insync.wrapper INFO Warning 2104, reqId -1: Market data farm connection is OK:cafarm 2023-08-08 23:52:28,592 ib_insync.client DEBUG <<< 4,2,-1,2104,Market data farm connection is OK:cashfarm, 2023-08-08 23:52:28,592 ib_insync.wrapper INFO Warning 2104, reqId -1: Market data farm connection is OK:cashfarm 2023-08-08 23:52:28,592 ib_insync.client DEBUG <<< 4,2,-1,2104,Market data farm connection is OK:usopt, 2023-08-08 23:52:28,592 ib_insync.wrapper INFO Warning 2104, reqId -1: Market data farm connection is OK:usopt 2023-08-08 23:52:28,592 ib_insync.client DEBUG <<< 4,2,-1,2104,Market data farm connection is OK:usfarm, 2023-08-08 23:52:28,592 ib_insync.wrapper INFO Warning 2104, reqId -1: Market data farm connection is OK:usfarm 2023-08-08 23:52:28,592 ib_insync.client DEBUG <<< 4,2,-1,2106,HMDS data farm connection is OK:ushmds.nj, 2023-08-08 23:52:28,592 ib_insync.wrapper INFO Warning 2106, reqId -1: HMDS data farm connection is OK:ushmds.nj 2023-08-08 23:52:28,592 ib_insync.client DEBUG <<< 4,2,-1,2106,HMDS data farm connection is OK:ushmds, 2023-08-08 23:52:28,592 ib_insync.wrapper INFO Warning 2106, reqId -1: HMDS data farm connection is OK:ushmds 2023-08-08 23:52:28,592 ib_insync.client DEBUG <<< 4,2,-1,2158,Sec-def data farm connection is OK:secdefnj, 2023-08-08 23:52:28,592 ib_insync.wrapper INFO Warning 2158, reqId -1: Sec-def data farm connection is OK:secdefnj 2023-08-08 23:52:28,593 ib_insync.client INFO API connection ready 2023-08-08 23:52:28,593 ib_insync.client DEBUG >>> 61,1

.... lists all the account details and ends with the following ....

2023-08-08 23:52:29,395 ib_insync.client DEBUG <<< 73,1,5,UXXXXX,,WarrantValue,0.00,BASE 2023-08-08 23:52:29,395 ib_insync.client DEBUG <<< 73,1,5,UXXXXX,,WarrantValue,0.00,CAD 2023-08-08 23:52:29,395 ib_insync.client DEBUG <<< 73,1,5,UXXXXX,,WarrantValue,0.00,USD 2023-08-08 23:52:29,395 ib_insync.client DEBUG <<< 74,1,5 2023-08-08 23:52:29,395 ib_insync.client DEBUG >>> 7,3,6,0,,,,,, 2023-08-08 23:52:33,397 ib_insync.ib INFO Disconnecting from 127.0.0.1:7497, 193 B sent in 11 messages, 32.7 kB received in 661 messages, session time 4.81 s. 2023-08-08 23:52:33,397 ib_insync.client INFO Disconnecting 2023-08-08 23:52:33,397 ib_insync.client INFO Disconnected.

430scud commented 1 year ago

connects and the disconnects?

2023-08-09 00:32:39,649 ib_insync.client INFO Connecting to 127.0.0.1:7497 with clientId 5... 2023-08-09 00:32:39,650 ib_insync.client INFO Connected 2023-08-09 00:32:43,652 ib_insync.client INFO Disconnecting 2023-08-09 00:32:43,653 ib_insync.client ERROR API connection failed: TimeoutError() 2023-08-09 00:32:43,653 ib_insync.client INFO Disconnected.

thisisloze commented 1 year ago

I updated my TWS and now get this error? What did you do to fix it?