import math


def get_price_for_trade(prediction, trade):
  """Returns the price of a trade for a prediction."""
  if trade.contract == 'CONTRACT_ONE':
    old_quantity = prediction.contract_one
    old_quantity_other = prediction.contract_two
  else:
    old_quantity = prediction.contract_two
    old_quantity_other = prediction.contract_one
  if trade.direction == 'BUY':
    new_quantity = old_quantity + trade.quantity
  else:
    new_quantity = old_quantity - trade.quantity
  price = (prediction.liquidity * math.log(
      math.pow(math.e, (new_quantity / prediction.liquidity)) +
      math.pow(math.e, (old_quantity_other / prediction.liquidity)))) - (
          prediction.liquidity * math.log(
              math.pow(math.e, (old_quantity / prediction.liquidity)) +
              math.pow(math.e, (old_quantity_other / prediction.liquidity))))
  return price