That's a very interesting subject, why a broad empire with so many advantages should lose out historically to a rag-bag of smelly, unbathed, crude and predictable Europeans.
The only explanation I've ever encountered was that the Ming Dynasty embodied a value of inward-turning perfection and elaboration of what it was to be Chinese. The state promoted Chinese-ness in everything, and strongly discouraged foreign imports and contacts.
I don't know when they turned to a mercantilistic economic model, under which they imported only cash and bullion, and exported only consumer nondurables like tea, whether that was during the Ming Dynasty or later; but the spirit of the time was, "Everything we Chinese need, we have here in China; anything from somewhere else, we do not need." Well, they needed improving artillery and firelocks.
China had very different attitudes towards these things than Europe or the rest of the world.
China was never much of a trading nation. Their attitude that they didn't need anything from the rest of the world was historically based in reality. While more gold and silver was always nice, they just didn't want much of anything produced by the rest of the world. China itself was so huge and diverse it produced everything they wanted.
Even the Chinese idea of trade was weird. It generally took the form of official "tribute" brought to the Son of Heaven, with "presents" returned to the foreigners by the Emperor in condenscion. A truly unique feature is that the presents were supposed to outweigh the tribute in value, to show the superiority of China, and usually did. Its root purpose was political, not economic.
The Chinese inside China were highly mercantile, and the only rival as middlemen to the overseas Chinese are the Jews, but Chinese import/export has always been strange.