softwarespartan / IB4m

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

Combo Limit with Price per Leg #46

Closed Despair2000 closed 4 years ago

Despair2000 commented 5 years ago

I found in the API documentation that there is an order type that allows you to specify separate limits for each leg of a combo order. This seems to be useful and I'm trying to implement it in matlab but would need some help because of my none existent java knowledge. :-) The following lines are causing trouble for me:

`order.orderComboLegs(new ArrayList<>());

    for(double price : legPrices) {
        OrderComboLeg comboLeg = new OrderComboLeg();
        comboLeg.price(5.0);
        order.orderComboLegs().add(comboLeg);
    }`

Combo market orders work fine for me, it is just this part which is obviously setting the limits that leaves me puzzled.

Thanks in advance!

Despair2000 commented 5 years ago

I think I figured out this one. Wasn't able to test it though (markets are still closed).

       leg1 = com.ib.client.OrderComboLeg;
       leg2 = com.ib.client.OrderComboLeg;
       leg1.price(limit1);
       leg2.price(limit2);
       order.orderComboLegs.add({leg1, leg2});
Despair2000 commented 5 years ago

The last line must be replaced by:

order.orderComboLegs.add(leg1); order.orderComboLegs.add(leg2);

But I still get the error: leg prices don't match combo price. :-S

softwarespartan commented 5 years ago

can you share link to the API documentation you're referring to ? Also, if you're able to share more complete example that would be helpful. Please correct me if I'm wrong, but you get the error when you submit the order not when you add the legs, right?

Despair2000 commented 5 years ago

I'm trying to construct a "Combo Limit with Price per Leg" order. Here is the link to the documentation:

https://interactivebrokers.github.io/tws-api/basic_orders.html

And yes, the error occurs after submitting the order. Adding the legs seems to work or at least doesn't throw an error.

It follows my complete code to create the order (my best guess but not working):

       order = com.ib.client.Order;
       order.totalQuantity(quantity);
       order.orderType('LMT');
       leg1 = com.ib.client.OrderComboLeg;
       leg2 = com.ib.client.OrderComboLeg;
       leg1.price(limit1);
       leg2.price(limit2);
       order.orderComboLegs.add(leg1);
       order.orderComboLegs.add(leg2);

       order.orderId = getNextOrderID;    % (this works, didn't include function)

       routingVector = java.util.Vector();
       params = com.ib.client.TagValue('NonGuaranteed','1');
       routingVector.add(params);
       order.smartComboRoutingParams(routingVector);
Despair2000 commented 5 years ago

BTW There may be even an error in the API documentation. I also found a mistake in the documentation of the "Relative Market Combo" order. :-S

ecpgieicg commented 5 years ago

Out of curiosity, could you share what IB customer support said about this? Thanks in advance.

Despair2000 commented 5 years ago

I never got a satisfying answer. Just a "it should work" and when I send them my log-file I got the reply all looks fine. So finally I gave up on this. If I remember right I could make work a combo limit order (giving just one limit for the whole combo), REL + MKT and REL + LMT worked also but specifying a separate limit for each leg never worked for me. If you find the solution I'm still eager to hear it. :-)

ecpgieicg commented 5 years ago

hmm. Do we have any solid indication that limiting price by leg is actually supported? There isn't a way to do that in TWS, for example.

The first customer support could be a relatively new/junior person. But at the same time, s/he is likely more willing to spend time with you. Did you try working within him/her to debug error messages? After some trials and errors, s/he may be able to connect you to a more senior person. You could get a better confirmation that limiting price by leg is actually supported, or not.

The other thing is to try Hong Kong office -- I assume you have been using the NA office up to now. Their office hour starts at 8:30pm EDT. There is a different API support person there. He may have a different perspective.

Despair2000 commented 5 years ago

Well the function is described in the API documentation, scroll a little down and you will find it: https://interactivebrokers.github.io/tws-api/basic_orders.html

As I said I had no luck with the customer support. Dealing with the support is always pretty time-consuming because the chat is lagging ridiculously (I wait always 5-10min for every reply). As I understood the person I was chatting with he was able to place a combo order with limit per leg through the TWS but he couldn't tell why it didn't work for me (I also send him the log file). I gave up pretty soon on this though.

ecpgieicg commented 4 years ago

Strange.

Re customer support. The chat response (from Ted) tends to be quite fast for me. However, he does follow a pretty stringent guideline of what he will support and will boot you out if you ask beyond the basic connectivity + whether specific method is working questions.

The person on phone seems a lot more able to spend time debugging with me and is a lot more liberal with what he supports.

Despair2000 commented 4 years ago

I actually never tried the phone support, just the chat. I got there help several times but not for the problem described in this thread. However I wasn't very persistent and simply gave up on this order type. I'm using now REL + LMT orders instead with good results.

ecpgieicg commented 4 years ago

I see. Glad to hear.