The portfolio has two types of positions: asset and cash positions. Cash positions are easy. One currency has only one position, so you can add and subtract easily. Asset positions seem to be more difficult. Ideally one asset would have only one position and we would add and subtract quantity from it. However in practice it seems necesary to have multiple positions for the same asset (different purchase price, date) that can exist simultaneously (say for stop limits as part of risk management -- need to know purchase price). Say the strategy decided to sell one asset position. Say in a straightforward scenario the order got fully executed (now the exchange does not know the internal ID of the position), so if we have several positions (of the same size) how do we know which one to close internally? Not talking about situations with partial fill (but I guess same problem). Or do the exchanges actually issue some kind of position ID via a "Confirmation Report" that can then be attached to the position?
Your broker will keep track of this information. Each order creates what is called a tax lot. TD Ameritrade explains it as follows:
Each time you purchase a security, the new position is a distinct and separate tax lot — even if you already owned shares of the same security. (A tax lot is a record of a transaction and its tax implications, including the purchase date and number of shares.)
A tax lot identification method is the way we determine which tax lots are to be sold when you have a position consisting of multiple purchases made on different dates at differing prices, and you enter a trade to sell only part of the position.
When you sell or cover, you are actually doing so on specific tax lots. Generally FIFO is used (so you are operating on the oldest lots), but you can specify specific lots if you want.
Whether you need to care about this is highly dependent on your strategy. This does have tax implications, for example whether your profits are taxed as long-term or short-term capital gains. This information is also needed to calculate things like cost basis and realized/unrealized P&L.