I participated in a company in the stock market in my country
All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
First of all, you have to know, dear brother, that if the main purpose of this company is forbidden, like dealing with Ribaa (usury or interest) or producing forbidden goods, or trading in forbidden goods, then it is forbidden to invest in it, without any difference of opinion among the scholars in this issue.
It is also not permissible to invest in this company, if it sometimes deals with Ribaa in some of its transactions, or that it invests some of its money in banks which deal with Ribaa, or lends money with Ribaa. This is the most preponderant opinion in Islamweb. The Islamic Fiqh Committee in his fourteenth conference held in Makkah issued the same ruling; therefore, it is not permissible to invest in the said company or any other company which deals in similar transactions.
It is an obligation to get rid of the profit obtained from it by spending it on the poor or on the general public interests of Muslims. Moreover, it is not permissible for you to use the profit in your own interest like paying off a debt or paying school fees, unless you are a poor person in which case you are only permitted to take your need, and it is not permissible to give this profit to your family unless they are poor.
Allah Knows best.
Fatwa answered by: The Fatwa Center at Islamweb