Canada's main stock index ended slightly higher on Wednesday, with gains in energy, industrials and materials groups offsetting losses from financials as the market recovered from a large sell-off the day before.

The Toronto Stock Exchange's S&P/TSX composite followed U.S. stocks in ending slightly up as investors focused on President Donald Trump's struggle to push through a healthcare bill and snapped up stocks after a steep drop the day before.

The Toronto Stock Exchange's S&P/TSX composite index ended up 35.33 points, or 0.23 per cent, at 15,348.46.

"It's just the correlation with the U.S. market," said Marcus Xu, president and director, portfolio manager, of M.Y. Capital Management Corp.

"Yesterday there was some jitter on the financials and the market was down quite a bit, and today I think it's just a little bit of rebound."

The energy group climbed 0.4 per cent, with Suncor Energy Inc (SU.TO) up 0.4 per cent at $40.70, and TransCanada Corp (TRP.TO) up 0.7 per cent at $61.50.

The increase came even as the price of oil, one of Canada's leading exports, slipped to its lowest since late November after data showed record-high U.S. crude inventories rising faster than expected, raising doubts over the viability of OPEC-led output cuts.

U.S. crude prices were down 0.3 per cent to US$48.12 a barrel, while Brent crude lost 0.5 per cent to US$50.72.

The financials group slipped 0.2 per cent. Royal Bank of Canada (RY.TO) fell 0.2 per cent to $95.21, and Toronto Dominion Bank (TD.TO) slipped 0.2 per cent to $64.72.

Industrials rose 0.2 per cent.

The materials group, which includes precious and base metals miners and fertilizer companies, added 0.3 per cent. Barrick Gold Corp (ABX.TO) was down 0.04 per cent to $25.98.

Gold futures rose 0.1 per cent to US$1,247.7 an ounce.

Copper prices advanced 0.6 per cent to US$5,808.25 a tonne.

Investors had been waiting on a federal budget released after the close.

Canada posted a slightly larger surplus in January of $1.24 billion, up from $1.07 billion a year ago as revenues increased in most areas, including corporate income tax, the Finance Department said on Wednesday.

LAGGING SECTORS THIS YEAR 

Health care (-12.9%)

Energy (-8.3%)

Consumer Staples (-0.48%)

LAGGING STOCKS THIS YEAR 

Crew Energy (-40.5%)

Baytex Energy (-34.5%)

MEG Energy (-34.3%)

(all percentage changes as of 9:40 a,m. ET Wednesday)