Shanghai nonferrous metals closed mostly with gains when the market sentiment improved as the China foreign trade data in July and the first seven months was better than expected, while the unexpectedly robust US job report has indicated stronger economy.