Search code examples
pythondockersynologyinteractive-brokers

Try to reach docker container from python script (Interactive brokers)


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?


Solution

  • 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)