I continue to have connection problems with IB in certain cases and I get the infamous message IB: No connection could be made because the target machine actively refused it.
There are numerous posts concerning this message!
I have traced down the problem and I quite firmly believe that this is a bug of the Ninja IB adapter.
Here my findings:
The content of the message makes sense: It means that TWS is already connected to Ninja and therefore a second connection is refused.
Can TWS already be connected to TWS? Yes it can and the typical case is that you have two or more IB accounts and one of them is already connected.
The IB adapter will then - erroneosly - take the running instance of TWS for good and will try to connect. But it will fail since the other IB connection is already there.
Here a fix proposal for your software guys:
Please check - when you get that message or always- wether there is another TWS connection already made in case you find the TWS application running. If you find another IB connection open then please load a new TWS instance instead and connect to the new TWS instance.
for example (pseudo-code)
ConnectToTWSAdapter(){
List<Connection> connections=FindAllActiveConnections();
List<TWSInstance> twsInstances = FindAllRunningIstances(TWS);
List<TWSInstance> twsAvailable=new List<TWSInstance>(twsInstances);
// create a copy to work on
foreach(Connection c in connections){
if c.Adapter==IB && c.IsConnected) {
twsavailable.Remove(c.twsInstance);
}
}
TWSInstance useMeTWS=null;
if(twsAvailable.Count>0) useMeTWS=twsAvailable[0];
if(useMeTWS==null) {
useMeTWS=LoadNewTWSInstance()
}
connectToInstance(useMeTWS);
}
I would welcome if your developers could revise the IB adapter logic and hopefully the above suggestions are useful and appreciated.
Best regards
Andreas
Comment