Hello QuantConnect Community!

We have an interesting question from Sergey Kolpakov in the following thread:
Shorting Bubbles At The Top #10630
It was asked whether QuantConnect provides information about short availability. 

The answer is yes. It is a fairly new feature that has arrived with Atreyu integration (they provide the data).

Basically, all we need to do is adding a custom brokerage model that sets the ShortableProvider:

class ShortAvailabilityDataAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetBrokerageModel(InteractiveBrokersBrokerageModelWithShortable())
 
class InteractiveBrokersBrokerageModelWithShortable(InteractiveBrokersBrokerageModel):
    def __init__(self):
        super().__init__()
        self.ShortableProvider = AtreyuShortableProvider(SecurityType.Equity, Market.USA)

If the security is not shortable, QuantConnect/Lean will invalidate the order. 

We can avoid placing orders that will be rejected by using the following methods from QCAlgorithm:

def OnData(self, data):
    # Gets all Symbols that are shortable, as well as the quantity shortable for them.
    # Returns a Dictionary of quantity shortable (long) keyed by Symbol.
    all_shortable_symbols = self.AllShortableSymbols()

    # Gets the quantity shortable for the given asset. Zero if not shortable
    shortable_quantity = self.ShortableQuantity(self.appl)

    # Determines if the Symbol is shortable at the brokerage.
    # Use a given order's quantity to check if it is currently shortable,
    # taking into account current holdings and open orders.
    is_shortable = self.Shortable(self.appl, 1000000)

Please find a working example below: