The teaching about wrong livelihood for laypeople is found in AN 5.177, as follows:
A lay follower should not engage in five types of business. Which five? Business in weapons, business in human beings, business in meat,
business in intoxicants, and business in poison.
In addition, a warning about "gambling" is found in DN 31:
There are, young householder, these six evil consequences in indulging in gambling: (i) the winner begets hate, (ii) the loser
grieves for lost wealth, (iii) loss of wealth, (iv) his word is not
relied upon in a court of law, (v) he is despised by his friends and
associates, (vi) he is not sought after for matrimony; for people
would say he is a gambler and is not fit to look after a wife.
Also, positive advice about "investing" is also found in DN 31:
With wealth acquired this way, a layman fit for household life, in portions four divides his wealth: thus will he friendship win. One
portion for his wants he uses, two portions on his business spends,
the fourth for times of need he keeps.
Where as the following teaching in MN 117 appears to be for monks:
And what, bhikkhus, is wrong livelihood? Scheming, talking, h inting, belittling, pursuing gain with gain: this is wrong livelihood.
Stock trading does not count as pursuing gain with gain mentioned as wrong view in MN117 because this teaching is for monks and is about when a monk acquires gains by donations and then gives some of those gains for the purpose of gaining a social reputation so he can acquire more gains. Its similar to public philanthropy by billionaires to develop a positive public image and avoid lynch mobs (as J.D. Rockerfeller did, when he was the most hated man in the USA).
As for active stock trading; there is nothing "very destructive" about it; apart from the destruction of wealth referred to in DN 31 for those who stock trade similar to "gambling". Those who get destroyed are the sheep that follow the herd. This said, it is not inherently immoral because such activity is done with others who consent to participate in this speculative activity.
As for passive stock investing in a company one believes will grow into a real and profitable business; this is not wrong livehood because most investors will benefit; such as if you invested in Apple Inc 30 years ago, 10 years ago or even 5 years ago.