softwarespartan / IB4m

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

WHATIF - orders #104

Closed Despair2000 closed 3 years ago

Despair2000 commented 3 years ago

I want to find the margin requirement for different option spreads and want to do this by placing a WHATIF orders.

The API-documentation says the results of such a query is returned as IBApi.OrderState object but I'm wondering where do I find this object? I checked for open order, order status and exec details events but all buffers remain empty.

@softwarespartan can you maybe tell me where the result ends up?

Despair2000 commented 3 years ago

@softwarespartan When you look at reqSecDefOptParam could you maybe also have a look at this one? Would be highly appreciated.

softwarespartan commented 3 years ago

OK, will do. Thanks for bumping this

softwarespartan commented 3 years ago

Do you have example for how you're placing the whatif order?

softwarespartan commented 3 years ago

The OrderState object comes in from the OpenOrder events

case 'com.tws.Handler$OpenOrderEvent'        
    notify(                                    ...
       TWS.Events.getInstance()              , ...
        TWS.Events.OPENORDER                 , ...
        TWS.EventData.OpenOrder(event)         ...
    );

which contains an OpenOrder with

public class OpenOrder {

    public final int        orderId   ;
    public final Contract   contract  ;
    public final Order      order     ;
    public final OrderState orderState;

OrderStatus callback is also implemented.

Despair2000 commented 3 years ago

I don't. I will try it today during the afternoon. Maybe it's working and the results end up as OpenOrder event.

Despair2000 commented 3 years ago

I tested it and it works perfectly.

I just didn't understand that the data would generate an openOrder event (although it said so in the documentation). Thanks for pointing this out.

I close the issue.

softwarespartan commented 3 years ago

Excellent