Investing should always be done with cash that we can afford to lose. We should always take care of our immediate expenses and only then should we invest with the rest. If we do so otherwise, our emotions will get in the way. When we invest with cash that we need urgently within the year, we would most probably brood over it and would not be able to sleep well when the stock dips.
Speaking from personal experience, to sleep well at night, always invest with surplus cash!