Close Navigation

Downloading & Installing the TWS API

Lesson 3 of 11

Duration 7:25
Level Intermediate

To watch this video you must accept functional cookies.

Welcome to this lesson on Downloading & Installing the TWS API. In this lesson, we will be moving through the process of initially downloading and installing the TWS API. We will also include unique setup instructions for the Python packages.

The API source code serves the purpose of defining the available messages which can be exchanged between TWS and an external API application. The messages are exchanged via a TCP socket connection and most commonly use a subscribe-and-publish, or “pub/sub” pattern in which a message is sent from an API client to subscribe to a particular type of data, after which TWS will publish updates about that data type as it occurs in real-time. The API source code also helps to translate those lower-level messages into a higher form which are more convenient for programmers.

The TWS API downloads and guides can be found on our IBKR Campus website, under the TWS API documentation section. Much like how we downloaded the Trader Workstation, we can now select the Download the TWS API section, followed by the TWS API Download Page button. Clicking the button directs users to the TWS API Non-Commercial License Agreement. After agreeing to the license, users can download the Stable or Latest releases for their affiliated operating system.

To use the TWS API in Python, you will need to download one of our supported releases, stable or latest, available on this page. The API is receiving constant support, and so we would encourage users to regularly check this page for new releases.

Please be aware that this tutorial assumes users are comfortable with programming in Python, or their language of choice. In addition, this series is predicated with the idea customers are familiar with navigating their operating system’s respective terminal. Users should look to resolve any difficulties with these topics with external resources before proceeding further.

You’ll notice that there are separate downloads on left and right for Windows and for Mac/Unix. The API source code is identical in the Windows and Mac/Linux distributions.

Windows Installation

For Windows installations, users can simply click “IBKR Latest for Windows” to download the initial MSI file. After the download is completed, you will likely be able to find the installer directly through your browser. Clicking the file will begin the install wizard, which can walk users through the full installation steps. The following steps will require administrative rights for Windows users to execute our MSI file. So, if your computer is managed by your company or school, please be aware that you may need to consult your IT group for the initial installation. Unless necessary, Interactive Brokers would encourage users to follow the default installation parameters. As such, we can simply click “Next” to proceed through the destination confirmations. After we proceed through the remaining prompts, we will receive a message confirming the successful installation.

Mac/Linux Installation

The process for installing the API on Unix machines is a bit different. While the initial download steps are the same, users will see that Unix operates with a zip file rather than an installation file. I would note that instead of an install wizard, we will be moving through the installation steps using the terminal. With a terminal launched, I can change directory to my downloads folder, and unzip the file with:

‘unzip twsapi_macunix.{major}{minor}.{micro}.zip’.

This will unzip the file and allow me to work with the file’s content.

Python-Specific Setup

Then, using either Windows or a Unix machine, I will need to change directory to my new TWS API or IBJts folder. Please be aware these steps must be followed using Command Prompt or Terminal for either machine. Here I will find a samples and source directory. For our Python tutorial, let’s move into the source directory, then under pythonclient. This should leave our present working directory to {TWS API}\source\pythonclient\. In our python source, we should see a setup.py file. This file must be run to apply the latest Python updates to your IDE and install all relevant libraries for TWS API.

To run this file, let’s type python setup.py install.

This will run the setup.py file with the command to install the appropriate content. After a few moments, we should see our installation complete.

To confirm successful installation, we can run python -m pip show ibapi to show the currently installed release. If our setup.py worked correctly, we should see the Version match the same release as the website. In my case, I can see 10.29 matching in both locations.

As a validation step before we start writing our own code, let’s execute one of our test programs bundled with the API installation. If we change our directory to C:\TWS API\samples\Python\Testbed, we should see several programs included here.

I will run $ python Program.py –port 7497 to execute the Program.py file. If the Port argument is not passed, the program will attempt to run on port 7496 by default. If everything is working correctly, we should see contract requests submitted for several instruments along with working through different test cases.

With those steps complete, we should be fully ready to proceed through the remaining lessons in this series. Customers facing any difficulties with the installation steps should contact Interactive Brokers customer support for more information.

Join The Conversation

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!

