Why do I get an "actxserver" error when trying to connect to Interactive Brokers Trader Workstation with the "ibtws" command?

13 views (last 30 days)
I have Interactive Brokers (IB) Trader Workstation and MATLAB Trading Toolbox installed on my machine. However, when I execute the following example command, to establish a connection object, from the Trading Toolbox documentation, I get an error. 
Command from documentation:
>> ib = ibtws('',7496)
Error received:
Error using actxserver (line 90)
Server creation failed. Invalid ProgID 'TWS.TwsCtrl.1'.
Error in ibtws (line 38)
What is the cause of this error and what can I do to fix the issue?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 2 Sep 2022
Edited: MathWorks Support Team on 2 Sep 2022
The aforementioned error indicates that the Trading Toolbox in MATLAB cannot establish a connection to the IB Trader Workstation ActiveX-based API. This can result when:
  1. the ActiveX APIs is not enabled within the installation of the IB Trader Workstation,
  2. the input port number does not match the one used by TWS, or
  3. if you are running an incompatible version of MATLAB or Trader Workstation.
As of MATLAB R2014a, both 32-Bit and 64-Bit MATLAB work with the IB Trader Workstation. In addition, please note that the Interactive Brokers functionality in Trading Toolbox requires a licensed account for IB Trader Workstation.
First, please ensure that you have the latest version of TWS and the IB Trader Workstation API (both linked below) and that you have a licensed account for IB Trader Workstation:
TWS 
Interactive Brokers API
Then, we can verify the TWS API configurations as follows:
 
  1. In the API settings (within Trader Workstation Configuration) please make sure that "Enable ActiveX and Socket Clients" is checked, and "Read-Ony API" is unchecked. You can access the API settings by navigating to 'File > Global Configuration > API > Settings' on the  main window of TWS. 
  2. In addition, please check that the Socket port number in the "ibtws" command is identical to one in the API settings.
If this does not resolve the issue, please verify whether you can use the COM interface outside of MATLAB (i.e. Visual Basic script):
  • Open a new EXCEL file
  • Enter 'ALT + F11' to open Visual Basic (VB) Editor
  • Locate the "Project - VBAProject" block the top left corner in the popped out window
  • Right click on your workbook name (e.g. Sheet1)
  • Select 'Insert > Module'
Paste the VB script below to the module:
Sub IBconnect()
Dim ibtws As Object
Set ibtws = CreateObject("TWS.TwsCtrl")
MsgBox ("success")
End Sub
  • Enter 'Crtl + S' to save the VB script. Select "Excel Macro-Enabled Workbook" from the "Save as type" drop-down list and click the "Save" button.
  • Run the VB script by clicking the green arrow button  
If the output from running the script is not "success" then likely there is something broken with the IB Trader API installation. It would be best to contact the IB support since the VB script is checking connection outside of MATLAB and the resulting error is not caused due to MATLAB. 
 
Additionally, I would suggest to first (before reaching out to IB) try the suggestions in the MATLAB Answers post linked below as other users came across the same issue and have gotten next steps from IB:
The BaT file provided by IB helps establish connection with Excel using DDE connection and not ActiveX API connection which is used by MATLAB.
In order to instantiate the connection between IB and MATLAB, the system needs to recognize the ActiveX API program ID 'TWS.TwsCtrl'. 
If the VB script won't run it's likely because it can't find the Trader Workstation program ID. This indicates that there is something going wrong with the IB installation files. If this is the case, I would recommend contacting the IB Support for help troubleshooting the IB installation files. 
  2 Comments
Walter Roberson
Walter Roberson on 30 Nov 2018
Diego Ochoa comments,
This answer DOES NOT solve the problem for Matlab 2018b and the latest IB API (9.73+) since the code that sends ProdID as "TWS.TwsCtrl.1" is still present. This answer is not accurate and the described procedure does not solve the issue.

Sign in to comment.

More Answers (1)

Yair Altman
Yair Altman on 3 Aug 2018
Edited: MathWorks Support Team on 19 May 2021
Sometime in recent years, presumably around TWS API 9.70, IB changed their COM server's ProgID from 'TWS.TwsCtrl.1' to 'TWS.TwsCtrl'. This breaks the Trading Toolbox code, which assumes a ProgId of 'TWS.TwsCtrl.1'. Since the Trading Toolbox's code is encrypted, you cannot modify its expected ProgId. The best you could do is to try to uninstall your API and install an old version (possibly with the assistance of IB). Note that this might break other things for you - the old API version might not be fully supported by IB today, but it's worth trying. And of course you could report this to MathWorks and hope that a fix or workaround will be provided in some future release.
Another potential reason might be if you're running on Mac or Linux: Trading Toolbox support for Interactive Brokers is limited to Windows only. This is clearly mentioned in the documented system requirements. On Mac & Linux you will see the error that you mentioned because these OSes don't support COM, on which the Trading Toolbox connector to IB is based.
You can try my Java-API-based connector ( IB-Matlab ), which does not rely on COM and does not exhibit the COM interface's problems. The reliance on Java also means that IB-Matlab works on all Matlab releases since 2008, all Matlab platforms (MacOS, Linux, Windows), and all IB API versions.
Yair Altman

Tags

No tags entered yet.

Products


Release

R2013b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!