Connection raises TimeoutError, but IB gateway is running and port is open
See original GitHub issueI only have one account and a telnet localhost 4002 gives me a shell as I would expect. Sadly I could not find a way to download and try an older version of the gateway. The current version for linux is 981.3c.
API connection failed: TimeoutError()
---------------------------------------------------------------------------
TimeoutError Traceback (most recent call last)
<ipython-input-10-13991e279071> in <module>
1 con = ib.IB()
----> 2 con.connect('localhost', 4002, clientId=1)
~/.local/lib/python3.8/site-packages/ib_insync/ib.py in connect(self, host, port, clientId, timeout, readonly, account)
269 account: Main account to receive updates for.
270 """
--> 271 return self._run(self.connectAsync(
272 host, port, clientId, timeout, readonly, account))
273
~/.local/lib/python3.8/site-packages/ib_insync/ib.py in _run(self, *awaitables)
308
309 def _run(self, *awaitables: Awaitable):
--> 310 return util.run(*awaitables, timeout=self.RequestTimeout)
311
312 def waitOnUpdate(self, timeout: float = 0) -> bool:
~/.local/lib/python3.8/site-packages/ib_insync/util.py in run(timeout, *awaitables)
320 globalErrorEvent.connect(onError)
321 try:
--> 322 result = loop.run_until_complete(task)
323 except asyncio.CancelledError as e:
324 raise globalErrorEvent.value() or e
~/.local/lib/python3.8/site-packages/nest_asyncio.py in run_until_complete(self, future)
68 raise RuntimeError(
69 'Event loop stopped before Future completed.')
---> 70 return f.result()
71
72 def _run_once(self):
/usr/lib/python3.8/asyncio/futures.py in result(self)
176 self.__log_traceback = False
177 if self._exception is not None:
--> 178 raise self._exception
179 return self._result
180
/usr/lib/python3.8/asyncio/tasks.py in __step(***failed resolving arguments***)
278 # We use the `send` method directly, because coroutines
279 # don't have `__iter__` and `__next__` methods.
--> 280 result = coro.send(None)
281 else:
282 result = coro.throw(exc)
~/.local/lib/python3.8/site-packages/ib_insync/ib.py in connectAsync(self, host, port, clientId, timeout, readonly, account)
1624 try:
1625 # establish API connection
-> 1626 await self.client.connectAsync(host, port, clientId, timeout)
1627
1628 # autobind manual orders
~/.local/lib/python3.8/site-packages/ib_insync/client.py in connectAsync(self, host, port, clientId, timeout)
216 b' ' + self.connectOptions if self.connectOptions else b''))
217 self.conn.sendMsg(msg)
--> 218 await asyncio.wait_for(self.apiStart, timeout)
219 self._logger.info('API connection ready')
220 except Exception as e:
/usr/lib/python3.8/asyncio/tasks.py in wait_for(fut, timeout, loop)
499 # See https://bugs.python.org/issue32751
500 await _cancel_and_wait(fut, loop=loop)
--> 501 raise exceptions.TimeoutError()
502 finally:
503 timeout_handle.cancel()
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:24 (9 by maintainers)
Top Results From Across the Web
Connection raises TimeoutError, but IB gateway is running ...
I only have one account and a telnet localhost 4002 gives me a shell as I would expect. Sadly I could not find...
Read more >How To Disconnect An Existing Connection Of Ib Gateway ...
Connection raises TimeoutError but IB gateway is running and port is open.I only have one account and a telnet localhost 4002 gives me...
Read more >insync@groups.io | Newbie: IB gateway problem
When I try to connect with logging on: >>> ib.connect(host="localhost", port=5000, clientId=1) 2020-04-08 03:13:20,819 ib_insync.client INFO ...
Read more >TWS API v9.72+: Connectivity
Most commonly error 502 will indicate that TWS is not running with the API enabled, or it is listening for connections on a...
Read more >Program cannot connect to interactive broker - Stack Overflow
I use the following class to handle IB connections: ... if not wait: raise TimeoutError('Could not connect to IB gateway') def ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is there a socket connection in CLOSE_WAIT state during the issue?
I noticed that both TWS (on Mac) and IBGateway (in Docker) would set the socket to CLOSE_WAIT state when the connection was opened and wasn’t closed with the
disconnect()
method. It happens even if I use python socket connect to test if the port is open. Even if I close it explicitly.…and it is locked:
After that I have to restart IBGateway / TWS or change the port in settings.
It’s a Java process.