softwarespartan / IB4m

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

session.eClientSocket.reqPositions() causes java.lang.NullPointerException #15

Closed dani-alvez closed 6 years ago

dani-alvez commented 6 years ago

thanks for sharing your code, looks very useful! when I run session.eClientSocket.reqPositions() to get open positions without having done any trade, I get a java.lang.NullPointerException and the connection to TWS will be closed. When I have an open position or previously had them, then there won't be any error. Also when I restart TWS or Matlab, still there will be no error. It looks like after the night when the daily trades had been cleared, the error appears again. Can you reproduce this? Is there any fix for that? Thanks for your help. BTW, I'm running your latest version of IB4m, Matlab 2017a and TWS 962.2c with API 9.71.

softwarespartan commented 6 years ago

Thanks for reaching out.

hm … that’s strange. It might be mis-match with the API version and the TWS version. Sometimes they update TWS and it sends some new/updated format and the API tries to grab some value from the tws data stream and it’s not there in the updated version. Maybe, i am just guessing at the moment. Usually these are easy fixes but we’ll see.

I am traveling but will try to look at this over the weekend and get back to you.

Cheers -abel

On Nov 24, 2017, at 6:15 PM, dani-alvez notifications@github.com wrote:

thanks for sharing your code, looks very useful! when I run session.eClientSocket.reqPositions() to get open positions without having done any trade, I get a java.lang.NullPointerException and the connection to TWS will be closed. When I have an open position or previously had them, then there won't be any error. Also when I restart TWS or Matlab, still there will be no error. It looks like after the night when the daily trades had been cleared, the error appears again. Can you reproduce this? Is there any fix for that? Thanks for your help. BTW, I'm running your latest version of IB4m, Matlab 2017a and TWS 962.2c with API 9.71.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/softwarespartan/IB4m/issues/15, or mute the thread https://github.com/notifications/unsubscribe-auth/AEWq1Ecf7cSlWS_tuGHQu75ADIoEb565ks5s504BgaJpZM4QqO40.

softwarespartan commented 6 years ago

Just as a data point ...

I am using TWS 969.0v Nov 22, 2017 with API 9.71 and no issues getting positions when i called it just now.

Looks like, from what you’re saying, only issue when there are no positions and get positions is called (i.e. null pointer from empty list).

Does that sound about correct?

If that is the case, might have to wait until monday so I can clear out paper account and test with zero positions active.

Thanks -abel

On Nov 24, 2017, at 6:15 PM, dani-alvez notifications@github.com wrote:

thanks for sharing your code, looks very useful! when I run session.eClientSocket.reqPositions() to get open positions without having done any trade, I get a java.lang.NullPointerException and the connection to TWS will be closed. When I have an open position or previously had them, then there won't be any error. Also when I restart TWS or Matlab, still there will be no error. It looks like after the night when the daily trades had been cleared, the error appears again. Can you reproduce this? Is there any fix for that? Thanks for your help. BTW, I'm running your latest version of IB4m, Matlab 2017a and TWS 962.2c with API 9.71.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/softwarespartan/IB4m/issues/15, or mute the thread https://github.com/notifications/unsubscribe-auth/AEWq1Ecf7cSlWS_tuGHQu75ADIoEb565ks5s504BgaJpZM4QqO40.

dani-alvez commented 6 years ago

dear Abel, thanks for your quick reply! yes, it seems to happen only when in TWS the activity window is empty, i.e. after old trades have been deleted from there over night. I just installed the latest stable version (968.2g) and the same error happens.

>> TWSSession.eClientSocket.reqPositions();
java.lang.NullPointerException

java.lang.NullPointerException

connection closed ...

thanks, dan

dani-alvez commented 6 years ago

dear Abel, any news on this issue? thanks dan

softwarespartan commented 6 years ago

Hi Dan

Apologies, this has totally slipped my mind (!!)

I think both of email inquiries have been after trading for the week.

Will look into this over the weekend and test on Monday when I can clear out paper account.

Again, apologies for delay. We will get this sorted.

Happy Holidays

-abel

On Dec 15, 2017, at 6:40 PM, dani-alvez notifications@github.com wrote:

dear Abel, any news on this issue? thanks dan

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/softwarespartan/IB4m/issues/15#issuecomment-352138743, or mute the thread https://github.com/notifications/unsubscribe-auth/AEWq1GPltlnWdgkLvPK4GXTwGyj6XAS5ks5tAwOAgaJpZM4QqO40.

softwarespartan commented 6 years ago

Hi Dan

Looking through the IB API, nothing stands out as throwing the null pointer exception. However, since the connection gets closed, that means proly the API tried to read data off the socket for position that didn’t exist and threw an exception. Still doesn’t explain why the callback is fired in the IB API in the first place though. It looks like TWS automatically pushed a round of position updates upon initial API request. This way can get positions when markets are closed and position updates sent when positions change.

At any rate, will have to wait until the markets open tomorrow and try to find some time to step through the code to try to repro the situation.

Thanks -abel

On Dec 15, 2017, at 6:40 PM, dani-alvez notifications@github.com wrote:

dear Abel, any news on this issue? thanks dan

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/softwarespartan/IB4m/issues/15#issuecomment-352138743, or mute the thread https://github.com/notifications/unsubscribe-auth/AEWq1GPltlnWdgkLvPK4GXTwGyj6XAS5ks5tAwOAgaJpZM4QqO40.

softwarespartan commented 6 years ago

Hi Dan

I have pushed update to GitHub which resolves this issue.

Currently, the behavior is not to return a response for empty positions (i.e. no event published for no events provided by TWS).

However, there is a good argument for actually returning an empty set depending on your software architecture convictions.

Either way, let me know if you need anything additional on this or encounter another bug.

Happy Holidays

Cheers -abel

On Dec 15, 2017, at 6:40 PM, dani-alvez notifications@github.com wrote:

dear Abel, any news on this issue? thanks dan

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/softwarespartan/IB4m/issues/15#issuecomment-352138743, or mute the thread https://github.com/notifications/unsubscribe-auth/AEWq1GPltlnWdgkLvPK4GXTwGyj6XAS5ks5tAwOAgaJpZM4QqO40.

dani-alvez commented 6 years ago

Dear Abel, thanks for the fix! enjoy holidays, dan