This paper provides a theory of endogenous network formation in over-the-counter markets based on trade competition and inventory risk balancing. A core-periphery network structure arises as an equilibrium outcome. A small number of agents emerge as core dealers to intermediate among a large number of peripheral agents. The equilibrium level of dealer entry (the size of the core) depends on the combined effect of two countervailing forces: (i) network competition among dealers in their pricing of immediacy to peripheral agents, and (ii) the benefits of a concentrated set of dealers for lowering inventory risk through their ability to quickly offset purchases against sales. The size of the dealer core grows with the total number of agents, and reaches a finite limit size in a market with infinitely many agents. The dealer sector also increases as agents become more risk tolerant. Having more dealers competing to provide liquidity lowers the equilibrium bid-ask spread, individual dealer inventory levels and turnover, but increases market-wide dealer inventory cost. From the viewpoint of market efficiency, surprisingly, dealers tend to under-compete in liquid markets, and over-compete in illiquid markets. Regulation policies on dealers are discussed.