If it were illegal nobody would be capable of trading stocks since there would be no market to trade on.