This paper proposes a convex programming model to solve the optimal power flow problem (OPF) related to the problems of generation active power dispatch and opportunity costs to meet the reactive power needs in energy markets. The problem is initially represented as a bilevel optimization problem where the upper level considers the minimization of opportunity costs of generating units through a second-order cone programming OPF model, and the lower level is a linear programming model that minimizes the value of active power offered by generators to the market energy. Subsequently, through the concept of strong duality, the problem is transformed into a one-level convex optimization model. Comparisons of the proposed modeling with other level formulations are presented. Results are presented for the IEEE14 and IEEE30 bus systems.