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
First, just for testing, try and use port 4001 directly:
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:The Dockerfile registers it.
Try and add a mapping for port 4002.
according to API document at https://ib-insync.readthedocs.io/api.html#module-ib_insync.ib
connect use following syntax:
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:
should be changed to: