In the market conditions generating companies put more attention to the question of energy and reserve distribution or purchasing. Each generating company tries to reduce its costs of energy production for increasing its profit from participation in the market. Thus, the question of energy and reserve distribution between generating stations and purchased amount is one of the key aspects of generating company behavior. In article the algorithm of generating company costs minimization, considering spot market and bilateral trading, is proposed. As criteria of optimization task cost minimization function is used. As variables in the model are used: energy, reserve, participation of the power plant in the market (both for reserve providing and for energy production). The algorithm operability was approved on example.