Hi, is there any way for CalculateOrderQuantity or setHolding to take into consideration margin requirements for shorting stocks?

As attached main.py, I'm trying to short AMC stock (or any hard to borrow stocks).

SetCash(100000), self.CalculateOrderQuantity("AMC", -0.9)

marketOrder successful, with 1662 shares x 55USD = 91410 (90% of portfolio)

 

It backtest succesful. But in reality, the total amount will probably only be 30% of your portfolio (think SetHolding(0.3)) because shorting them requires a Maintenance Margin, in which its requirement could be up to x3 the amount.

In my IBKR paper account, shorting 100 shares of AMC = 5757, Margin required: 5757 * 3 = 17,106

85566_1625120705.jpg

 

And running live trading will encounter this error

Order rejected - reason:YOUR ORDER IS NOT ACCEPTED. IN ORDER TO OBTAIN THE DESIRED POSITION YOUR EQUITY WITH LOAN VALUE [1154077.00 USD] MUST EXCEED THE INITIAL MARGIN [2877799.82 USD]. Origin: [Id=3] IBPlaceOrder: AMC (STK AMC USD Smart NYSE 0 )