¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

request margin without whatif


 

Hi,

1)I know whatif orders can be used to check the margin impact of an order, but this depends on the open position before the trade, and is not what I need.
I would like to check the margin of individual futures, independently of the open position, i.e. the information which is available in the contract details in TWS.under:

Current?Margin?Requirements
Intraday Initial
Intraday Maintenance
Overnight Initial
Overnight Maintenance

I check carefully the ContractDetails? class properties, and I do not see it there.
How can It be obtained via API?
It would be very important to assess the expected return on different trades in an objective way, independently of the open positions before the trade is placed.

2)In a similar way? would also like to obtain the margin impact of combo orders, without using whatif orders, because of the same reason, i.e. the result of whatif depends on the currently opened positions, so it is not an objective measure of the margin impact,

I think 1) should be possible, since this information is available in TWS, while for 2) a span calculator may be needed, and if someone knows a python api to use I would really appreciate.

Thanks
QT


 

You are correct: ContractDetails() does not provide information about margin requirements. This has led to using the solution where you place a whatif-order and compare the account margin requirement before and after the whatif-order. This results in the margin requirement, independent on whether you already have an open position in this instrument.


 

Hi,
I did some extensive testing and the margin computed as -(margin before-margin after) depends on the opened positions.
For example if you have a ZC position long already opened, and try a what-if for a short ZW, the margin will computed for the spread ZC-ZW, which is reduced with respect to the ZW short position only.
I need to create a table with all the margins, using what-if is slow. I could get it by running what-if on all contract , using a paper trading account with no open positions, to avoid the problem mentioned above, and save the data for easy and fast access, but since that info is in TWS, it would be nice to have it in the API as well.

Thasnk

GT


 

I don't think that your calculation is correct. In your example is the Before account margin requirement equal to the ZC margin requirement. The what-if trade consists of selling 1 contract ZW. The margin requirement for one contract ZW will therefore be added to the account margin requirement. The After account margin requirement is thus the sum of the margin for one ZC plus margin for one ZW. Therefore:

Margin one contract ZW = Abs(After - Before)

I am using the Absolute so that you can also handle cases properly where you already had a position in the contract for which you want to determine the margin requirement.


 

As you can see on the CME website there is a 50% credit on ZC-ZW spread,https://www.cmegroup.com/clearing/margins/inters.html#exchange=CBT&sector=AGRICULTURE&pageNumber=1
IB takes this into account when computing margin impact, so that opening a naked ZC position, or opening a ZC position in an account with a ZW opposite position already opened gives different
after-before margins, even if the order is the same. It has nothing to do with absolute value of anything.

I am totally sure about this, you can check yourself , using the API or the check margin impact option in TWS.

What-if results depends on the already opened positions as I said, so the only way to get the naked margin, is to use whatif on an empty account, using the paper account for example, but there should a simpler way, since this information is available in TWS.


 

I am looking for exactly the same thing. I contacted IB and they said it was currently not possible via the API. Which is annoying because clearly the information is available on TWS.