Back

Live trading IB: GetInitialMarginRequirement?

Hi, I was wondering how can I check initialMarginRequirement for specific security programmatically before executing the order and calculating it's quantity? What Security Margin Model does live trading algo implement. How can I access IB's initial margin requirements? 

Thanky you in advance for help! 

Update Backtest







The security margin model has a few methods that can help determine the margin requirements.  The method GetInitialMarginRequiredForOrder(Security security, Order order) gets the total margin required to execute the specified order in units of the account currency including fees. If there is no order, a more general method GetInitialMarginRequirement(Security security) gets the percentage of an order's absolute cost that must be held in free cash in order to place the order.

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Gurumeher Sawhney  thank you! 

But as I understand GetInitialMarginRequiredForOrder is a protected method and can only be called within a class itself or its ancestors. 

At the same time, Securities[symbol].MarginModel property is of IBuyingPowerModel type. 

So to use any method of SecurityMarginModel interface implementation I need to cast that to a proper type then call a public method? 

In live trading mode - paper account through IB - how do I need to cast the MarginModel property to call the public methods, I wonder?

0

You're right, since Python is not strongly-typed it was easier to access those methods. When trading equities the initial margin requirement is simply 1/leverage. The IBuyingPowerModel type has similar methods such as HasSufficientBuyingPowerForOrder(SecurityPortfolioManager portfolio, Security security, Order order) and GetBuyingPower(SecurityPortfolioManager portfolio, Security security, OrderDirection direction) which will return the values that are needed.

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed