gnzsnz / ib-gateway-docker

Docker image with IB Gateway/TWS and IBC
https://github.com/users/gnzsnz/packages/container/package/ib-gateway
MIT License
274 stars 50 forks source link

Gatweay Port Hangs #123

Closed Al4ise closed 5 months ago

Al4ise commented 5 months ago

Describe the bug

The docker image runs well, the terminal logs no errors as far as I have seen (I will attach a log just in case). But when I do a "curl -X GET "localhost:$port", the command hangs. I am sure I am using the right port as when I mistake the live for the paper port (or vice versa), the command returns an error.

Note: I am using a custom image, but it is based on the latest stable with the only difference being that I installed curl for healthcheck purposes. I may be missing something really simple, perhaps something firewall related? I haven't touched firewall settings. But I just can't figure it out. Any help would be appreciated.

docker-compose.yaml:

image

.env:

image

(username and password are filled in when running, the rest are as is)

I build the project with 'docker compose up'

Expected

The second package is a python app that calls the TWS API. I need the ib-gateway to make the api available so the healthcheck passes and the app connects to the API.

Container logs

logs.txt## Versions

Please complete the following information:

Additional context

Add any other context about the problem here.

What have you tried and failed. I have tried stable/latest branches I have tried accessing the port from outside of the container, same result. I have tried accessing the port from inside of the container, same result. I have tried using a paper account instead of a live one (ports adjusted), same result. I have tried using 127.0.0.1:4001:4003 instead of 4001:4003.

gnzsnz commented 5 months ago

Hi,

not shure what's your expectation, why would "curl -X GET "localhost:$port/v1/api/one/user" work, this is not a RESTfull API.

I just did a quick test on my running TWS instance and ports are working.

image

if you need a healthcheck(which just is telling you that the port is open, but not that is actually working) you can use that

this is how it would look like on ib-gateway with the port down (ibgateway is not running)

image

something like this to have it working as a docker healthcheck

HEALTHCHECK --interval=30m --timeout=15s --start-period=10s \
  CMD timeout 1 bash -c '</dev/tcp/0.0.0.0/4001 && echo "TWS API up" || echo "TWS API down"' || echo "Connection timeout"

take into account that any disconnection to IBKR server farm will not be reported by this health check. I use ib_async and disconnectedEvent to keep TWS api connectivity.

hope this helps

Al4ise commented 5 months ago

Hm, yeah thanks for the healthcheck, I could see it being useful. And thanks for the answer, I figured it out. I wasn't managing my connection IDs correctly.