We buy lottery is not correct, we would usually say We play the lottery. Also, in this case we need to say investing in, as follows:
We play the lottery, take part in contests or spend hours setting up a business or investing in the stock market.
The lottery is a game and a competition: we can take part in it, and play it.
The stock market obviously isn't a game: we invest money in the stock market, or buy stocks. Playing the stock market is an idiom meaning investing in the stock market.