skip to Main Content

On my synology I have this docker container running: https://registry.hub.docker.com/r/mgvazquez/ibgateway/

In the "manual" is says: "In this example you will launch the Interactive Brokers Gateway in paper mode listening on port 4001, and the VNC Server listening on port 5900"

So in the docker container I did the following port mapping:

Local port 32778 to container 5900 and local port 32776 to container 4001. My Synology Nas is 192.168.2.6.

When I connect from my local pc using vnc to 192.168.2.6:32778 it works perfectly.

Now, In my Python script I do:

from ib_insync import *
ib = IB()

# use this instead for IB Gateway
ib.connect('192.168.2.6:32776', 4002, clientId=1)

The 4002 is a socket port setting inside the gateway.

When I run the script I get "Getaddrinfo failed". Does not make sense to me.

What can be the issue here?

2

Answers


  1. First, just for testing, try and use port 4001 directly:

    ib.connect('192.168.2.6:32776', 4002, clientId=1)
    

    Second, check your IB socat service is running, since it is that service which establishes two bidirectional byte streams and transfers data between 4001 and 4002:

    echo "Starting Interactive Brokers Controller" | info
    exec socat TCP-LISTEN:4001,fork TCP:127.0.0.1:4002 2>&1 | info
    

    The Dockerfile registers it.
    Try and add a mapping for port 4002.

    Login or Signup to reply.
  2. according to API document at https://ib-insync.readthedocs.io/api.html#module-ib_insync.ib

    connect use following syntax:

    connect(host='127.0.0.1', port=7497, clientId=1, timeout=4, readonly=False, account='')
    

    host (str) – Host name or IP address.

    port (int) – Port number.

    clientId (int) – ID number to use for this client; must be unique per connection. Setting clientId=0 will automatically merge manual TWS trading with this client.

    timeout (float) – If establishing the connection takes longer than timeout seconds then the asyncio.TimeoutError exception is raised. Set to 0 to disable timeout.

    readonly (bool) – Set to True when API is in read-only mode.

    account (str) – Main account to receive updates for.

    so your code:

    # use this instead for IB Gateway
    ib.connect('192.168.2.6:32776', 4002, clientId=1)
    

    should be changed to:

    # use this instead for IB Gateway
    ib.connect('192.168.2.6', 32776, clientId=1)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search