This work presents a novel day-ahead energy acquisition model for a distribution company (DisCo) in a competitive market based on Pool and financial bilateral contracts. The market structure encompasses wholesale generation companies, distributed generation (DG) units of independent producers, DG units owned by the DisCo, and load curtailment options. Thus, while satisfying its technical constraints, the DisCo purchases active and reactive power according to the offers of DG units, customers, and the wholesale market. The resulting optimal power flow model is implemented with an object-oriented approach, which is solved numerically by making use of a branch and border sequential quadratic programming algorithm. The model is validated in test systems and then applied to a real case study. Results show the general applicability of the proposed model, with potential cost savings for the DisCo. Finally, the analysis of Lagrange multipliers gives valuable information, which can be used to improve the market design and to extend the use of the model to a more general market structure such as a power exchange. Index Terms--Ancillary services, distributed generation, market design, optimal power flow (OPF), quadratic programming.