We study a model of over-the-counter trading in which ex-ante identical traders invest in a contact technology and participate in bilateral trade. We show that a rich market structure emerges both in equilibrium and in an optimal allocation. There is continuous heterogeneity in market access under weak regularity conditions. If the cost per contact is constant, heterogeneity is governed by a power law and there are middlemen, market participants with unboundedly high contact rates who account for a positive fraction of meetings. Externalities lead to overinvestment in equilibrium, and policies that reduce investment in the contact technology can improve welfare. We relate our findings to important features of real-world trading networks.