The fair market value is essentially the dollar value that the market is willing to pay for a given cryptocurrency at a specific time. We can calculate the fair market value (FMV) at any given timestamp for any given cryptocurrency. We integrate with multiple third party APIs that specialize in calculating the fair market value for different cryptocurrencies. So once the fair market value is determined, the problem is boiled down to basic arithmetic that our algorithm calculates.
You trade one BTC for five XRP on 7-17-2015 14:31
ZenLedger will first look at when that one BTC was bought, or perhaps it was bought through a series of acquisitions of Satoshis. In any case, once the date of the purchase of the one BTC is determined (say 4-19-2012) we can calculate the fair market value in US dollars. Let's say the fair market value at a specific time on 4-19-2012 is $350, and when you made the trade, the fair market value for one BTC was $4,500, so when you are trading one BTC for five XRP, we will first record a gain of ($4,500 - $350) $4,150 and then record $4,500 again as the cost basis for your investment in five XRP on 7-17-2015.
If the fee for trading one BTC for five XRP is one ETH and on 7-17-2015 one ETH is worth $1,600, then we subtract that amount from the $4,150 gains you made trading one BTC for five XRP. Your net gains from this trade will equal the sales proceeds minus the cost basis: $4,500 - (Cost Basis ($350) + Fees ($1600)) = $2,550.
You have also acquired five XRP for $4,500 (because that was their fair market value when you acquired them) and depending on the market and when you sell or trade them you will make another gain or loss depending on their fair market values.