Hello,
I use Cash (don't want Margin yet)

        stockPicked = self.AddEquity("TQQQ", Resolution.Minute)

        stockPicked.SetDataNormalizationMode(DataNormalizationMode.Adjusted)
        self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Cash)

I like to have a logic to avoid insufficient fund error at all by two ways I can think of.

  1. Handling “insufficient fund error”. If this error occurs, I like to avoid any logic for buying for the date.
  2. Before buying with “SetHoldings” I like to check if there is enough purchasing power in advance. So, I only put order when there is enough purchasing power.

 

Is there a way to do it? If so, could you share the code or link to the code?

Thank you in advance!