views:

409

answers:

4

My java skills are limiting me from doing what I want to do.

I am trying to use the Interactive Brokers Java API to see if I can do some algorithmic trading (on paper initially). I want to call a method called ReqMktDepth() which is in a class called EClientSocket.

The EClientSocket constructor requires an object of type AnyWrapper to be passed, and AnyWrapper is an interface not a concrete class. In theory how do I go about passing an AnyWrapper class to the EClientSocket constructor.

If I need to provide more info please let me know.

+6  A: 

You need to create a class that implements AnyWrapper (using the "implements" keyword) and then you must provide the definitions for any methods defined by that interface.

Here's one simple tutorial:

http://www.uweb.ucsb.edu/~cdecuir/Polymorphism.html

BobbyShaftoe
I am using some other companies API and don't really understand what the methods do, can my implementation just be empty?
Ankur
It depends on the specific. There might be a concrete class that implements AnyWrapper already in the third party API. Essentially, it cannot be empty unless AnyWrapper is empty; that is, you must define every method defined by an interface you wish to implement.
BobbyShaftoe
+4  A: 

You can either create your own class which implements AnyWrapper interface as Bobby suggests. or Use any other class(present in the library/jar/namespace) which already extends from AnyWrapper interface like the EWrapper, class which already has an implementation of AnyWrapper.

see -> http://www.interactivebrokers.com/php/apiUsersGuide/apiguide/java/eclientsocket.htm

AB Kolan
:) Yeah, I didn't think about that.
BobbyShaftoe
Thanks I've been trying to find that for ages.
Ankur
+2  A: 

You should probably use some class in that API you use which implements the AnyWrapper interface. You could have a look into the JavaDoc of that API or use your IDE's features (something like show type hierarchy) to find out which classes implement AnyWrapper, and pass one of them.

Fabian Steeg
+2  A: 

Several other answers have pointed out that you can create an instance of AnyWrapper by either implementing it yourself or by finding an existing class and passing in an instance of that class.

However it seems to me that what you are doing is not likely to succeed. You are trying to call a method whose argument is completely unknown to you. You need to read the documentation about that method and find out what the AnyWrapper is for and how it will be used. Maybe there just needs to be something provided, but maybe AnyWrapper has some responsibility that the EClientSocket needs.

This kind of programming by trial and error can lead to some serious problems down the road. For one thing, certain methods are not safe to call unless other safeguards are taken. Certain methods have major performance or security implications. In this case I think you really need to find out what it is you're trying to do before you figure out how to do it.

Mr. Shiny and New