hackingthemarkets / tradingview-interactive-brokers

TradingView Interactive Brokers Integration using Webhooks
149 stars 58 forks source link

ib.connect() returns connect call failed error #5

Closed abhayarathore closed 1 year ago

abhayarathore commented 1 year ago

I tried your code, with the same instructions as in the video, installed virtual environment for VS Code and WSL, ran webapp and the file, but it fails to connect. Please advise and solve the problem. This was the error message

API connection failed: ConnectionRefusedError(111, "Connect call failed ('127.0.0.1', 7497)")
Make sure API port on TWS/IBG is open
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 187, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.10/runpy.py", line 110, in _get_module_details
    __import__(pkg_name)
  File "/mnt/c/users/r s rathore/downloads/bot files/tradingview-interactive-brokers-main/trendbot.py", line 15, in <module>
    app.connect(host="127.0.0.1", port=7497, clientId=1)
  File "/mnt/c/users/r s rathore/downloads/bot files/tradingview-interactive-brokers-main/ib_insync/ib.py", line 269, in connect
    return self._run(self.connectAsync(
  File "/mnt/c/users/r s rathore/downloads/bot files/tradingview-interactive-brokers-main/ib_insync/ib.py", line 308, in _run
    return util.run(*awaitables, timeout=self.RequestTimeout)
  File "/mnt/c/users/r s rathore/downloads/bot files/tradingview-interactive-brokers-main/ib_insync/util.py", line 341, in run
    result = loop.run_until_complete(task)
  File "/mnt/c/users/r s rathore/downloads/bot files/tradingview-interactive-brokers-main/nest_asyncio.py", line 90, in run_until_complete
    return f.result()
  File "/usr/lib/python3.10/asyncio/futures.py", line 201, in result
    raise self._exception.with_traceback(self._exception_tb)
  File "/usr/lib/python3.10/asyncio/tasks.py", line 232, in __step
    result = coro.send(None)
  File "/mnt/c/users/r s rathore/downloads/bot files/tradingview-interactive-brokers-main/ib_insync/ib.py", line 1674, in connectAsync
    await self.client.connectAsync(host, port, clientId, timeout)
  File "/mnt/c/users/r s rathore/downloads/bot files/tradingview-interactive-brokers-main/ib_insync/client.py", line 211, in connectAsync
    await asyncio.wait_for(self.conn.connectAsync(host, port), timeout)
  File "/usr/lib/python3.10/asyncio/tasks.py", line 445, in wait_for
    return fut.result()
  File "/usr/lib/python3.10/asyncio/futures.py", line 201, in result
    raise self._exception.with_traceback(self._exception_tb)
  File "/usr/lib/python3.10/asyncio/tasks.py", line 234, in __step
    result = coro.throw(exc)
  File "/mnt/c/users/r s rathore/downloads/bot files/tradingview-interactive-brokers-main/ib_insync/connection.py", line 39, in connectAsync
    self.transport, _ = await loop.create_connection(
  File "/usr/lib/python3.10/asyncio/base_events.py", line 1064, in create_connection
    raise exceptions[0]
  File "/usr/lib/python3.10/asyncio/base_events.py", line 1049, in create_connection
    sock = await self._connect_sock(
  File "/usr/lib/python3.10/asyncio/base_events.py", line 960, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/lib/python3.10/asyncio/selector_events.py", line 500, in sock_connect
    return await fut
  File "/usr/lib/python3.10/asyncio/futures.py", line 285, in __await__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.10/asyncio/tasks.py", line 304, in __wakeup
    future.result()
  File "/usr/lib/python3.10/asyncio/futures.py", line 201, in result
    raise self._exception.with_traceback(self._exception_tb)
  File "/usr/lib/python3.10/asyncio/selector_events.py", line 535, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('127.0.0.1', 7497)