Broker API HubMenu

Interactive Brokers TWS API message code

Interactive Brokers API error 502: cannot connect to TWS

The error, as text you can copy

502
Kind
TWS API message code
Where you meet it
In the TWS API, not in the Web API and not in an HTTP status
API
Interactive Brokers

What does 502 (cannot connect to tws) mean on the Interactive Brokers API?

Couldn't connect to TWS. Confirm that 'Enable ActiveX and Socket Clients' is enabled. The API is not enabled in TWS or the wrong port was used.

Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.

Independent and unofficialinteractivebrokers.github.iochecked

How do I fix 502 (cannot connect to tws)?

Enable ActiveX and Socket Clients in TWS API settings and check the port (TWS or Gateway, live or paper).