Error messages

TWS error 507 or EOF: the API socket closed

Quick answer

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. 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. 2 Compare the socket error time with TWS restarts and shutdowns.
  3. 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. 4 Bring TWS back to a fully logged-in state if needed.
  5. 5 Reconnect the intended app once and wait for account initialization.
  6. 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.

Illustrative scenario, not a record of a trade placed during this review.

Screen reference

TWS View Logs dialog with View Logs, Export Logs and Export Today Logs buttons
This session has no recorded API logs in the list, so export buttons are disabled. Enable API logging before the event you need to capture. No log was exported or uploaded for this screenshot. Captured in TWS paper mode on 3 October 2026. Open the image for full size.
Help, Troubleshooting, Diagnostics menu leading to API Logs
In this build, follow Help → Troubleshooting → Diagnostics → API Logs. Upload Diagnostics is a different action. Captured in TWS paper mode on 3 October 2026. Open the image for full size.
TWS Market Data Connections with farm purpose and status, plus API client columns
The observed services are connected and the API client list is empty. Use this panel to read current status; it does not reproduce a disconnect or prove an app handshake completed. Captured in TWS paper mode on 3 October 2026. Open the image for full size.
TWS Lock and Exit settings showing lock and restart controls
Compare the configured time and selected restart or logoff mode. Availability can differ by account entity. Captured in TWS paper mode on 3 October 2026. Open the image for full size.
How to confirm the result The app should reconnect cleanly and agree with the broker’s current state.

Mistake to avoid

The word Bad Message in this context does not automatically mean your TradingView JSON is invalid.

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.

Financial and information disclaimers

Financial disclaimer

These guides explain software. They are for education, not financial, investment, tax, or legal advice. No example is a suggestion to buy or sell a product or use a trading strategy. Trading can lose money, including all funds you put at risk. With margin, futures, short sales, or some options, losses can exceed your starting funds. Automation can fail, send duplicate orders, or act late. Stops do not guarantee a fill or a price. Review your orders and positions, and seek advice from a qualified professional for your own needs. Paper trades, examples, and past results do not predict live results or promise a profit.

Information disclaimer

This is general help based on the sources and check date shown on the page. Screens, settings, fees, data access, and product support can change or differ by app version, account, country, and broker. The content may contain errors or become out of date; accuracy, completeness, and continuous service are not guaranteed. Check current broker and app instructions before acting. Screenshots show where controls are; they do not prove that an order test passed. This guide does not replace broker terms or risk notices. References to IBKR and TradingView identify their products and do not imply their endorsement of this guide.

IBKR risk disclosures · IBKR paper-trading limits · SEC guidance on automated investment tools

PickMyTrade help · Independent guidance for Trader Workstation and the desktop integration. TWS images show paper trading. Other applications are named in the image captions. Settings and availability can vary by version and account.

Automate TradingView alerts to Interactive Brokers

See the IBKR integration