BrokerIB.exe: GetTradingInterface() returns null


I've been using the BrokerIB.exe together with Interactive Brokers for about five years, without any problem.

This is the code I have

ibc = GetTradingInterface("IB");
for ( i = 0; i < 10 && ( ibc.IsConnected() != 2 AND ibc.IsConnected() != 3 ); i++ ) 
  ibc.Sleep( 200 );

This evening, it stopped working with the error message

COM/object handle is null

The AB log trace displays the same message. As far as I can tell, the connection between AB and the BrokerIB.exe is broken.

I have checked the IB settings on Edit -> Global Configuration -> API -> Settings, and they haven't changed.

The BrokerIB.exe itself seems to be working perfectly. It retrieves the Portfolio and Pending Orders from IB perfectly. However, it displays the messages

ID=2147483647. Error 321. Error validating request: - 'be' : cause -Invalid account code 'UxxxxxxA'.
ID=2147483647. Error 321. Error validating request: - 'be' : cause -The account code is required for this operation.
Connection established OK. Next order ID=19414
ID=-1. Error 2106. HMDS data farm connection is OK: ushmds
Connection established OK. Next order ID=19414
Available accounts: UxxxxxxA, Uxxxxxx, Uyyyyyy,
Using FA account Uxxxxxx

These messages have always been displayed, so I don't think they are related to my problem.

I have two accounts Uxxxxxx and Uyyyyyy. How does IB decide which use one to use as the FA account, with the letter 'A' appended at the end? I haven't programmed this FA account anywhere in my code. The last message seems to imply that it uses Uxxxxxx as the FA account, instead of UxxxxxxA.

Many thanks,

Most likely antivirus or other "registry cleaner" that you are running on your system unregistered BrokerIB COM server in the Windows registry (HKEY_CLASSES_ROOT). To fix that you need to right click on BrokerIB.exe and select "Run As Administrator". Just once. That should be enough to fix missing OLE registration.


Great! That solved it. Updated as a comment in my code, so that I don't forget the next time it happens.

Many thanks Tomasz.


Hi Paul,
I have a similar problem with Error 321, which says I have 2 accounts available and one of them is just the actual one with an "A" attached to it. While orders can still go through, I cannot retrieve certain account information like position info. I searched all over the Internet and this seems to be the only relevant thread. Can you advise whether you solved that problem as well?


I was never able to solve the problem. In my case, I was using two accounts, and IBC always had problems. In the end I just removed the second account, and only use one account.


Did you use


As per documentation

SetInfoAccount ( string Account )
(new in 1.3.5)

This function changes the account which is displayed in the "account information" window and "portfolio" tabs.
It does NOT change account used for orders.

Separation of order and viewing accounts allows directing orders to any account withing changing any views, i.e. you can monitor/view "All" account - that displays cumulative information for all F&F/FA accounts or any other account while placing orders for other accounts.

By default viewing information is the "ALL" account and in most cases there is no need to change it as it receives updates from all sub-accounts.

Note that IB uses "A" subscript to designate "All" account that is aggregate of all subaccounts. So if your FA account has a number of F1234, you need to add "A" suffix to it to get aggregate data:

To use aggregated account:


To use individual account:

ibc.SetInfoAccount("F1234"); // set individual account

Thanks Tomasz. This does enable IB Controller to show portfolio and account info. However, I do also wonder, since I have only one account there, why is there showing the "A" account anyway? BTW the Error wasn't there before, and only started to occur very recently.

Also, I am doing a periodic scan for signals on a portfolio containing hundreds of symbols, so while using SetInfoAccount() function, the Portfolio tab, as well as the Portfolio page in IB gets refreshed each time 1 symbol is being calculated for signal. This seems to cause some of the signals not to be able to sent to IB. Any method to have the SetInfoAccount() run only once for a scan?

The "A" (aggregated) account is a feature of F&F (Friends and Family) and FA (Fin Advisor) accounts.

Yes you can (and should) call SetInfoAccount as rarely as possible
The way Traders Workstation functions is that TWS has significant delay between setting account and receiving account data. This can be even more than 1 second.

You can do things once per scan easily

if( Status("stocknum")== 0 ) 
// this will be done once per Analysis run 
1 Like

Fantastic! Thanks Tomasz I'll give it a try and report back.

Indeed, SetInfoAccount in every run of the code blocks my computer with overload. Is it ok if I call it only once at the begginning of the trading sesion using the following code? My question is: when does SetInfoAccount get lost so I need to refresh it?


		if( Nz( StaticVarGet("InfoAccount") ) == 0 )
			StaticVarSet("InfoAccount", 1);	

You should NOT call it if account does not change. I guess that you do NOT need to change account with every code run (with every chart refresh). Info account is for viewing information. TWS will go bananas if you change account dozens of times per second. It does not get "lost". TWS will use whatever you set once and it will keep it.


Calling SetInfoAccount only once per trading session (as per the code above with static vars) fixed all the problems.

I suggest adding a line in the IBcontroller documentation explaining that SetInfoAccount should not be called in every run of the code but only once. This is clear in this forum but it is missing in the documentation. It will help others to not experience the problems I had.

Thank you

1 Like