If one makes haram money while trading, and without using that money in real life, then one invests it in halal stocks, and withdraws and uses only the money made on the halal stocks, did he commit a sin? What I mean by without using it in real life is one directly puts it into investing without using it to buy things like food or clothes etc…

1- First of all, making haram money it self is haram.
2- He have to give the haram money and the profits made out of it to poor people.