- Solve real problems with our hands-on interface
- Progress from basic puts and calls to advanced strategies
Lesson 6 of 6
It is important to remember that the TWS API is an interface or an extension of TWS and IB Gateway. When troubleshooting issues with the Excel samples or other API applications, it is important to check the corresponding TWS functions. The TWS can be used as a reference for the expected behavior of the API application, or to check if a legitimate issue stems from the TWS itself. Additionally, when working with API applications, it is important to monitor error messages and gather diagnostics files and logs. These topics will all be covered in this video.
Example Case
Say you are requesting:

With these parameters, you may assume that the last daily bar returned would have a time stamp of 20200907.

However, the timestamp of the last bar is “20200904”.To check why the response is not what’s expected, we can review the corresponding TWS function. In this case, the API historical bars function corresponds to TWS bar charts.
In our shifted graph, locate the bar with date 202009. Then, let’s count 3 day bars going back starting with 20200909.
In a TWS chart, if we try to count 3 bars at this date, the last bar is also 20200904 and there is no bar for 0907.

You have now confirmed the TWS shows the same results. To take it a step further and see if this is expected TWS behavior, you could check the IBKR trading schedule and found that trading was closed on 0907.
Error messages and Notifications
When an API function does not produce the expected results, the first thing to check for are error messages. Whenever a request is made to TWS by the API, some sort of response is usually expected, whether it is account management, market data, or an error message. Although there can be an issue that causes the TWS to never return a response to the API, it is fairly uncommon.
The API returns error messages via the error callback function. As with most callback functions, each message has a “reqId” or request Id associated with it. This ID will allow you to associate the error with a specific request, whether it be a placed order, a request for market data, etc.
Let’s go back to our first scenario where we were requesting historical data for IBKR via the DDE sample.
Now, let’s intentionally send an incorrect request.
Log files and Diagnostics

Now let’s click on Apply and Ok, and advanced API logging is enabled from this point forward.
After an issue occurs, the log files can be reviewed by either the client or an API support representative.
However, an important concept in the API logs is that a left arrow indicates an outbound message or request being sent from the API to TWS, and a right arrow is a message being returned by TWS to the API.
This covers the major concepts of issue diagnosing and troubleshooting. IBKR support representatives can help with further questions.
Please note that the API can help troubleshoot issues and review log files, however it cannot provide programming assistance or troubleshoot local operating system issues.
The topics discussed here are also documented in our API support page.
For specific platform feedback and suggestions, please submit it directly to our team using these instructions.
If you have an account-specific question or concern, please reach out to Client Services.
We encourage you to look through our FAQs before posting. Your question may already be covered!
The analysis in this material is provided for information only and is not and should not be construed as an offer to sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad-based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation by IBKR to buy, sell or hold such investments. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.
The views and opinions expressed herein are those of the author and do not necessarily reflect the views of Interactive Brokers, its affiliates, or its employees.
Please keep in mind that the examples discussed in this material are purely for technical demonstration purposes, and do not constitute trading advice. Also, it is important to remember that placing trades in a paper account is recommended before any live trading.
“A client may view their logs by going to the menu Account, Diagnostics, then choose either the TWS logs or the API logs.”
This statement is incorrect, Cant see Diagnostics in Account menu at all
Hello Anonymous, thank you for reaching out. Please review this user guide page, which will provide more information on API Log Files: https://interactivebrokers.github.io/tws-api/support.html#tws_logs
TWS API not liable with visual studio 2022/64b windows 11 with very last comp. No way to reach tws on toolbox, no way Good job Bande de fils de putes
Please create a web ticket for this inquiry; we have a category specifically for “API.” One of our API experts will be happy to guide you! https://spr.ly/IBKR_ClientServicesCampus