How to ensure portfolio positions are updated daily?

When running my script. I log each position in my portfolio upon selling at market open. If I run my script for multiple days, the positions in the portfolio are not updated and the script tries to sell positions that have previously already been sold the previous day.

Is there any line of code that will ensure the positions are updated appropriately?