softwarespartan / IB4m

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

Buffer remains empty? #34

Closed Despair2000 closed 5 years ago

Despair2000 commented 5 years ago

Hi Abel,

I experience a really annoying problem and slowly I’m growing desperate.

I’m using your IB4m and it works great for me so far. It works fine on my Mac it also works fine on my PC with windows 7 but I can not make it work compiled on another PC running windows 10. (I'm deploying my ready strategies on a PC that does not have Matlab installed on it; I'm doing so successfully for other brokers. A difference with IB4m is the use of an external .jar file. So this might be part of the problem. The deployed version is finding the .jar file though since it is utilizing it to connect to the gateway.) The computer connects to the gateway and sends all requests fine and I see also in the API messages that it sends my requests to the IB server and that the server replies as it should. For example when I request an account summary I see the requested data in the messages BUT somehow the data never makes it into the FIFO buffer. First I thought I just would have to wait a little longer but no matter how long I wait the buffer remains empty (buf.isEmpty = true). Running the same code on one of my other computers works without problems.

If you have an idea what might be wrong I’d be extremely grateful!

softwarespartan commented 5 years ago

Apologies for delay

Do you have he Trading Toolbox installed on the Windows box by chance?

This often happens because the trading toolbox has a conflicting jar file that gets automatically added the the static Java path at install.

Sent from my iPhone

On Aug 31, 2018, at 6:10 AM, Despair2000 notifications@github.com wrote:

Hi Abel,

I experience a really annoying problem and slowly I’m growing desperate.

I’m using your IB4m and it works great for me so far. It works fine on my Mac it also works fine on my PC with windows 7 but I can not make it work on another PC running windows 10. The computer connects to the TWS and sends all requests fine and I see also in the API messages (I run it via IB gateway) that it sends my requests to the IB server and that the server replies as it should. For example when I request an account summary I see the requested data in the messages BUT somehow the data never makes it into the FIFO buffer. First I thought I just would have to wait a little longer but no matter how long I wait the buffer remains empty (buf.isEmpty = true). Running the same code on one of my other computers works without problems.

If you have an idea what might be wrong I’d be extremely grateful!

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

Despair2000 commented 5 years ago

No, trading toolbox is not installed.

Also it works to connect and for example create a contract. So the .jar file seems to work. It is just that when I send some sort of request the api replies correctly with the requested data, I can see this in the log. But the requested data somehow never pops up in the buffer.

softwarespartan commented 5 years ago

Is same version of matlab on both windows setups?

Sent from my iPhone

On Aug 31, 2018, at 3:20 PM, Despair2000 notifications@github.com wrote:

No, trading toolbox is not installed.

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

Despair2000 commented 5 years ago

I develop on the windows 7 machine, then compile the ready application and deploy it to the windows 10 machine. This includes the matlab runtime so both versions are identical.

Despair2000 commented 5 years ago

Can this problem maybe be caused by a path that was not set correctly?

softwarespartan commented 5 years ago

In not sure . Since you’re compiling an application it’s not clear what gets added to the runtime. My guess is that the IB4m jar is not added when compiled and that some other version of the jar was included from the trading toolbox.

Can you run on windows 10 with matlab and ib4m directly (without the compiler). If that works for you then clearly something behind the scene in the compiler configuration

Sent from my iPhone

On Sep 2, 2018, at 5:42 AM, Despair2000 notifications@github.com wrote:

Can this problem maybe be caused by a path that was not set correctly?

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

Despair2000 commented 5 years ago

External jar files are not added to the runtime while compiling, you have to copy them to the machine you deploy the application to and specify the path in the javaclasspath.txt. This works correctly I'm 99% sure. If the jar file was not accessible I could not call any functions from it (like for example connect to the gateway) or am I wrong?

I sadly have no access to a windows 10 PC with matlab on and the laptop I run it on is too weak to install matlab on it.

