Changing Short to Long, get 'Insufficient Quantity Available' even after check for no open orders

It is my understanding that one cannot switch from Short to Long or Long to Short positions without first closing the initial position, make sure the order is filled the order the new position otherwise you get the Insufficient Quantity Avaialble Error. To move from Short to Long in Paper Environment. I:

  1. Place a Buy Order
  2. Wait 5 seconds and check for any open orders (check_orders = api.list_orders(status=‘open’))
  3. If check_orders, then don’t place the second Buy order
  4. Else, place the Buy order to enter long position

Sometimes, when the Else statement runs, it still fails with Insufficient Quantity Available
Alpaca Support - Why does my order say "insufficient quantity available"?

Can anyone help me with this why it still happens even though there check_orders returns no value?