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.
If you have a general question, it may already be covered in our FAQs. If you have an account-specific question or concern, please reach out to Client Services.
2 thoughts on “Diagnosing Issues and Troubleshooting with the TWS API”
Anonymous August 13, 2023 at 6:12 am“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
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.
Throughout the lesson, please keep in mind that the examples discussed 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.
CFA Institute allows its members the ability to self-determine and self-report professional learning (PL) credits earned from external sources. CFA Institute members are encouraged to self-document such credits in their
Online PL Tracker.
This form is aimed at answering questions about this lesson only. If you have questions about your Interactive Brokers account please contact Customer Service.
Get updates on podcasts, webinars, courses, and more from our IBKR pillars.
View the latest financial news articles from the top voices in the industry.
Get updates on podcasts, webinars, courses, and more from our IBKR pillars.
For those wanting to trade markets using computer-power by coders and developers.
Hear about the latest tools and techniques from our own IBKR API staff.
© 2024 Interactive Brokers, LLC
The risk of loss in online trading of stocks, options, futures, forex, foreign equities, and fixed income can be substantial. Before trading, clients must read the relevant risk disclosure statements on IBKR's Warnings and Disclosures page.
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.
Securities or other financial instruments mentioned in the material posted are not suitable for all investors. The material posted does not take into account your particular investment objectives, financial situations or needs and is not intended as a recommendation to you of any particular securities, financial instruments or strategies. Before making any investment or trade, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice. Past performance is no guarantee of future results.
Any information provided by third parties has been obtained from sources believed to be reliable and accurate; however, IBKR does not warrant its accuracy and assumes no responsibility for any errors or omissions.
Any information posted by employees of IBKR or an affiliated company is based upon information that is believed to be reliable. However, neither IBKR nor its affiliates warrant its completeness, accuracy or adequacy. IBKR does not make any representations or warranties concerning the past or future performance of any financial instrument. By posting material on IBKR Campus, IBKR is not representing that any particular financial instrument or trading strategy is appropriate for you.
Any trading symbols displayed are for illustrative purposes only and are not intended to portray recommendations.
Please note that any advertisement has not been reviewed by the Monetary Authority of Singapore.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply. If you have any questions or comments, or are interested in becoming a contributor to the IBKR Campus, please contact us here.
Is a member NYSE - FINRA - SIPC and regulated by the US Securities and Exchange Commission and the Commodity Futures Trading Commission. Headquarters: One Pickwick Plaza, Greenwich, CT 06830 USA.
Website: www.interactivebrokers.com
Is a member of the Investment Industry Regulatory Organization of Canada (CIRO) and Member - Canadian Investor Protection Fund. Registered Office: 1800 McGill College Avenue, Suite 2106, Montreal, Quebec, H3A 3J6, Canada.
Website: www.interactivebrokers.ca
ABN 98 166 929 568 is licensed and regulated by the Australian Securities and Investments Commission (AFSL: 453554) and is a participant of ASX, ASX 24 and Cboe Australia. Registered Office: Level 11, 175 Pitt Street, Sydney, New South Wales 2000, Australia.
Website: www.interactivebrokers.com.au
Is regulated by the Hong Kong Securities and Futures Commission, and is a member of the SEHK and the HKFE. Registered Office: Suite 1512, Two Pacific Place, 88 Queensway, Admiralty, Hong Kong SAR.
Website: www.interactivebrokers.com.hk
Is a trading member of NSE, BSE, and depository participant of NSDL. SEBI Registration No. INZ000217730; NSDL: IN-DP-602-2021. CIN-U67120MH2007FTC170004. Registered Office: 502/A, Times Square, Andheri Kurla Road, Andheri East, Mumbai 400059, India. Phone: +91-22-61289888 | Fax: +91-22-61289898.
Website: www.interactivebrokers.co.in
Is regulated by Kanto Local Finance Bureau (Registration No.187) and is a member of Japan Securities Dealers Association and The Commodity Futures Association of Japan. Registered Office: Kasumigaseki Building 25F, 2-5 Kasumigaseki 3-chome, Chiyoda-ku, Tokyo, 100-6025 Japan. Phone: +81 (0)3-4588-9700 (On business days from 8:30-17:30 JST).
Website: www.interactivebrokers.co.jp
Is licensed and regulated by the Monetary Authority of Singapore (Licence No. CMS100917). Registered Office: #40-02A, Asia Square Tower 1, 8 Marina View, Singapore 018960.
Website: www.interactivebrokers.com.sg
This website uses cookies to collect usage information in order to offer a better browsing experience. By browsing this site or by clicking on the "ACCEPT COOKIES" button you accept our Cookie Policy.