There's nothing illegal about making any trade.
If your intent behind the trade is tax avoidance, we have clear rules to help avoid that. That's not 'illegal' that's called good tax planning and leveraging the laws allowed.
It would be illegal to hide something you need to report, like...