I suggest you avoid that completely for now. That will release oxytocin, which I think can also cause contractions. Can you bear with it for now to protect your baby?
masturbation is completely fine as long as there is no insertion inside the vagina. any kind of insertion inside the vagina is NOT SAFE