Strong gains by petroleum-linked shares helped lift US stocks higher on Tuesday despite lingering worries about trade and a Facebook data scandal that hit social media shares.
The Dow Jones Industrial Average finished up 0.5 percent to 24,727.27.
The broad-based S&P 500 gained 0.2 percent to 2,716.94, while the tech-rich Nasdaq Composite Index advanced 0.3 percent to 7,364.30.
US stocks were in positive territory most of the day, a big improvement from Monday, when the market was dragged lower by a pullback in large technology shares in the wake of a Facebook data breach scandal.
Energy shares were among the best performers, with Halliburton winning 1.8 percent, Apache 1.9 percent and Dow member Chevron 0.5 percent. 
Oil prices rose on speculation President Donald Trump could spike the nuclear agreement with Iran that loosened sanctions on the country.
Gains in energy shares helped offset worries about trade disputes in the wake of Trump’s tariffs on imported aluminum and steel. Investors are also girding for an expected Federal Reserve interest rate hike on Wednesday.
Facebook dropped 2.6 percent, adding to Monday’s big decline on word the Federal Trade Commission was investigating the company over reports that a data analysis firm hired by Trump’s presidential campaign had misused the data of some 50 million users.
Twitter, another big social media company, slumped 10.4 percent after Israeli Justice Minister Ayelet Shaked threatened ‘legal action’ against the microblogging network for not doing enough to counter messages that incite violence against Israel.
But within technology, the losses were mostly contained to social media names. 
Amazon gained 2.7 percent, Microsoft climbed 0.3 percent and Netflix won 1.3 percent.
Oracle tumbled 9.4 percent after reporting a six percent rise in quarterly revenues to $9.8 billion. The company’s forecast for cloud services sales growth lagged many analysts’ expectations.