The market gained for the second straight session and closed at a three-week high on July 2 on optimism ahead of the 2019 Union Budget.