Test Order Impact (WhatIf)
Test Order Impact (WhatIf)
From the API it is possible to check how a specified trade execution is expected to change the account margin requirements for an account in real time. This is done by creating an Order object which has the IBApi.Order.WhatIf flag set to true. By default, the whatif boolean in Order has a false value, but if set to True in an Order object with is passed to IBApi.EClient.placeOrder, instead of sending the order to a destination the IB server it will undergo a credit check for the expected post-trade margin requirement. The estimated post-trade margin requirement is returned to the IBApi.OrderState object in the [EWrapper.openOrder](/tws-api/doc/order-management/open-orders) callback..
This is equivalent to creating a order ticket in TWS, clicking “Preview”, and viewing the information in the “Margin Impact” panel.
Apart from InitMarginChange, there are other supported variables. For details, please visit: /tws-api/ref/introduction
Note:
It is not recommended for users to submit lots of what-if orders. When a user submits a what-if order for margin preview only, the request is sent to IB credit system for review. In some cases, if user(s) submit lots of what-if orders, the creditman is affected. There is no clear limitation about this what-if feature. However, if you want to use this what-if feature, please:
- keep the ratio: 10 order submissions: 1 what-if request
- do not overuse the what-if request (> 1 what-if request per minute)
- cancel the what-if order after margin review

