The TWS API is Interactive Brokers' main way to automate trading through code instead of clicking buttons. It's a TCP socket connection that lets you place orders, get market data, and manage your account programmatically. Been around for over 20 years and used by hedge funds and retail traders who want to run algorithms.
How It Actually Works
You need either TWS (the full trading platform) or IB Gateway (lightweight headless version) running on your machine. Both are Java apps that connect to IB's servers and give you an API to talk to them. Most production systems use Gateway because it's more stable and doesn't eat as much RAM.
The connection works through two classes: EClient sends your requests (orders, data requests) and EWrapper handles responses (market data, order fills, errors). It's all async callbacks, so your code will look like callback hell unless you use a wrapper library.
Language Support Reality Check
IB officially supports Python, Java, C++, C#, and VB. Here's the actual story:
Python is by far the most popular because pandas makes everything easier. The official client is okay but most people use ib_insync which wraps the callback hell in a sane async interface. There's also ib_async as a maintained alternative and community examples.
Java works best since TWS itself is Java. You get the newest features first and fewer weird bugs. But it's Java, so enjoy writing 50 lines for what Python does in 5.
C++ is fast but the API wrapper is a pain in the ass. Only worth it for high-frequency stuff where microseconds matter. Memory management will bite you.
C# is fine for Windows shops. Pretty much identical to Java in terms of features but less community support.
VB exists but why would you torture yourself?
Real Problems You'll Face
UPDATE January 2025: IB just changed the rate limiting rules. The old 50 message per second limit is now based on your Market Data Lines divided by 2. If you have 100 market data lines, you get 50 messages per second. More lines = higher limits, which is actually better for serious traders.
But here's the kicker - most retail accounts start with 100 market data lines, so you're still stuck at that 50 msg/sec bottleneck. Historical data requests eat into this limit aggressively.
TWS will disconnect randomly and give you error 1100 which tells you nothing useful. Connection monitoring is mandatory - not optional. Lost a production system for 6 hours on a Friday because the connection died at 2am and nobody noticed until markets opened. Error 1100 just means "shit broke" - could be network, could be TWS crashed, could be IB's servers having a bad day.
Paper trading fills are instant but live fills take time. Your backtests will lie to you about slippage and fill rates. Also, paper trading uses different market data feeds so prices can be off.
Market data costs add up fast. "Real-time" feeds are $1-50/month per exchange and professional user fees are way higher. Budget at least $100/month if you're serious about this.
The Java requirement means TWS Gateway needs significant RAM. Plan for 2-4GB just for the gateway, more if you're pulling lots of market data. On AWS that's money.