Sometimes, it is possible to buy a ticket at the last minute. The minimum time to make the reservation online is 3 days with the exception of Machu Picchu and Huayna Picchu (3 months before). Do not count on it because in high season the tickets book out fast.