MATLAB Answers


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

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?


No tags entered yet.




2 Answers

Answer by MathWorks Support Team on 19 Jun 2019
Edited by MathWorks Support Team on 19 Jun 2019
 Accepted Answer

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 the installation of the IB Trader Workstation did not include the ActiveX APIs, the input port number does not match the one use by TWS, or if the user is running an incompatible version of MATLAB or Trader Workstation. Also, The Interactive Brokers functionality in Trading Toolbox require a licensed account for IB Trader Workstation. As of MATLAB R2014a, both 32-Bit and 64-Bit MATLAB work with the IB Trader Workstation.
If the user meets the requirements, the APIs can be installed directly. The latest version of the IB Trader Workstation APIs can be found at the following location, after accepting the terms of agreement:
To verify that the port numbers match, you can navigate to 'File > Global Configuration > API' on the main window of TWS. When you select 'API > Settings', you will see the Socket port number. When calling 'ibtws', the input port (second input) must be identical to the number you see in the Settings.
If this does not resolve the issue, verify whether you can use the COM interface outside MATLAB, i.e. in a Visual Basic Script containing:
Sub IBconnect()
Dim ibtws As Object
Set ibtws = CreateObject("TWS.TwsCtrl")
MsgBox ("success")
End Sub
If the output of this command is not "success", there is something broken with the IB Trader API installation and you should contact IB support.


Show 1 older comment
Did you ever receive a response from Mathworks? Ihave the same configuration as you and running into the same problems.
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.
I can confirm it still doesn't connect with Matlab 2018b or 2019b, using the latest IB API (9.76) and the latest "stable" IB API (9.72). The bug is still present, sending ProgID as "TWS.TwsCtrl.1" instead of "TWS.TwsCtrl". Can we get a fix, Mathworks? And if so, when?
After reading other threads I found the tip to use the old API 9.71.06 and I got it to connect, although then found other bugs and couldn't even run the basic sample examples.

Sign in to comment.

Answer by Yair Altman on 3 Aug 2018
Edited by Yair Altman on 3 Aug 2018

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


Sign in to comment.