Example 1:

2 buys (4 and 5 ETH) and 1 sale (8 ETH)

After the 8 ETH were sold, the second purchase pool (CoinTracking ID 4481) will still hold 1 ETH.

Example 2:

Selling 0.53 BTC from a partial used purchase pool and some additional purchase pools

And selling 0.18004 BTC from a partial used purchase pool and a missing purchase pool (warning)

There are 4 different situations and several sub-situations that can occur.

1) Sell > Buy: Look for next buy and calculate against the remaining sell (buy will be closed, sell remains)

2) Sell < Buy: Sell partial from buy. Go to next sale and calculate with remaining buy (sale will be closed, buy remains)

3) Sell = Buy: Both transactions can be offset against each other.

4) No remaining buys available before sell date: Show warning and use 0 USD (or any user FIAT currency) as cost basis