Modeling Markets from First Principles