Convex Optimization, Stochastic Approximation, and Optimal Contract Management in Real-time Bidding