Canada's main stock index notched a third-straight record close on Tuesday, fueled by a rally in energy shares that offset Shopify Inc's steep decline and broad losses among mining firms.

Oil and gas companies, which account for about 20 per cent of the index's weight, rallied 1.7 per cent as crude prices closed at the highest level in more than two years.

Encana Corp (ECA.TO) rose 4.4 per cent to finish at $15.09, while Crescent Point Energy Corp (CPG.TO) rallied 4.5 per cent to $10.61.

"Year-to-date, energy is the worst performing sector by a long shot," said Manash Goswami, a portfolio manager at First Asset Investment Management Inc. The group has fallen about 12 per cent this year. "People are a little bit more confident with crude prices. It seems the fundamental background for oil is more constructive now."

The Toronto Stock Exchange's S&P/TSX composite index rose 22.81 points, or 0.14 per cent, to a record close of 16,025.59. It touched a fresh intraday high of 16,064.68.

Half of the index's 10 primary sectors rose.

"If energy reverses their first-half of the year performance or claws some of it can see this rally continuing," said Goswami, adding that investors are also seeing a positive growth trend based on quarterly results so far.

The heavily weighted financials group added 0.2 per cent.

Canadian Western Bank (CWB.TO) gained 4.8 per cent to $36.34 following news it is acquiring ECN Capital Corp assets. ECN Capital Corp (ECN.TO) was up 4.8 per cent at $36.34.

Colliers International Group (CIGI.TO) jumped 7.8 per cent to $75.61 after posting strong quarterly growth.

Health care stocks also rallied, climbing 1.7 per cent, with cannabis producer Canopy Growth (WEED.TO) up 6.3 per cent to $16.18, extending the previous session's gains.

Valeant Pharmaceuticals Inc (VRX.TO) was up three per cent to $15.07 after it said it will cut its debt by an additional US$125 million, exceeding its previously stated goal of US$5 billion, and months ahead of schedule.

Consumer discretionaries added 0.5 per cent, with Shaw Communications Inc (SJRb.TO) up 1.7 per cent at $29.46.

On the downside, Shopify Inc (SHOP.TO) slumped 8.5 per cent to $128.26 despite posting strong quarterly results. Investors expressed disappointment it did not do more to address short-seller Citron Research's concerns.

The technology sector lost 1.7 per cent.

The materials group, home to mining companies, lost 0.4 per cent, in tandem with weaker bullion prices.

Eldorado Gold (ELD.TO) fell 6.9 per cent to $1.62, while a number of other miners, including Goldcorp Inc (G.TO) and Barrick Gold (ABX.TO), fell more than 1 per cent.