TORONTO — Canadian and U.S. stock markets gained on Wednesday as hopes continued to build for an end to the war in the Middle East.