US stock markets close day with gains