It's the same as stocks. Let's walk through an example.
You have 1 share of Stock A and I have 1 share of Stock B. We both paid 1 USD for each of our different stocks.
Now I want Stock A and you want Stock B, so we'll trade with each other, and lucky us, both stocks are now valued at 2 USD per share.
After performing this trade, ask yourself these questions (from my perspective, or swap A and B for yours, it's the same either way):
* Have I held Stock B?
* What did I pay for Stock B?
* Do I now hold Stock B?
* Why not?
* What did I sell it for?
* And how much was that valued?
* So then how much did I gain?
* How much is owed in tax?
Unless your local tax law specifies "cashing out" not only as a taxable event, but the only taxable event, which I assure you it does not for stocks, the correct answers are as below. The equivalent to what you seem to describe for crypto would be transferring money in and out of the exchange where you trade stocks, and it would be ludicrous if this was the taxable event, which it isn't - but this is a common misconception among amateur crypto traders.
* I did hold 1 Stock B.
* I paid 1 USD for it.
* I don't hold it anymore.
* My dog did not eat it, so I must have sold it, which I did.
* I sold it for 1 Stock A and it was valued at 2 USD at the time of the transaction.
* 1 USD of value was gained at the time I sold from the time I bought.
* I owe a percentage of the 1 USD of value gained, depending on the capital gains tax rate, which differs.
I'd ask the local tax office anonymously. Not knowing doesn't fly as an excuse, everyone says that and it doesn't matter if it's true. Where is this place, if you don't mind?
Bonus question, what if we trade 1 DOGE for 1 Stock C? Is that different? What about 1 DOGE for 1 USD? What about 1 DOGE for 1 token backed by 1 USD? What about 1 Stock C for 1 token backed by 1 USD? Somehow it seems to get more complicated with "cashing out" laws, not less. Also I don't believe they exist, but I'd like to know too if they do anywhere.