I read yesterday night that if a function is used in a callback as string or with feval then you have to specify this functions for the compiler to include. I wondered if this might be part of the problem but the whole callback with listener is implemented in the "initBuffer" java-function. Puh I really do not know what to do about this. :-(

Despair2000 commented 5 years ago

To your idea with Trading Toolbox (I forgot to comment that), I don't have Trading Toolbox installed. Not on the windows 7 machine I'm compiling with and not on the windows 10 machine (obviously since it has no matlab installed). I just had a look which toolboxes are installed on the PC I'm compiling with and the only two toolboxes that I can imagine could conflict with TWS are the database toolbox and the data audition toolbox. Do you have any experience with one of those causing problems?

Despair2000 commented 5 years ago

I now uninstalled several toolboxes but this doesn't change the runtime that is installed along with the app. Obviously the compiler doesn't include unused toolboxes. I also contacted mathwork support with the problem but they say they can't help me because a third-party software (IB4m) is involved in the problem. :-S I somehow lack the knowledge that is required to debug this issue. To be honest I have no clue how exactly the gateway is communicating with the app in detail.

softwarespartan commented 5 years ago

It is nothing to do with the gateway. IB4m works just fine with the gateway.

If you’re going to use the java compiler you might as well use IB API directly in java. If you use complicated MATLAB functions then just compile them to java using the matlab compiler to java and then call them in your IB java program.

This way you’re not taking a java API into MATLAB (i.e. IB4m) just to compile it back to Java using their very complicated tools and runtime.

I don’t have the compiler so very difficult to debug. my sense is that if the Win10 machine can’t even handle install matlab then probably not much hardcore mathematics in the trading algorithm. This means probably easy to use IB java api directly and get rid of matlab (just guessing though).

-abel

On Sep 3, 2018, at 2:42 PM, Despair2000 notifications@github.com wrote:

I now uninstalled several toolboxes but this doesn't change the runtime that is installed along with the app. Obviously the compiler doesn't include unused toolboxes. I also contacted mathwork support with the problem but they say they can't help me because a third-party software (IB4m) is involved in the problem. :-S I somehow lack the knowledge that is required to debug this issue. To be honest I have no clue how exactly the gateway is communicating with the app in detail.

Despair2000 commented 5 years ago

I don't use the java compiler but the usual matlab compiler.

You are of course right, having the whole app written in java would solve this issue but this is no option for me since I have never worked with java and have no knowledge about it. :-S

I also agree that what I'm doing is a little bit back and forth but it works for me very well with algos i wrote for other brokers (which go directly via a web API and don't use java).

On the windows 10 machine it is more an issue of lacking capacity than lacking computational power. It has only a 32GB HDD which is already more than full with just windows installed (don't get me started) and almost all apps are running from flash drives and similar. Anyway it would be (with use of an external HDD) possible to install matlab on it but there are several reasons why I don't want to do so. This is a computer that I use at work and has the advantage of very fast, stable internet and it is running 24/7. This is of course nice for algo-trading. So I develop my algos at home (living outside town with unstable internet), compile them when they are ready and run them in the background on my work PC. This works great so far but it would look really strange if I would start installing matlab on this work PC - you understand.

Now a question that probably is pretty stupid, but I desperate enough to make you laugh. ;-) Does a computer need to have java installed to run IB4m? I still have the feeling that it is something simple that is missing. Just like a PATH not set correctly or similar. But it can't be as simple as the app does not find the jar file. This problem I had before. If the jar-file is not found just trying to connect to the gateway caused several errors. Then I include a javaclasspath.txt in the folder of the deployed up containing the full path to the jar-file. This made it work and now I can call functions from the jar-file but somehow my app doesn't catch the replies from the gateway.

Despair2000 commented 5 years ago

I now bought a laptop that I'm going to install in a closet at work. On this one I will have Matlab installed so I don't have to compile my apps and all hopefully goes fine and I can forget this annoying bug. Thanks for your help anyway and thanks for sharing a so wonderful bit of software like IB4m!