115 thoughts on “Downloading & Installing the TWS API”

  • Anonymous

    Why there are no specific guidance on how to install the API? I downloaded it but do not know what to do with the downloaded file folder. I have to search the website, try the errors and try to install and solve all the installation issues. Here is a guidance I found: https://www.interactivebrokers.com/campus/ibkr-quant-news/interactive-brokers-python-api-native-a-step-by-step-guide/#:~:text=Download%20the%20IB%20Python%20native%20API,-You%20can%20download&text=Run%20the%20downloaded%20msi%20file,TWS%20API%2Fsource%2Fpythonclient.. Please include the steps in to the video, so a newbie could really establish TWS API and build the connection to start.

    • Interactive Brokers

      Hello Anonymous, we are sorry to learn that your experience has been unsatisfactory. Our API experts would be glad to help you out! Please create a web ticket for this inquiry and select “API” as the category: https://www.interactivebrokers.com/sso/resolver?action=NEW_TICKET. We hope this helps! Once again, please accept our apologies.

  • Lily

    Why there are no specific guidance on how to install the API? I downloaded it but do not know what to do with the downloaded file folder. I have to search the website, try the errors and try to install and solve all the installation issues. Here is a guidance I found:
    https://www.interactivebrokers.com/campus/ibkr-quant-news/interactive-brokers-python-api-native-a-step-by-step-guide/#:~:text=Download%20the%20IB%20Python%20native%20API,-You%20can%20download&text=Run%20the%20downloaded%20msi%20file,TWS%20API%2Fsource%2Fpythonclient.. Please include the steps in to the video, so a newbie could really establish TWS API and build the connection to start.

    • Interactive Brokers

      Hello Lily, we are sorry to learn that your experience has been unsatisfactory. Our API experts would be glad to help you out! Please create a web ticket for this inquiry and select “API” as the category: https://www.interactivebrokers.com/sso/resolver?action=NEW_TICKET. We hope this helps! Once again, please accept our apologies.

  • Lily

    After downloading the file folders, how to install? There is no specific guidance at all. Then it jumped to “After install,….” It is hard for newbies to figure out the installation steps.

    • Interactive Brokers

      Hello Lily, thank you for reaching out. You can run the downloaded msi file and go through the setup wizard. This will copy the required Python source files to your hard drive. Once completed, navigate over to the directory that you specified in the installer and drill down to this directory – /TWS API/source/pythonclient. In this folder, run the python3 setup.py install file to install the API as a package. You should make sure to select API version 9.73 or higher because any prior versions do not have the Python source files needed. Also ensure that you are using Python 3.1 or higher. You can also create a web ticket for this inquiry and select “API” as the category, and our API experts would be happy to help. https://www.interactivebrokers.com/sso/resolver?action=NEW_TICKET.

  • gordon0888

    why always show “Error: {‘reqId’: 16777217, ‘errorCode’: 10089, ‘errorString’: “Requested market data requires additional subscription for API. See link in ‘Market Data Connections’ dialog for more details.Delayed market data is available.GOOG NASDAQ.NMS/TOP/ALL”, ‘advancedOrderRejectJson’: ”}
    {‘reqId’: 16777217, ‘errorCode’: 10089, ‘errorString’: “Requested market data requires additional subscription for API. See link in ‘Market Data Connections’ dialog for more details.Delayed market data is available.GOOG NASDAQ.NMS/TOP/ALL”, ‘advancedOrderRejectJson’: ”}”

  • Luke

    Dealbreaker, realtime undelayed market data should be free. I’ll use alpaca instead. Was hoping to algo trade with IB cause its more established. Please reply if IB ever makes it free.

  • Bastian

    Hello whenever I try to install the setup.py in the CMD than i get this issue: C:\TWS API\source\pythonclient>python setup.py install Traceback (most recent call last): File “C:\TWS API\source\pythonclient\setup.py”, line 6, in from setuptools import setup ModuleNotFoundError: No module named ‘setuptools’ WHenever I open the setup.py, then I see this: # from distutils.core import setup from setuptools import setup from ibapi import get_version_string but when I scroll over setuptools then i read this: Import “setuptools” could not be resolved from sourcePylancereportMissingModuleSource (module) setuptools What am I missing, what can I do? Thanks

    • New

      how did you solve this problem? Thx

      • Bob

        Running “pip install .” worked for me. Run this from the same directory rather than “python setup.py install”

        • Chris

          I had to run pip install setuptools (to install setuptools from pip), then python setup.py install (to install local libraries from download). I was using a virtual environment, don’t know it this is why I needed to install setuptools first

  • Bastian

    Problem solved. Thx Bastian

  • Anonymous

    on IB Traders’ Academy(Downloading & Installing the TWS API) I followed the video until 5:25 C:\TWS API\source\pythonclient>python setup.py install Traceback(most recent call last):File “C:\TWS API\source\pythonclient\setup.py”,line 6, in from setuptools import setup ModuleNotFoundError:No module named’setuptools i installed Python3.12 64bit on my computer earlier. How can I resolve this problem?

    • Interactive Brokers

      Hello, thank you for reaching out. If setuptools is not installed with Python by default, you will likely need to download the library using a tool such as pip. Assuming pip is installed correctly, you should be able to call pip install setuptools which will download the library to your environment and allow you to run the setup.py file appropriately. We hope this helps!

      • Bart D

        @IBKR: You should include this in the video. setuptools is not installed by default on Mac. I had the same issue.

  • Anonymous

    Thanks for your prebious helpful message. on IB Traders’ Academy(Downloading & Installing the TWS API) I followed the video until 6:33. python Program.py–port 7497 Using args Namespace(port=7497,global_cancel=False)ERROR -1 502 Couldn’t connect to Tws. Confirm that “Enable ActiveX and Socket Eclients”is enabled and connection port is the same as “Socket Port” on theTWS “Edit->Global Configuration…->API->Settings” menu. Live Trading ports:TWS: 7496: IB Gateway:4001.Simulated Trading ports for new installations954.1 or newer:TWS:7497:IB Gateway:4002of versionError. Id:-1 Code: 502 Msg: Couldn’t connect to Tws. Confirm that “Enable ActiveX and Socket Eclients”is enabled and connection port is the same as “Socket Port” on theTWS “Edit->Global Confiquration…->API->Settings” menu. Live Trading ports:TWS: 7496;IB Gateway:4001.Simulated Trading ports for new installationsof version 954.1 or newer: TWS:7497;IB Gateway:4002serverVersion:None connectionTime:None What dose that mean? How to resolve it? Sincerely

  • Jeffrey

    Hello, after run “c:\TWS API\samples\Python\Testbed>python program.py –port 7497”, got the response: Using args Namespace(port=7497, global_cancel=False) ERROR -1 502 Couldn’t connect to TWS. Confirm that “Enable ActiveX and Socket EClients” is enabled and connection port is the same as “Socket Port” on the TWS “Edit->Global Configuration…->API->Settings” menu. Live Trading ports: TWS: 7496; IB Gateway: 4001. Simulated Trading ports for new installations of version 954.1 or newer: TWS: 7497; IB Gateway: 4002 Error. Id: -1 Code: 502 Msg: Couldn’t connect to TWS. Confirm that “Enable ActiveX and Socket EClients” is enabled and connection port is the same as “Socket Port” on the TWS “Edit->Global Configuration…->API->Settings” menu. Live Trading ports: TWS: 7496; IB Gateway: 4001. Simulated Trading ports for new installations of version 954.1 or newer: TWS: 7497; IB Gateway: 4002 serverVersion:None connectionTime:None I checked the TWS API setting is correct with “Enable ActiveX and Socket Clients” and the “Socked port 7497” for my Paper Account. How can I fix the issue?

  • Michael

    Hello, When running Program.py, I got this error message: Error. Id: 1 Code: 388 Msg: Order size $1K is smaller than the minimum required size of $100K. Did I configure something wrong?

    Also, apparently program.py runs super slowly, what could be the reason?

    • Daniel

      Hello, I am getting the same error message as Michael:

      ERROR 3 388 Order size $1K is smaller than the minimum required size of $100K.
      Error. Id: 3 Code: 388 Msg: Order size $1K is smaller than the minimum required size of $100K.
      ERROR 3 10147 OrderId 3 that needs to be cancelled is not found

      Alongside some messages that don’t seem to be real errors

      ERROR -1 2104 Market data farm connection is OK:usfarm.nj
      Error. Id: -1 Code: 2104 Msg: Market data farm connection is OK:usfarm.nj

      • Interactive Brokers

        Hello, thank you for asking. Messages such as this are related to the Order Precaution settings listed under the Global Configuration -> Presets -> {Select whichever instrument type you are trading. In our case, let’s start with Stocks} -> You may modify the values inside the “Precautionary Settings” settings to be more or less restrictive. You may also set the value to ‘0’ to disable the precaution entirely. Please be aware that additional precautionary settings are listed in the API Precautions section as well. This is further discussed in the documentation here: https://www.interactivebrokers.com/campus/ibkr-api-page/twsapi-doc/#bp-order-precautions.

        If you have any additional questions, 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

        • Bart D

          @IBKR I believe this answer is incorrect. The error msg says that the minimum order size is HIGHER than what is entered so it is not a precautionary setting limit that the order size is too high. It seems the test program tries to place an order for 1 bond in rfqOperation(), resulting in $1K and the minimum for this type of instrument is $100K. I see the same issue. When I change the qty from 1 to 100 in RfqEmpty() in OrderSamples.py the error goes away. It’s odd that your sample tries to place a bond order, I believe it would be more logical to place a stock order as that is much more common.

          • Interactive Brokers

            Hello, thank you for reaching out. The Program.py file is a program created to test all aspects of the API. As a result, the orderOperations_req function will create orders for stocks, options, futures, bonds, and more to ensure the user has a reference of how to construct these particular contracts. If you have any further questions, please create a web ticket for our API experts: https://spr.ly/IBKR_TicketCampus

            We would love to assist you.

  • Mark

    Hi, I’m trying the process of 6:35, I wonder does it requires trading hours or not. I ask this question because I try it on Sunday and did not see executing cancels, executing cancels finish, finishing test etc.

    • Interactive Brokers

      Hello, thank you for reaching out. The orders in the Program.py file do not support orders outside of regular trading hours by default. Also, market data may be unavailable or limited when used outside regular trading hours. However, historical data should behave as intended. The API’s functionalities work best during trading hours.

      Program.py is largely used to make sure you have access to the “ibapi” Python module, rather than the system being tested itself. Please view the remainder of the course for more information.

      We hope this information is helpful!

  • Anonymous

    I’m getting error:
    error: [WinError 32] The process cannot access the file because it is being used by another process: ‘c:\\users\\peter ding\\appdata\\local\\programs\\python\\python312\\lib\\site-packages\\ibapi-10.19.4-py3.12.egg’
    When i run CMD python setup.py install

    • Interactive Brokers

      Hello, thank you for asking. This windows error implies there was some error while originally installing the API. An ideal means to resolve this would be to run “python -m pip uninstall ibapi” to remove any installed API releases. After following this process until all API releases have been removed, it may sometimes be necessary to validate in the path that the .egg file no longer exists I the designated location. Along with manually deleting the file from the stated location. You should then attempt to reinstall the API using the method described in the video. If there error persists, I would encourage you to contact Customer Service to help resolve the matter as soon as possible. You can find the steps to create a ticket here: https://www.ibkrguides.com/complianceportal/creatingaticket.htm.

      We hope this helps!

  • Anonymous

    Hi, I am using windows and python 3.11. After installing the program and going in the folder C:\TWS API\source\pythonclient>, the respond to python setup.py is error: no commands supplied Can you please help me to solve the problem?

  • Anonymous

    I’m not sure if this is just me, but when I’m downloading the TWS API on my Mac(“TWS API Stable for Mac/Unix”), it has me download a ZIP file. But then when I open the zip file, it tells me that, “Unable to expand “twsapi_macunix.1030.01 (3).zip. It is an unsupported format”. Tried this three times and not sure why this continues to happen. I’m running TWS on my Mac.

  • Anonymous

    I get to C:\TWS API\source\pythonclient> When I enter >python setup.py install The message says python was not found… what do I do with that?

    • Interactive Brokers

      Thank you for contacting us. It sounds like you have not installed Python on your machine, or perhaps not implemented Python in your PATH. This information would be available from the Python software page: https://www.python.org/

      We hope this helps!

  • Dan

    version 10.35, Linux (ubuntu): followed your intructions and got this: File “/home/wawa/work/Trading/tws/python_api/IBJts/source/pythonclient/../../samples/Python/Testbed/Program.py”, line 16, in from ibapi.client import EClient File “/home/wawa/python_envs/env_Py3.10/lib/python3.10/site-packages/ibapi-10.35.1-py3.10.egg/ibapi/client.py”, line 18, in File “/home/wawa/python_envs/env_Py3.10/lib/python3.10/site-packages/ibapi-10.35.1-py3.10.egg/ibapi/decoder.py”, line 33, in ModuleNotFoundError: No module named ‘protobuf’ (I tried also some work arounds, uninstalling, installing via pip to avoid the egg install, copying the protobuf folder manually). Nothing. Please advise?

    • Andy

      (pydata-book) C:\TWS API\samples\Python\Testbed>python Program.py –port 7497 Traceback (most recent call last): File “C:\TWS API\samples\Python\Testbed\Program.py”, line 16, in from ibapi.client import EClient File “C:\Users\86189\anaconda3\envs\pydata-book\Lib\site-packages\ibapi-10.30.1-py3.13.egg\ibapi\client.py”, line 18, in from ibapi import decoder, reader, comm File “C:\Users\86189\anaconda3\envs\pydata-book\Lib\site-packages\ibapi-10.30.1-py3.13.egg\ibapi\decoder.py”, line 33, in from protobuf.ExecutionDetails_pb2 import ExecutionDetails as ExecutionDetailsProto ModuleNotFoundError: No module named ‘protobuf’ I hit the same issue as Dan. I tried ibapi 10.35 and 10.31. pip install different version of protobuf. Does not help.

      • Interactive Brokers

        Hello Andy, thank you for reaching out. This is a known issue in the 10.35.1 release of the TWS API. We have instructions to resolve this matter currently listed at https://github.com/awiseib/Python-testers/blob/main/README.md though this behavior should be resolved in our next TWS API release. You can also opt to install the TWS API Stable release, which will also avoid this behavior. If you have any additional questions, 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

    • Conor

      Same issue for me on windows

  • K.

    I am getting the same issue as Dan on Windows, could be a version specific issue.

  • VJ

    I am running into the same issue ModuleNotFound ‘protobuf’ on mac. I have 10.35.1 ibapi installed and protobuf 6.30.2

    • Interactive Brokers

      Hello, thank you for reaching out. You can review the instructions provided in this documentation to resolve this issue: https://www.interactivebrokers.com/campus/ibkr-api-page/twsapi-doc/#python-protobuf. The behavior should be replaced in TWSAPI 10.36.1 and above. If you have any additional questions on this topic, please create a detailed web ticket; we have a category specifically for “API.” One of our API experts will be happy to guide you! https://spr.ly/IBKR_ClientServicesCampus

      • Anonymous

        Why has the solution been removed from the link provided?

        • Interactive Brokers

          Hello, thanks for reaching out. Can you please clarify your question? We would appreciate the opportunity to turn around your experience.

  • Chris

    Hi I followed your instructions on Ubuntu 24.04 LTS, but after install I keep getting: Traceback (most recent call last): from ibapi.client import EClient File “/home/chris/miniconda3/envs/Quant/lib/python3.12/site-packages/ibapi-10.35.1-py3.12.egg/ibapi/client.py”, line 18, in File “/home/chris/miniconda3/envs/Quant/lib/python3.12/site-packages/ibapi-10.35.1-py3.12.egg/ibapi/decoder.py”, line 33, in ModuleNotFoundError: No module named ‘protobuf’ I looked in the build for the python client and it appears to not include your module named “protobuf” in the build, so I suspect there is something wrong with your setup.py config.

    • Chris

      Nevermind I found this link and resolved the issues: https://github.com/awiseib/Python-testers/blob/main/README.md

      • Z

        Hi, I have changed all of files as this link mentioned, however this error still there. I don’t know why

        • Anonymous

          Me the same, did all changes in the files and same error.

          • Anonymous

            hi have y’all managed to resolve it? I changed all the files and still same error too

          • Interactive Brokers

            Hello, thank you for contacting us and we apologize for the delayed response. If you continue to experience difficulties, please create a web ticket under the category “API”. https://spr.ly/IBKR_TicketCampus

            One of our API experts would be happy to guide you!

  • Anonymous

    when will the fix of 1035 for the protobuf coming out

    • Interactive Brokers

      Hello, thank you for reaching out. Please be aware that the TWS API now requires Python 3.11 or higher to function with the Latest release. If you have not done so already, please download a compatible version from https://www.python.org/downloads/.

  • Anonymous

    (ibenv) dizhouzhao@MacBookPro desktop % python3 t1.py Traceback (most recent call last): File “/Users/dizhouzhao/Desktop/t1.py”, line 2, in from ibapi.client import EClient File “/Users/dizhouzhao/Documents/ibenv/lib/python3.13/site-packages/ibapi-10.36.1-py3.13.egg/ibapi/client.py”, line 18, in from ibapi import decoder, reader, comm File “/Users/dizhouzhao/Documents/ibenv/lib/python3.13/site-packages/ibapi-10.36.1-py3.13.egg/ibapi/decoder.py”, line 33, in from ibapi.protobuf.ExecutionDetails_pb2 import ExecutionDetails as ExecutionDetailsProto ModuleNotFoundError: No module named ‘ibapi.protobuf’

  • Dave

    Hi, I use Windows and followed your instruction to install it via “python setup.py install” command. Which works, but then at “pip show ibapi” it says that it still requires protobuf. It also created an “easy-install.pth” file in the Python packages folder. Can you please advise?

    • Interactive Brokers

      Hello, thank you for reaching out. The “Requires” field from the pip show command will include all dependencies required by the library to run. In this case, protobuf must be installed in order to run ibapi. If you run “$ pip show protobuf”, its information should be listed, along with the “Required-by” field listing “ibapi”. We hope this helps!

  • Anonymous

    I followed along in windows and this worked perfectly! Thanks for the very detailed instructions!

    • Interactive Brokers

      Please reach back out with any additional questions. We are here to help!

  • Anonymous

    Team – It would also be great to keep that Program.py test file updated with the latest changes as well. Either all of some instruments and test cases are failing. In my case, the SPY, IBM and BMW orders excecated but nothing else.

    • Interactive Brokers

      Thank you for the feedback. We have passed it to the appropriate team. In a coming update, we will look to update Python, along with our other language contracts.

  • Anonymous

    HI, I downloaded the new Mac version 10.36 and there isn’t any zipped file. So I skipped the unzip file given the folder was downloaded as unzipped. Is this ok? I proceeded to change cd to C:\TWS API but there is no such file and directory. I downloaded anaconda already. is there something I am missing

    • Anonymous

      Hi, I managed to use another browser to download and it is a zip file. I can’t open it so I use terminal to unzip it. Now that it is unzipped, how do I make it run the download wizard? I can’t seem to be able to change to C:TWS API. What can I do

  • Anonymous

    Hi, I have changed all of files on the link mentioned, however this error still there that I still don’t have the No module named ‘ibapi.protobuf’. what can I do?

    • Interactive Brokers

      Hello, thank you for asking. Please be aware that the TWS API now requires Python 3.11 or higher to function with the Latest release. If you have not done so already, please download a compatible version from https://www.python.org/downloads/.

      • Anonymous

        Will anaconda/jupyter notebook work?

  • Anonymous0001

    Same issue here: PS C:\TWS API\samples\Python\Testbed> python Program.py Traceback (most recent call last): File “C:\TWS API\samples\Python\Testbed\Program.py”, line 15, in from ibapi import wrapper File “C:\Users\LAPTOP0001\AppData\Local\Programs\Python\Python311\Lib\site-packages\ibapi-10.37.1-py3.11.egg\ibapi\wrapper.py”, line 53, in ModuleNotFoundError: No module named ‘ibapi.protobuf’ Using Python 3.11.8 and TWS API 10.37 (latest), still receiving this error. Any suggestions on a solve? Or it’s fine to leave the error as it is and move on?

  • Anonymous

    Testbed % python3 Program.py -port 7497 Traceback (most recent call last): File “/Users/IBKR_Python_Dev/twsapi_macunix/IBJts/samples/Python/Testbed/Program.py”, line 15, in from ibapi import wrapper File “”, line 259, in load_module File “/opt/homebrew/lib/python3.9/site-packages/ibapi-10.37.2-py3.9.egg/ibapi/wrapper.py”, line 53, in ModuleNotFoundError: No module named ‘ibapi.protobuf’

    • Interactive Brokers

      Hello, thank you for reaching out. Taking a look at your error, it appears that you are using Python 3.9, which is beneath our minimum supported version of 3.11. We would advise fully removing the TWS API and then installing at least python 3.11 or higher. Once the new Python version has been installed on your machine, you should then be able to follow the standard installation steps along with the Python API Setup to resolve this reference error. We hope this helps!

  • Robert

    After starting the program.py, I got those messages: C:\TWS API\samples\Python\Testbed>py program.py -p 7497 Using args Namespace(port=7497, global_cancel=False) serverVersion:203 connectionTime:b’20250616 15:53:04 Mitteleurop\xe4ische Normalzeit’ OpenOrderProtoBuf OpenOrder. PermId: 860821855 ClientId: 0 OrderId: 4 Account: DUK871354 Symbol: IBM SecType: STK Strike: Exchange: SMART Action: BUY OrderType: LMT TotalQty: 200 CashQty: LmtPrice: 10 AuxPrice: 0 Status: Submitted MinTradeQty: MinCompeteSize: competeAgainstBestOffset: MidOffsetAtWhole: MidOffsetAtHalf: FAGroup: FAMethod: CustomerAccount: ProfessionalCustomer: False BondAccruedInterest: IncludeOvernight: False ExtOperator: ManualOrderIndicator: Submitter: ImbalanceOnly: False AlgoStrategy: DeltaNeutralContract: {conid: 0 delta: 0 price:0 } SoftDollarTier: {name: val: displayName: } OrderStatusProtoBuf OrderStatus. Id: 4 Status: Submitted Filled: 0 Remaining: 200 AvgFillPrice: 0 PermId: 860821855 ParentId: 0 LastFillPrice: 0 ClientId: 0 WhyHeld: MktCapPrice: 0 OpenOrderProtoBuf OpenOrder. PermId: 1374681981 ClientId: 0 OrderId: 20 Account: DUK871354 Symbol: IBM SecType: STK Strike: Exchange: SMART Action: BUY OrderType: LMT TotalQty: 200 CashQty: LmtPrice: 10 AuxPrice: 0 Status: Submitted MinTradeQty: MinCompeteSize: competeAgainstBestOffset: MidOffsetAtWhole: MidOffsetAtHalf: FAGroup: FAMethod: CustomerAccount: ProfessionalCustomer: False BondAccruedInterest: IncludeOvernight: False ExtOperator: ManualOrderIndicator: Submitter: ImbalanceOnly: False AlgoStrategy: DeltaNeutralContract: {conid: 0 delta: 0 price:0 } SoftDollarTier: {name: val: displayName: } OrderStatusProtoBuf OrderStatus. Id: 20 Status: Submitted Filled: 0 Remaining: 200 AvgFillPrice: 0 PermId: 1374681981 ParentId: 0 LastFillPrice: 0 ClientId: 0 WhyHeld: MktCapPrice: 0 OpenOrderProtoBuf OpenOrder. PermId: 1374681980 ClientId: 0 OrderId: 19 Account: DUK871354 Symbol: IBM SecType: STK Strike: Exchange: SMART Action: BUY OrderType: LMT TotalQty: 200 CashQty: LmtPrice: 10 AuxPrice: 0 Status: Submitted MinTradeQty: MinCompeteSize: competeAgainstBestOffset: MidOffsetAtWhole: MidOffsetAtHalf: FAGroup: FAMethod: CustomerAccount: ProfessionalCustomer: False BondAccruedInterest: IncludeOvernight: False ExtOperator: ManualOrderIndicator: Submitter: ImbalanceOnly: False AlgoStrategy: DeltaNeutralContract: {conid: 0 delta: 0 price:0 } SoftDollarTier: {name: val: displayName: } OrderStatusProtoBuf OrderStatus. Id: 19 Status: Submitted Filled: 0 Remaining: 200 AvgFillPrice: 0 PermId: 1374681980 ParentId: 0 LastFillPrice: 0 ClientId: 0 WhyHeld: MktCapPrice: 0 OpenOrderProtoBuf OpenOrder. PermId: 1374681987 ClientId: 0 OrderId: 28 Account: DUK871354 Symbol: IBM SecType: STK Strike: Exchange: SMART Action: BUY OrderType: LMT TotalQty: 200 CashQty: LmtPrice: 10 AuxPrice: 0 Status: Submitted MinTradeQty: MinCompeteSize: competeAgainstBestOffset: MidOffsetAtWhole: MidOffsetAtHalf: FAGroup: FAMethod: CustomerAccount: ProfessionalCustomer: False BondAccruedInterest: IncludeOvernight: False ExtOperator: ManualOrderIndicator: Submitter: ImbalanceOnly: False AlgoStrategy: DeltaNeutralContract: {conid: 0 delta: 0 price:0 } SoftDollarTier: {name: val: displayName: } OrderStatusProtoBuf OrderStatus. Id: 28 Status: Submitted Filled: 0 Remaining: 200 AvgFillPrice: 0 PermId: 1374681987 ParentId: 0 LastFillPrice: 0 ClientId: 0 WhyHeld: MktCapPrice: 0 OpenOrderProtoBuf OpenOrder. PermId: 1374681986 ClientId: 0 OrderId: 27 Account: DUK871354 Symbol: IBM SecType: STK Strike: Exchange: SMART Action: BUY OrderType: LMT TotalQty: 200 CashQty: LmtPrice: 10 AuxPrice: 0 Status: Submitted MinTradeQty: MinCompeteSize: competeAgainstBestOffset: MidOffsetAtWhole: MidOffsetAtHalf: FAGroup: FAMethod: CustomerAccount: ProfessionalCustomer: False BondAccruedInterest: IncludeOvernight: False ExtOperator: ManualOrderIndicator: Submitter: ImbalanceOnly: False AlgoStrategy: DeltaNeutralContract: {conid: 0 delta: 0 price:0 } SoftDollarTier: {name: val: displayName: } OrderStatusProtoBuf OrderStatus. Id: 27 Status: Submitted Filled: 0 Remaining: 200 AvgFillPrice: 0 PermId: 1374681986 ParentId: 0 LastFillPrice: 0 ClientId: 0 WhyHeld: MktCapPrice: 0 OpenOrderProtoBuf OpenOrder. PermId: 860821856 ClientId: 0 OrderId: 5 Account: DUK871354 Symbol: IBM SecType: STK Strike: Exchange: SMART Action: BUY OrderType: LMT TotalQty: 200 CashQty: LmtPrice: 10 AuxPrice: 0 Status: Submitted MinTradeQty: MinCompeteSize: competeAgainstBestOffset: MidOffsetAtWhole: MidOffsetAtHalf: FAGroup: FAMethod: CustomerAccount: ProfessionalCustomer: False BondAccruedInterest: IncludeOvernight: False ExtOperator: ManualOrderIndicator: Submitter: ImbalanceOnly: False AlgoStrategy: DeltaNeutralContract: {conid: 0 delta: 0 price:0 } SoftDollarTier: {name: val: displayName: } OrderStatusProtoBuf OrderStatus. Id: 5 Status: Submitted Filled: 0 Remaining: 200 AvgFillPrice: 0 PermId: 860821856 ParentId: 0 LastFillPrice: 0 ClientId: 0 WhyHeld: MktCapPrice: 0 OpenOrdersEndProtoBuf OpenOrderEnd NextValidId: 54 Account list: DUK871354 Executing requests doing orderOperations_req Traceback (most recent call last): File “C:\TWS API\samples\Python\Testbed\program.py”, line 2256, in main() ~~~~^^ File “C:\TWS API\samples\Python\Testbed\program.py”, line 2246, in main app.run() ~~~~~~~^^ File “C:\TWS API\samples\Python\Testbed\program.py”, line 132, in countReqId_ return fn(*args, **kwargs) File “C:\Users\rhuet\AppData\Local\Programs\Python\Python313\Lib\site-packages\ibapi\client.py”, line 442, in run self.decoder.interpret(fields, msgId) ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^ File “C:\Users\rhuet\AppData\Local\Programs\Python\Python313\Lib\site-packages\ibapi\decoder.py”, line 1578, in interpret self.interpretWithSignature(fields, handleInfo) ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^ File “C:\Users\rhuet\AppData\Local\Programs\Python\Python313\Lib\site-packages\ibapi\decoder.py”, line 1562, in interpretWithSignature method(*args) ~~~~~~^^^^^^^ File “C:\TWS API\samples\Python\Testbed\program.py”, line 535, in managedAccounts self.start() ~~~~~~~~~~^^ File “C:\TWS API\samples\Python\Testbed\program.py”, line 286, in start self.orderOperations_req() ~~~~~~~~~~~~~~~~~~~~~~~~^^ File “C:\TWS API\samples\Python\Testbed\program.py”, line 77, in fn2 fn(self) ~~^^^^^^ File “C:\TWS API\samples\Python\Testbed\program.py”, line 1850, in orderOperations_req self.bracketSample() ~~~~~~~~~~~~~~~~~~^^ File “C:\TWS API\samples\Python\Testbed\program.py”, line 1511, in bracketSample self.placeOrder(o.orderId, ContractSamples.EuropeanStock(), o) ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “C:\TWS API\samples\Python\Testbed\program.py”, line 132, in countReqId_ return fn(*args, **kwargs) File “C:\Users\rhuet\AppData\Local\Programs\Python\Python313\Lib\site-packages\ibapi\client.py”, line 1245, in placeOrder placeOrderRequestProto = createPlaceOrderRequestProto(orderId, contract, order) File “C:\Users\rhuet\AppData\Local\Programs\Python\Python313\Lib\site-packages\ibapi\client_utils.py”, line 50, in createPlaceOrderRequestProto contractProto = createContractProto(contract, order) File “C:\Users\rhuet\AppData\Local\Programs\Python\Python313\Lib\site-packages\ibapi\client_utils.py”, line 67, in createContractProto if contract.primaryExchange: contractProto.primaryExchange = contract.primaryExchange ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: Protocol message Contract has no “primaryExchange” field.

    • Interactive Brokers

      Hello, thank you for contacting us. 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

    • Anonymous

      Any Solution for this?

      • Interactive Brokers

        Hello, thank you for reaching out. If you have any specific questions, one of our API experts will be happy to help you! https://spr.ly/IBKR_TicketCampus

  • Anonymous

    Hi, am installing TWS API for MacOS. Have followed all the instructions and everything is fine until I try to run the program.py in testbed. Am using protobuf 5.29.3 and get the following error message: Traceback (most recent call last): File “/Users/alberttchang/Desktop/twsapi_macunix/IBJts/samples/Python/Testbed/program.py”, line 15, in from ibapi import wrapper File “/opt/anaconda3/lib/python3.12/site-packages/ibapi-10.37.2-py3.12.egg/ibapi/wrapper.py”, line 53, in ModuleNotFoundError: No module named ‘ibapi.protobuf’ (base) Mac:testbed alberttchang$ python Program.py –port 7497 Traceback (most recent call last): File “/Users/alberttchang/Desktop/twsapi_macunix/IBJts/samples/Python/Testbed/Program.py”, line 15, in from ibapi import wrapper File “/opt/anaconda3/lib/python3.12/site-packages/ibapi-10.37.2-py3.12.egg/ibapi/wrapper.py”, line 53, in ModuleNotFoundError: No module named ‘ibapi.protobuf’ Any advice?

  • tpant

    Hello, I get the following error when I run the Program.py file. I have python 3.11.3 installed. Any guidance? C:\TWS API\samples\Python\Testbed>python Program.py –port 7497 Traceback (most recent call last): File “C:\TWS API\samples\Python\Testbed\Program.py”, line 15, in from ibapi import wrapper File “C:\Users\tpant\AppData\Local\Programs\Python\Python311\Lib\site-packages\ibapi-10.37.2-py3.11.egg\ibapi\wrapper.py”, line 53, in ModuleNotFoundError: No module named ‘ibapi.protobuf’

    • Interactive Brokers

      Hello, thank you for reaching out. This error message is typically a sign of a previously installed API instance or a potential error from running the setup.py installation process. Completely uninstalling the api and pip uninstalling ibapi references prior to a reinstallation will resolve the matter. We hope this helps!

      • Anonymous

        Thanks I think this worked!

  • wilmar quinones

    excelente tarde , tengo la plataforma TWS activa , configurada 7496 , Api TWS descargada y validada intento correr el programa python Program.py , pero de demosra mas de 10 min , luego lo dentego y sale este mensaje, me podrias indicar por favor posibles soluciones, gracias Using args Namespace(port=7496, global_cancel=False) Traceback (most recent call last): File “C:\Users\ACER\AppData\Local\Programs\Python\Python313\Lib\site-packages\ibapi\connection.py”, line 94, in recvMsg buf = self._recvAllMsg() File “C:\Users\ACER\AppData\Local\Programs\Python\Python313\Lib\site-packages\ibapi\connection.py”, line 119, in _recvAllMsg buf = self.socket.recv(4096) TimeoutError: timed out During handling of the above exception, another exception occurred: Traceback (most recent call last): File “E:\Info WP\inversiones\Trading\trade is simple\Creacion estrategia\TWS API\samples\Python\Testbed\Program.py”, line 2383, in main() ~~~~^^ File “E:\Info WP\inversiones\Trading\trade is simple\Creacion estrategia\TWS API\samples\Python\Testbed\Program.py”, line 2367, in main app.connect(“127.0.0.1”, args.port, clientId=0) ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “E:\Info WP\inversiones\Trading\trade is simple\Creacion estrategia\TWS API\samples\Python\Testbed\Program.py”, line 146, in countReqId_ return fn(*args, **kwargs) File “C:\Users\ACER\AppData\Local\Programs\Python\Python313\Lib\site-packages\ibapi\client.py”, line 374, in connect buf = self.conn.recvMsg() File “C:\Users\ACER\AppData\Local\Programs\Python\Python313\Lib\site-packages\ibapi\connection.py”, line 101, in recvMsg logger.debug(“socket timeout from recvMsg %s”, sys.exc_info()) ~~~~~~~~~~~~^^ KeyboardInterrupt

    • Interactive Brokers

      Hola, gracias por contactarnos. Por favor, cree un ticket web para esta consulta; tenemos una categoría específica para “API”. ¡Uno de nuestros expertos en API estará encantado de ayudarle! https://spr.ly/IBKR_TicketCampus

  • Florian

    Hi, when excecuting python Program.py, I receive the following error messages : “Using args Namespace(port=7496, global_cancel=False) serverVersion:187 connectionTime:b’20250713 15:28:18 Central European Standard Time’ NextValidId: 2 Account list: U20723105 Executing requests doing rfqOperations done w/ rfqOperations Executing requests … finished ERROR -1 2104 Market data farm connection is OK:usfarm.nj Error. Id: -1 Code: 2104 Msg: Market data farm connection is OK:usfarm.nj ERROR -1 2104 Market data farm connection is OK:usfuture Error. Id: -1 Code: 2104 Msg: Market data farm connection is OK:usfuture ERROR -1 2104 Market data farm connection is OK:eufarm Error. Id: -1 Code: 2104 Msg: Market data farm connection is OK:eufarm ERROR -1 2104 Market data farm connection is OK:cashfarm Error. Id: -1 Code: 2104 Msg: Market data farm connection is OK:cashfarm ERROR -1 2104 Market data farm connection is OK:eufarmnj Error. Id: -1 Code: 2104 Msg: Market data farm connection is OK:eufarmnj ERROR -1 2104 Market data farm connection is OK:usfarm Error. Id: -1 Code: 2104 Msg: Market data farm connection is OK:usfarm ERROR -1 2106 HMDS data farm connection is OK:euhmds Error. Id: -1 Code: 2106 Msg: HMDS data farm connection is OK:euhmds ERROR -1 2106 HMDS data farm connection is OK:ushmds Error. Id: -1 Code: 2106 Msg: HMDS data farm connection is OK:ushmds ERROR -1 2158 Sec-def data farm connection is OK:secdefeu Error. Id: -1 Code: 2158 Msg: Sec-def data farm connection is OK:secdefeu ERROR 2 388 Order size $1K is smaller than the minimum required size of $100K. Error. Id: 2 Code: 388 Msg: Order size $1K is smaller than the minimum required size of $100K. ERROR 2 10340 The following order attribute is not supported: ManualOrderIndicator Error. Id: 2 Code: 10340 Msg: The following order attribute is not supported: ManualOrderIndicator ERROR 3 10340 The following order attribute is not supported: ManualOrderIndicator Error. Id: 3 Code: 10340 Msg: The following order attribute is not supported: ManualOrderIndicator” my TWS version is 10.38, the TWS API is 10.30. I have IBKR PRO, and so far have not made any trades or changes to the config. Please advise

    • Interactive Brokers

      Hello, thank you for reaching out. The “The following order attribute is not supported: ManualOrderIndicator” is a typical sign of running the legacy release of the TWS API from not following the Python Interpreter Update steps. Please review the Python-Specific Setup steps in this video, or follow the steps in our TWS API Documentation. We hope this information is helpful!

  • Luis

    Hello While trying the last check of this lesson I get the following: PS C:\TWS API\samples\Python\Testbed> py Program.py -port 7497 Traceback (most recent call last): File “C:\TWS API\samples\Python\Testbed\Program.py”, line 15, in from ibapi import wrapper File “C:\Users\Luis\AppData\Local\Programs\Python\Python313\Lib\site-packages\ibapi\wrapper.py”, line 53, in from ibapi.protobuf.OrderStatus_pb2 import OrderStatus as OrderStatusProto File “C:\Users\Luis\AppData\Local\Programs\Python\Python313\Lib\site-packages\ibapi\protobuf\OrderStatus_pb2.py”, line 7, in from google.protobuf import descriptor as _descriptor ModuleNotFoundError: No module named ‘google’ Do you have any idea why I get this error ? Thank you in advance for your reply. Best regards

    • Interactive Brokers

      Hello Luis, thank you for reaching out. 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_TicketCampus

  • Anonymous

    Hi, I switched to a new mac, and installed ibapi 10.39.1, protobuf 5.29.3, and Python 3.11.7. However, I will get this protobuf parsing error. (MainThread) 250831_17:16:06.530 DEBUG client.py:513 msgId: 4, protobuf: b’***”\’Market data farm connection is OK:hfarm’ (MainThread) 250831_17:16:06.530 INFO utils.py:211 ANSWER errorProtoBuf {‘errorMessageProto’: id: -1 errorTime: 1756631767301 errorCode: 2104 errorMsg: “Market data farm connection is OK:hfarm” } Could IB provide older version of API for customers to install and test?

    • Interactive Brokers

      Hello, thank you for reaching out. The information provided is an indicator that the connection is “OK” and has been present in the TWS API connection for the past 10 years. There is nothing to be concerned with regarding these errors and they may be simply dismissed. We hope this answers your question!

      • Anonymous

        Hi, Thanks for your reply. But then I will have this error and it will terminate. File “*/python3.11/site-packages/ibapi-10.39.1-py3.11.egg/ibapi/client.py”, line 514, in run File “*/python3.11/site-packages/ibapi-10.39.1-py3.11.egg/ibapi/decoder.py”, line 2251, in processProtoBuf File “*/python3.11/site-packages/ibapi-10.39.1-py3.11.egg/ibapi/decoder.py”, line 1983, in processErrorMsgProtoBuf TypeError: TradeApp.error() takes 5 positional arguments but 6 were given

        • Anonymous

          I found out that I need to update the error API to “def error(self, reqId: TickerId, errorTime: int, errorCode: int, errorString: str, advancedOrderRejectJson = “”)” It is different in the new version. Thanks a lot for help.

        • Interactive Brokers

          Hi, thank you for asking. Since this tutorial was initially created, we’ve updated our Error function to take the following arguments: self, reqId: TickerId, errorTime: int, errorCode: int, errorString: str, advancedOrderRejectJson=””. Please be aware that the advancedOrderRejectJson argument must be an optional argument, as it may not always return. We hope this helps!

  • Jack

    Hi for everyone facing the issue with Protobuf: Uninstall and reinstall using the version required by ibapi–> pip uninstall protobuf pip install protobuf==5.29.3 tested Python 3.13.0 Other issues: Using args Namespace(port=7497, global_cancel=False) serverVersion:203 connectionTime:b’20250916 17:42:55 Central European Standard Time’ NextValidId: 39 Account list: XXXXXXXXX Executing requests doing orderOperations_req Traceback (most recent call last): File “c:\TWS API\samples\Python\Testbed\Program.py”, line 2256, in main() ~~~~^^ File “c:\TWS API\samples\Python\Testbed\Program.py”, line 2246, in main app.run() ~~~~~~~^^ File “c:\TWS API\samples\Python\Testbed\Program.py”, line 132, in countReqId_ return fn(*args, **kwargs) File “C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\site-packages\ibapi\client.py”, line 442, in run self.decoder.interpret(fields, msgId) ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^ File “C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\site-packages\ibapi\decoder.py”, line 1578, in interpret self.interpretWithSignature(fields, handleInfo) ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^ File “C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\site-packages\ibapi\decoder.py”, line 1562, in interpretWithSignature method(*args) ~~~~~~^^^^^^^ File “c:\TWS API\samples\Python\Testbed\Program.py”, line 535, in managedAccounts self.start() ~~~~~~~~~~^^ File “c:\TWS API\samples\Python\Testbed\Program.py”, line 286, in start self.orderOperations_req() ~~~~~~~~~~~~~~~~~~~~~~~~^^ File “c:\TWS API\samples\Python\Testbed\Program.py”, line 77, in fn2 fn(self) ~~^^^^^^ File “c:\TWS API\samples\Python\Testbed\Program.py”, line 1850, in orderOperations_req self.bracketSample() ~~~~~~~~~~~~~~~~~~^^ File “c:\TWS API\samples\Python\Testbed\Program.py”, line 1511, in bracketSample self.placeOrder(o.orderId, ContractSamples.EuropeanStock(), o) ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “c:\TWS API\samples\Python\Testbed\Program.py”, line 132, in countReqId_ return fn(*args, **kwargs) File “C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\site-packages\ibapi\client.py”, line 1245, in placeOrder placeOrderRequestProto = createPlaceOrderRequestProto(orderId, contract, order) File “C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\site-packages\ibapi\client_utils.py”, line 50, in createPlaceOrderRequestProto contractProto = createContractProto(contract, order) File “C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\site-packages\ibapi\client_utils.py”, line 67, in createContractProto if contract.primaryExchange: contractProto.primaryExchange = contract.primaryExchange

  • Anonymous

    Hello, I have installed the latest version of TWS API for Windows 10.37, protobuf 5.29.3, I have tried with Python versions 3.9, 3.10 and 3.11 and 3.13, I am getting the error “No module named ibapi.protobuf” found. Kindly help

    • Interactive Brokers

      Hi, thank you for reaching out. 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

    • Anonymous

      Hi, I had a similar error, but I solved it by adding an __init__.py file inside the protobuf folder in the Python site-packages directory. This issue is related to how Python recognizes a package — if you don’t have this file, Python doesn’t treat the folder as a package.

  • Pras

    Hi , After running the command python setup.py install, I get the Access Denied error when the setup file tries to copy ibapi package in PythonSoftwareFoundation copying ibapi/protobuf\WshMetaDataRequest_pb2.py -> build\lib\ibapi/protobuf copying ibapi/protobuf\WshMetaData_pb2.py -> build\lib\ibapi/protobuf copying ibapi/protobuf\__init__.py -> build\lib\ibapi/protobuf running install_lib creating C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.2800.0_x64__qbz5n2kfra8p0\Lib\site-packages\ibapi error: could not create ‘C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.2800.0_x64__qbz5n2kfra8p0\Lib\site-packages\ibapi’: Access is denied

    • Interactive Brokers

      Hello, thank you for reaching out. Given the “Access is denied” error message, this would indicate a local permissions issue. Please be sure to run the software as administrator. If your computer is managed by your school or company, please contact your local IT department for further assistance with the affiliated privileges.  

  • Anonymous

    Hi I downloaded theTWS API and unzipped the file. Initially I had Python3.11 and when I execute the command “python3.11 setup.py install” everything went through except the last part where I got an error /IBJts/source/pythonclient/setup.py”, line 6, in from setuptools import setup ModuleNotFoundError: No module named ‘setuptools’

    • Interactive Brokers

      Based on the error message, it sounds like Python’s setuptools module is not installed. To resolve this, simply type “pip install setuptools” in your terminal to install setuptools. Afterwards, attempting to run the script again will resolve the behavior.

  • Anonymous

    Good evening. When using TWS API for Python, version 10.37.2 and protobuf-5.29.3-py3.12.egg, I received the following error message: ModuleNotFoundError: No module named ‘ibapi.protobuf’. Please provide any guidance. Thank you

    • Interactive Brokers

      Thank you for contacting us. 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

    • Interactive Brokers

      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

  • Paul

    i recently (today) downloaded API 10.37 for linux, ubuntu LTS (latest) i followed all steps after command “python3 -m pip install .” (is same as “python setup.py install”) i get a protobuf error. ERROR: Could not find a version that satisfies the requirement protobuf==5.29.3 (from ibapi) (from versions:none) ERROR: No matching distribution found for protobuf==5.29.3 how to fix this?

    • Interactive Brokers

      Hello, thank you for asking. To resolve the issue, you will need to include an empty “__init__.py” file under {TWS API}/source/pythonclient/ibapi/protobuf, or you may upgrade to the Latest release of TWS API which has resolved the issue. We hope this helps!

  • Zavier

    SOLUTION: Create a empty file named `__init__.py` into `source/ibapi/protobuf/`, uninstall & reinstall Hi, I had the same issue at first, but when I think why this happend, I figured out this because `protobuf` package is not installed currectly with ibapi. After I checked files in `source/`, I found a important file is missing which is `__init__.py`. This file should be in `source/ibapi/protobuf/`, you can touch a empty file but named `__init__.py`, this issue will be setteled. Because protobuf won’t be regarded as a package whithout `__init__.py`.

  • lkcurious

    Hi guys, first time installing python api on mac. When I try and run setup.py this comes up:lkentris@Louies-MacBook-Pro pythonclient % python3 setup.py install Traceback (most recent call last): File “/Users/myname/Downloads/IBJts/source/pythonclient/setup.py”, line 6, in from setuptools import setup ModuleNotFoundError: No module named ‘setuptools’

    • Interactive Brokers

      Thank you for reaching out. This is an issue that arises on more modern release of MacOS. To resolve this, send the following from your terminal:“python3 -m pip install setuptools”. Once setuptools installs, you can follow the original guide. We hope this helps!

  • Victor

    Ended up having issues when installing the package. Executing a `python setup.py install` in my virtual environment appeared as if it had worked, but it didn’t; I kept getting an error when trying to run the `Program.py`. I ended up having to follow the instructions in the `readme.md` instead, so I ran a `python setup.py sdist` followed by `pip install –force-reinstall dist/ibapi-10.37.2-py3-none-any.whl`. When I run the `Program.py` in `samples/Python/Testbed/`, I can see orders being placed in TWS, but error messages appear as follows: “` Traceback (most recent call last): File “~/some/path/IBJts/samples/Python/Testbed/Program.py”, line 2256, in main() File “~/some/path/IBJts/samples/Python/Testbed/Program.py”, line 2246, in main app.run() File “~/some/path/IBJts/samples/Python/Testbed/Program.py”, line 132, in countReqId_ return fn(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^ File “~/path_to_venv/lib/python3.11/site-packages/ibapi/client.py”, line 442, in run self.decoder.interpret(fields, msgId) File “~/path_to_venv/lib/python3.11/site-packages/ibapi/decoder.py”, line 1578, in interpret self.interpretWithSignature(fields, handleInfo) File “~/path_to_venv/lib/python3.11/site-packages/ibapi/decoder.py”, line 1562, in interpretWithSignature method(*args) File “~/some/path/IBJts/samples/Python/Testbed/Program.py”, line 535, in managedAccounts self.start() File “~/some/path/IBJts/samples/Python/Testbed/Program.py”, line 286, in start self.orderOperations_req() File ~/some/path/IBJts/samples/Python/Testbed/Program.py”, line 77, in fn2 fn(self) File “~/some/path//IBJts/samples/Python/Testbed/Program.py”, line 1850, in orderOperations_req self.bracketSample() File “~/some/path/IBJts/samples/Python/Testbed/Program.py”, line 1511, in bracketSample self.placeOrder(o.orderId, ContractSamples.EuropeanStock(), o) File “~/some/path/IBJts/samples/Python/Testbed/Program.py”, line 132, in countReqId_ return fn(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^ File “~/path_to_venv/lib/python3.11/site-packages/ibapi/client.py”, line 1245, in placeOrder placeOrderRequestProto = createPlaceOrderRequestProto(orderId, contract, order) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “~/path_to_venv/lib/python3.11/site-packages/ibapi/client_utils.py”, line 50, in createPlaceOrderRequestProto contractProto = createContractProto(contract, order) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “~/path_to_venv/lib/python3.11/site-packages/ibapi/client_utils.py”, line 67, in createContractProto if contract.primaryExchange: contractProto.primaryExchange = contract.primaryExchange ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: Protocol message Contract has no “primaryExchange” field. “` Which steps might I have done incorrectly? I am on a MacOS arm using my own virtual environment (not conda based). Thank you in advance!

  • Vax Datex

    Why no include the link to the download repo right here in this article? Pointing verbally to another page without a link is just bad form and surprising to find a lack of basic understanding of how to structure documents on the web in 2026.

  • Derrick Tate

    I believe the documentation needs to be tested. It could just be me. Date: 2026-04-12 @ 10:03 am On Windows 11 I was testing with: python -V – Python 3.14.2 I had to do the following just to start getting responses. Run the commands in the command-line: python -m pip install setuptools python -m pip install google-api-python-client google-auth python -m pip uninstall protobuf -y python -m pip install protobuf==5.29.3 Lastly, I ran the following command as the Python.py script seems to have been updated: C:\TWS API\samples\Python\Testbed>python Program.py -p 7497 The script still fails, but I am at least now able to debug and troubleshoot. – I am a developer, so I decided to help those who might need a touch of help.

  • Derrick Tate

    aaa bbb

  • Derrick Tate

    I was hope the HTML tags would help better format the text and I would have submitted a bit more readable response. I believe I will repost a couple of times for clarity.

  • Derrick Tate

    I believe the documentation needs to be tested. It could just be me. I am using Windows 11. I am using Python 3.14.2.

  • Derrick Tate

    Run the commands in the command-line:

  • Derrick Tate

    python -m pip install setuptools

  • Derrick Tate

    python -m pip install google-api-python-client google-auth

Leave a Reply

Disclosure: Interactive Brokers

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.

Disclosure: API Examples Discussed

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.

IBKR Campus Newsletters

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.