Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection refused when connecting to IBKR using IB Gateway Container #19

Open
azenakhi opened this issue Sep 18, 2023 · 0 comments
Open

Comments

@azenakhi
Copy link

azenakhi commented Sep 18, 2023

Hello,

I tried to launch a sample to connect to IBKR using IB Gateway Container but I receive this error :

API connection failed: TimeoutError()
Traceback (most recent call last):
File "C:\Python39\lib\asyncio\tasks.py", line 688, in _wrap_awaitable
return (yield from awaitable.await())
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Python39\lib\asyncio\tasks.py", line 490, in wait_for
return fut.result()
asyncio.exceptions.CancelledError

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

python.exe app.py
============

Traceback (most recent call last):
File "C:\Users\KN6353\source\repos\stock-market\app.py", line 5, in
ib.connect('127.0.0.1', 4002, clientId=1)
File "C:\Users\KN6353\source\repos\stock-market.venv\lib\site-packages\ib_insync\ib.py", line 279, in connect
return self._run(self.connectAsync(
File "C:\Users\KN6353\source\repos\stock-market.venv\lib\site-packages\ib_insync\ib.py", line 318, in _run
return util.run(*awaitables, timeout=self.RequestTimeout)
File "C:\Users\KN6353\source\repos\stock-market.venv\lib\site-packages\ib_insync\util.py", line 341, in run
result = loop.run_until_complete(task)
File "C:\Python39\lib\asyncio\base_events.py", line 647, in run_until_complete
return future.result()
File "C:\Users\KN6353\source\repos\stock-market.venv\lib\site-packages\ib_insync\ib.py", line 1748, in connectAsync
await self.client.connectAsync(host, port, clientId, timeout)
File "C:\Users\KN6353\source\repos\stock-market.venv\lib\site-packages\ib_insync\client.py", line 217, in connectAsync
await asyncio.wait_for(self.apiStart, timeout)
File "C:\Python39\lib\asyncio\tasks.py", line 492, in wait_for
raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError

Logs inside IB Gateway Container
======================

ib-gateway-1 | 2023/09/18 06:41:00 socat[167] E connect(5, AF=2 127.0.0.1:4000, 16): Connection refused

App.py
=====

from ib_insync import *

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

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

df = util.df(bars)
print(df)


Thanks for your help !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant