开云体育

ctrl + shift + ? for shortcuts
© 2025 开云体育

Connected to gateway, but no response from API via gateway


 

Hello,

One computer on my LAN is running the IB Gateway and another is running scripts that connect to the IB Gateway. I am able to connect to the gateway, but I am not getting responses from the API:

?curl -v " -d "{"symbol": "GWO","secType": "STK"}"
*?? Trying 192.168.1.10:4002...
* Connected to 192.168.1.10 (192.168.1.10) port 4002 (#0)
POST /v1/api/trsrv/stocks HTTP/1.1
Host: 192.168.1.10:4002
User-Agent: curl/7.74.0
Accept: */*
Content-Length: 26
Content-Type: application/x-www-form-urlencoded
* upload completely sent off: 26 out of 26 bytes

After that, it just sits there waiting for a response. I have got log and API messages visible on the gateway and cannot see any trace of the (supposedly) incoming requests.

The same result with python code (no surprise, I suppose):

import requests
r = requests.post(", data='{"symbol": "GWO","secType": "STK"}')

No connection errors, but it just sits there.

The configuration of the IB Gateway (v.10.12):

- All default except that "Allow connections from localhost only" has been disabled, and I have added the client machine to the Trusted IPs list.

Gateway network and firewall:

inet 192.168.1.10/24 brd 192.168.1.255 scope global noprefixroute enp2s0

$ sudo ufw status
Status: active

To???????????????????????? Action????? From
--???????????????????????? ------????? ----
22/tcp???????????????????? ALLOW?????? Anywhere
80/tcp???????????????????? ALLOW?????? Anywhere
443/tcp??????????????????? ALLOW?????? Anywhere
4002?????????????????????? ALLOW?????? Anywhere
4001?????????????????????? ALLOW?????? Anywhere
4000?????????????????????? ALLOW?????? Anywhere
22/tcp (v6)??????????????? ALLOW?????? Anywhere (v6)
80/tcp (v6)??????????????? ALLOW?????? Anywhere (v6)
443/tcp (v6)?????????????? ALLOW?????? Anywhere (v6)
4002 (v6)????????????????? ALLOW?????? Anywhere (v6)
4001 (v6)????????????????? ALLOW?????? Anywhere (v6)
4000 (v6)????????????????? ALLOW?????? Anywhere (v6)

Client machine network and firewall:

inet 192.168.1.106/24 brd 192.168.1.255 scope global noprefixroute wlp0s20f3

$ sudo ufw status
Status: active

To???????????????????????? Action????? From
--???????????????????????? ------????? ----
22/tcp???????????????????? ALLOW?????? Anywhere
59000????????????????????? ALLOW?????? Anywhere
4002?????????????????????? ALLOW?????? Anywhere
22/tcp (v6)??????????????? ALLOW?????? Anywhere (v6)
59000 (v6)???????????????? ALLOW?????? Anywhere (v6)
4002 (v6)????????????????? ALLOW?????? Anywhere (v6)

Log and ini-file enclosed.

Any help much appreciated.

Best regards,

Eric Eikrem


Nick
 

开云体育

Um, the TWS API is not a web server or http based at all. It uses a custom protocol, http is not going to work.

I am not a python expert so I apologize if your example is running a python TWS API library rather than http.


On 3/9/2022 9:57 AM, Eric Eikrem via groups.io wrote:

r = requests.post(, data='{"symbol": "GWO","secType": "STK"}')


 

Are you sure you are using the correct gateway, Eric? It feels like you are trying to make "Client Portal API" calls to the ":TWS API Gateway".

The Client Portal API comes with its own little gateway and generally uses port 5000. Here a link to the section of the Client Portal API,

闯ü谤驳别苍