Trying to make a live portfolio checker

So I made a bot to close all positions when the PnL% is above or lower than ±3%, Im also know how much share I have outstanding. The problems if I have outstanding orders like sell AAPL at 150$, it says error because it cannot close more than what the minimum I own, If you know how get the outstanding orders It would be life saving!

Here’s my code: