softwarespartan / IB4m

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

Accountsummary request works only once #43

Closed Despair2000 closed 5 years ago

Despair2000 commented 5 years ago

I have a peculiar problem.

This is what is happening:

all the above works fine.

At the end of the loop it shall request an account summary again to see if there are still enough funds available to run the strategy again on another symbol and here the program freezes. I can see in the log file that the request is send to the API correctly and also that the API answers with the correct response (the account summary) but the data never shows up in the buffer.

When I at this point exit the program and try to request an account summary manually it is the same - it does not work. To make it work again I have to issue CLEAR ALL (to remove the listener) and reconnect to the TWS (just disconnect and reconnect without clear all does not work). After reconnection it works all fine again. I can also request an account summary several times in a row without problems. But when I run the strategy again the above happens again. All works fine until the second request for an account summary when the program freezes.

So it seems like one (or several) of the IB4m-functions I call inbetween the first and second summary request screws with the listener and makes it stop working.

@softwarespartan: Somehow this reminds me of issue 34 I opened sometime ago. Back then I was trying to make IB4m work in a compiled application and also then I could see the correct request and API-answers in the gateways log file but the data never made it into the buffer. However now this is happening with an uncompiled m-file.

Any help would be greatly appreciated!

Despair2000 commented 5 years ago

I just had to notice that the problem is not specific to a request of the account summary. I commented out the summary request and the program got stuck in the next loop iteration when requesting historical data in the exat same way. Is my code maybe lacking something? Maybe that I must cancel one request before I can send a new one or something similar?

softwarespartan commented 5 years ago

Ok, let me look into it. There is a reader thread that is required for +9.73 api and this thread gets started in the connect call. Likely something happened (exception etc internally) that causes the thread to get interrupted.

I really dislike having to manage that reader thread for exactly these reasons. I sent IB a note about this a few times but alas here we are.

Sent from my iPhone

On Dec 3, 2018, at 4:19 PM, Despair2000 notifications@github.com wrote:

I just had to notice that the problem is not prefix to a request of the account summary. I commented out the summary request and the program go stuck in the next loop iteration when requesting historical data.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

Despair2000 commented 5 years ago

I understand. Would be awesome if you could create a workaround of some sort.

Thanks in advance!

Despair2000 commented 5 years ago

Is there maybe a way to reset this reader from within matlab without issuing clear all? Then I could disconnect and reconnect to TWS at every loop-iteration of my strategy. A pretty crude solution but the only idea I have. :-(

Despair2000 commented 5 years ago

I now fixed this problem in a REALLY ugly way. At the end of every loop-iteration I disconnect from the TWS then I have to issue twice (!) "clear session" (with only one clear session it does not work - I can't reconnect to the TWS) then I reconnect.

I do not like this solution but it is the best I could do. I hope there will be an update to IB4m soon that solves this bug. Actually I'm pretty amazed that I seem to be the only one with this problem.

Tukan-Kolor commented 5 years ago

I had a Java out of heap memory problem that would occur about once daily during the trade day. I solved it in the same brute force manner. (I probably created that problem for myself with so many historical data calls instead of subscribing to realtime data)

softwarespartan commented 5 years ago

Did you try increase Java heap size in matlab?

https://www.mathworks.com/matlabcentral/answers/337797-java-heap-size-is-not-accessing-all-available-ram https://www.mathworks.com/matlabcentral/answers/337797-java-heap-size-is-not-accessing-all-available-ram

-abel

On Dec 6, 2018, at 4:24 PM, Tukan-Kolor notifications@github.com wrote:

I had a Java out of heap memory problem that would occur about once daily during the trade day. I solved it in the same brute force manner. (I probably created that problem for myself with so many historical data calls instead of subscribing to realtime data)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/softwarespartan/IB4m/issues/43#issuecomment-445034702, or mute the thread https://github.com/notifications/unsubscribe-auth/AEWq1E250dXfsHHcZZVjl8v41HULAw7Rks5u2YsbgaJpZM4Y-3gx.

Tukan-Kolor commented 5 years ago

Hey nice! Thanks Abel, I am learning something new all the time.

Despair2000 commented 5 years ago

@softwarespartan: Did you have the time to look into this?

Despair2000 commented 5 years ago

I don't want to be a pain in the *** and I understand that you have other more important things to do but I'm confronted with this problem in more and more situations. Now for example I also have to disconnect (and reconnect) in the fashion mentioned above before I make an order to avoid the program freezing. I'd be utmost grateful if you could have a look at it because it is really impairing the usability of IB4m.

Thanks in advance!

softwarespartan commented 5 years ago

No worries, apologies for delay — it’s that time of year. Appreciate the follow up. A fix is in the works and will get it committed to the repo asap.

-abel

On Dec 20, 2018, at 1:33 AM, Despair2000 notifications@github.com wrote:

I don't want to be a pain in the *** and I understand that you have other more important things to do but I'm confronted with this problem in more and more situations. Now for example I also have to disconnect (and reconnect) in the fashion mentioned above before I make an order to avoid the program freezing. I'd be utmost grateful if you could have a look at it because it is really impairing the usability of IB4m.

Thanks in advance!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/softwarespartan/IB4m/issues/43#issuecomment-448932812, or mute the thread https://github.com/notifications/unsubscribe-auth/AEWq1KNQnqth-khwncyknY5G6ikeIXOkks5u61lQgaJpZM4Y-3gx.

softwarespartan commented 5 years ago

Can you give a summary of the API calls you’re making in your strategy.

You are welcome to just email me directly: brown2179gmailcom

Thanks -abel

On Dec 3, 2018, at 4:19 PM, Despair2000 notifications@github.com wrote:

I just had to notice that the problem is not prefix to a request of the account summary. I commented out the summary request and the program go stuck in the next loop iteration when requesting historical data.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/softwarespartan/IB4m/issues/43#issuecomment-443874263, or mute the thread https://github.com/notifications/unsubscribe-auth/AEWq1FriAR0gZJs6x5gwB7S8p7mkQxTaks5u1ZVtgaJpZM4Y-3gx.