We propose a model where both security design and market structure are endogenously determined to explain why standardized securities are frequently traded in decentralized markets. We find that issuers offer debt contracts in thinner markets where investors have a higher price impact, and equity in deeper markets. In turn, investors accept to trade in thinner markets to elicit less variable securities from issuers if gains from trade are small. Otherwise, investors choose to trade in deeper markets where their price impact is minimized. We also show that there exist equilibrium market structures in which both debt and equity are traded.