We develop a general model of matching in trading networks with heterogeneity and market imperfections. Our model allows for complementarities between inputs, distortionary frictions, externalities of both quantities and prices, technological constraints, and wealth effects. We provide sufficient conditions for the existence of competitive equilibria. When sales are substitutable, we show that nonlinear-pricing competitive equilibria coincide with outcomes that satisfy a cooperative solution concept that we call sequential stability.