In a Java client, error 507 or an end-of-stream message can indicate that the socket connection broke. Check whether TWS closed, restarted, or rejected a competing client. Restore state before retrying business actions.
Educational software guidance. Trading involves risk. Read the financial and information disclaimers.
Step by step
- 1 Save the full app message first. To check a recorded TWS API log, open Help → Troubleshooting → Diagnostics → API Logs. Select its date and choose View Logs. If the list is empty, enable API logging before the next event.
- 2 Compare the socket error time with TWS restarts and shutdowns.
- 3 Open Help → Data Connections and check the API Connections list for another client using the same ID. Compare this with the app log; an empty list does not explain an earlier disconnect.
- 4 Bring TWS back to a fully logged-in state if needed.
- 5 Reconnect the intended app once and wait for account initialization.
- 6 Compare working orders, fills, and positions before allowing new signals.
A practical example
Suppose TWS restarts while a Java app is still reading from its socket. The app may see the stream end and report 507. That does not tell you whether the last trade request reached the broker before the break. Bring the link back, then compare orders and fills with the last alert. Fixing the link and deciding whether to resend are two separate tasks.
Screen reference




Mistake to avoid
Common questions
Is this the same in every programming language?
The reported code or exception can differ between API implementations.
Can I just resend the last trade?
First confirm whether that trade was accepted before the disconnect.