SHANGHAI, Aug 17 (Reuters) - China's major state-owned banks were seen busy selling U.S. dollars to buy yuan in both onshore and offshore spot foreign exchange markets this week, people with direct knowledge of the matter said, in an attempt to arrest the yuan's rapid losses.

State banks usually act on behalf of China's central bank in the country's foreign exchange market, but they could also trade on their own behalf or execute their clients' orders.

Offshore branches of the state banks were seen selling dollars during London and New York trading hours this week, two sources with direct knowledge of the matter said on Thursday.

Such dollar selling could limit falls in the offshore yuan and prevent it from diverging too far from its onshore counterpart.

Meanwhile, two separate sources also said state banks offered dollars in onshore foreign exchange markets.

Dollar selling was mainly to "control the pace of yuan depreciation," one of the sources said.

The onshore yuan traded at 7.3096 per dollar as of 0205 GMT, while the offshore yuan last fetched 7.3356. (Reporting by Shanghai Newsroom; Editing by Jacqueline Wong)