softwarespartan / IB4m

Interactive Brokers API for Matlab
GNU General Public License v2.0
62 stars 21 forks source link

Problem connecting with two clients #103

Closed Despair2000 closed 3 years ago

Despair2000 commented 4 years ago

As I understood it should be possible to for example run the TWS and connect with two separate clientIDs through the API, correct?

If I try to do so I get the following error:

Java exception occurred: java.lang.NullPointerException at com.ib.client.EClientSocket.eDisconnect(EClientSocket.java:281) at com.ib.client.EClientSocket.eDisconnect(EClientSocket.java:245) at com.ib.client.EClientSocket.eConnect(EClientSocket.java:154) at com.ib.client.EClientSocket.eConnect(EClientSocket.java:135)

softwarespartan commented 4 years ago

Can you share the code you’re using that triggers this error?

Sent from my iPhone

On Aug 25, 2020, at 4:57 AM, Despair2000 notifications@github.com wrote:

 As I understood it should be possible to for example run the TWS and connect with two separate clientIDs through the API, correct?

If I try to do so I get the following error:

Java exception occurred: java.lang.NullPointerException at com.ib.client.EClientSocket.eDisconnect(EClientSocket.java:281) at com.ib.client.EClientSocket.eDisconnect(EClientSocket.java:245) at com.ib.client.EClientSocket.eConnect(EClientSocket.java:154) at com.ib.client.EClientSocket.eConnect(EClientSocket.java:135)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

Despair2000 commented 4 years ago

I now realized that the error only occurs if I try to login from a different machine! Trying to login with a second client on the same machine as the first seems to work!

My setup looks like this:

I have a laptop on which I run the TWS (live). Here I also run matlab and connect with IB4m with IP 127.0.0.1 to the TWS. So far I had simultaneously running the gateway logged in to the paper account. Then I have a second computer in the same network. This computer I use for my development and so far always connected to the gateway on the laptop with IP 192.168.1.100, port 7497. This all worked fine. Now I tried to login to the TWS on the laptop from my development-computer (to access the live account instead of the papper account) with IP 192.168.1.100, port 7496, clientID 1 (the laptop is logged in with clientID 0).

session = TWS.Session.getInstance(); eConnect(session.eClientSocket,'192.168.1.100',7496,1);

The above is giving the error. Then this is no big deal since I noticed that when running a second instance of matlab on the same computer it seems to work. So don't waste too much time on it.

softwarespartan commented 4 years ago

OK great. Even if the IB API doesn’t want multiple logins from separate machines, it should not be throwing a null ptr exception. I’ll have a look and see what I can find.

On Aug 25, 2020, at 5:37 AM, Despair2000 notifications@github.com wrote:

I now realized that the error only occurs if I try to login from a different machine! Trying to login with a second client on the same machine as the first seems to work!

My setup looks like this:

I have a laptop on which I run the TWS (live). Here I also run matlab and connect with IB4m with IP 127.0.0.1 to the TWS. So far I had simultaneously running the gateway logged in to the paper account. Then I have a second computer in the same network. This computer I use for my development and so far always connected to the gateway on the laptop with IP 192.168.1.100, port 7497. This all worked fine. Now I tried to login to the TWS on the laptop from my development-computer (to access the live account instead of the papper account) with IP 192.168.1.100, port 7496, clientID 1 (the laptop is logged in with clientID 0).

session = TWS.Session.getInstance(); eConnect(session.eClientSocket,'192.168.1.100',7496,1);

The above is giving the error. Then this is no big deal since I noticed that when running a second instance of matlab on the same computer it seems to work. So don't waste too much time on it.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/softwarespartan/IB4m/issues/103#issuecomment-679918862, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABC2VVH4VJW53VWW2EKR7HDSCOA6NANCNFSM4QKM4F7A.

Despair2000 commented 3 years ago

I want to add some information regarding this "bug". The problem seems to have to do with the TWS specifically. The TWS behaves differently than the gateway. If I have the gateway running on my laptop I have not problem connecting with my second computer in the same network to it but now I tried the same with the TWS running on the laptop (I wanted to debug my order placement and thought it'd be nice to be able to see my orders) and it throws the java exception above even though there is no second client connected to the TWS.

Like I said, I can live with this (don't put too much time on it). Just wanted to add some more info to this peculiar behaviour in case it gives you a "ahhh now I see" ;-).