Hello. In order to calculate the number of shares I can buy, I use this formula:

self.equity = self.Portfolio.GetBuyingPower(self.symbol, OrderDirection.Buy)
quantity = math.floor(self.equity / self.Securities[self.symbol].Close)

But when testing on live trading, I keep getting this error:

LiveTradingResultHandler.OrderEvent(): Time: 07/17/2023 19:00:00 OrderID: 9 EventID: 1 Symbol: TSLA Status: Invalid Quantity: 3640 Message: Order Error: ids: [9], Insufficient buying power to complete orders (Value:[1498419.6520]), Reason: Id: 9, Initial Margin: 1498446.2640736949846468781985, Free Margin: 1024936.045111858458839390115514. BrokerId:

This error also occurred during the backtest, but only a few times during the year of trading and the algorithm generally worked fine:

Order Error: ids: [3], Insufficient buying power to complete orders (Value: [106648,96]), Reason: Id: 3, Initial Margin: 106650.72, Free Margin: 105541.48

As I understand it, GetBuyingPower should already be returning the amount to me, given the margin, but it seems that this is not happening. How do I fix this error?

Second:
And the second small question I wanted to know: when I run a live trade, the log.txt file records all the information about it. During the weekend when the exchange is down, most of the entries in the file look like this:

Isolator.ExecuteWithTimeLimit(): Used: 148, Sample: 138, App: 1101, CurrentTimeStepElapsed: 00:00.000. CPU: 5%
InteractiveBrokersBrokerage.HandleError(): RequestId: -1 ErrorCode: 2103 - Market data farm connection is broken:hfarm
InteractiveBrokersBrokerage.StartGatewayRestartTask(): skipped request: restart task already scheduled
InteractiveBrokersBrokerage.HandleError(): RequestId: -1 ErrorCode: 2157 - Sec-def data farm connection is broken:secdefhk
InteractiveBrokersBrokerage.HandleError(): RequestId: -1 ErrorCode: 2105 - HMDS data farm connection is broken:hkhmds
InteractiveBrokersBrokerage.StartGatewayRestartTask(): skipped request: restart task already scheduled

And it's a very long scroll through to find the right information. Is there any way to view the report but without such technical messages?