You can close your position at any time. You do not need to wait for a market to resolve. When you sell, the proceeds are added immediately to your cash balance.
As a market gets closer to resolution, prices can change quickly. This can affect the price you receive if you sell before the outcome is known.