We study problems arising in real-time auction markets, common in e-commerce and computational advertising, where bidders face the problem of calculating optimal bids. We focus upon a contract management problem where a demand aggregator is subject to multiple contractual obligations requiring them to acquire items of heterogeneous types at a specified rate and where they will seek to fulfill these obligations at minimum cost. Our main results show that, through a transformation of variables, this problem can be formulated as a convex optimization problem, for both first and second price auctions. The resulting duality theory admits rich structure and interpretations. Additionally, we show that the transformation of variables can be used to guarantee the convexity of optimal bidding problems studied by other authors, who did not leverage convexity in their analysis. The main point of our work is to emphasize that the natural convexity properties arising in first and second price auctions are not being fully exploited. Finally, we show direct analogies to problems in financial markets: the expected cost of bidding in second price auctions is formally identical to certain transaction costs when submitting market orders, and that a related conjugate function arises in dark pool financial markets.