Cannot connect to TWS API
Closed this issue · 14 comments
Hi
My docker-compose setup of TWS:
Container is successfully created and I can open TWS and see trades etc:
I'm trying connect to TWS using provided EClientSocket from TWS API. Using host: ikbr, port: 8888 (tried use host as localhost, 127.0.0.1, host.docker.internal etc. nothing helped):
I am not getting any error but IsConnected() method at line 42 all time returning me false.
In ikbr container logs I can see thet connection to 127.0.0.1:7496 is refused:
What I'm doing wrong?
Try adding IBC_AcceptIncomingConnectionAction: accept
to the environment
key:
ibkr:
image: ghcr.io/extrange/ibkr:stable
ports:
- 6080:6080
- 8888:8888
restart: always
ulimits:
nofile: 10000
environment:
IBC_AcceptIncomingConnectionAction: accept
@extrange Trusted APIs must be provided in global configuration. How to do this via env in docker?
That's strange, I'm using ib_insync
and I have no problems connecting to the API, I'm not sure if this could be an issue with the C# library you're using.
You didn't specify IBC_TradingMode
- by default, live
is used - is your username and password for a live account?
What do you mean by trusted APIs - do you mean trusted incoming connections?
Ok. By default, the paper account is used (even if a live username is provided). Can you add the following to your config and try again?
GATEWAY_OR_TWS: tws
IBC_TradingMode: live
socat
in the container will forward the API connection automatically, so external connections will appear as localhost
to TWS. There is therefore no need to specify trusted IPs.
Can you run the following and paste the output?
docker exec $(docker ps | awk '/ibkr/ {print $1}') bash -c 'apt-get install -qy iproute2 && ss -antp'
State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0 5 0.0.0.0:5900 0.0.0.0:* users:(("Xvnc",pid=7,fd=8))
LISTEN 0 5 0.0.0.0:8888 0.0.0.0:* users:(("socat",pid=10,fd=5))
LISTEN 0 4096 127.0.0.11:33375 0.0.0.0:*
LISTEN 0 100 0.0.0.0:6080 0.0.0.0:* users:(("python3",pid=19,fd=3))
CLOSE-WAIT 271 0 172.19.0.3:57548 96.16.54.170:443 users:(("java",pid=45,fd=65))
TIME-WAIT 0 0 172.19.0.3:57612 8.17.22.31:4000
TIME-WAIT 0 0 172.19.0.3:48766 146.75.118.132:80
ESTAB 0 0 172.19.0.3:59032 8.17.22.31:4001 users:(("java",pid=45,fd=61))
ESTAB 0 0 172.19.0.3:57640 8.17.22.31:4000 users:(("java",pid=45,fd=60))
ESTAB 0 0 172.19.0.3:59722 96.16.54.168:443 users:(("java",pid=45,fd=30))
TIME-WAIT 0 0 172.19.0.3:45700 64.190.197.40:4001
FIN-WAIT-2 0 0 172.19.0.3:55570 103.38.91.3:4001
CLOSE-WAIT 271 0 172.19.0.3:57558 96.16.54.170:443 users:(("java",pid=45,fd=66))
TIME-WAIT 0 0 172.19.0.3:45726 64.190.197.40:4001
LISTEN 0 5 [::]:5900 [::]:* users:(("Xvnc",pid=7,fd=9))
When using tws (default) then the '''Enable Active and Socket Clients''' option needs to be checked under '''File>Global Configuration...>API'''.
Then it works. Not sure if this can be set as environment variable....
Yup, that's correct. Specifically this needs to be ticked (Enable ActiveX and Socket Clients
)
Unfortunately, IBCAlpha
does not do this (issue). At this point, I'm afraid you'll have to manually set it, or otherwise use IBGateway (it automatically has the API enabled).
Closing this issue, as it is out of scope for this repository.
Unfortunately, IBCAlpha does not do this (IbcAlpha/IBC#120). At this point, I'm afraid you'll have to manually set it, or otherwise use IBGateway (it automatically has the API enabled).
How should I manually set ? Using VNC UI?
Yup, on the VNC web client at localhost:6080
. To persist it, you can volume mount the resulting ibg.xml
in /root/Jts/<long random string>
.