code: def optimize_spot_bid(ctx, instance_type, spot_bid):
      
      spot_history = _get_spot_history(ctx, instance_type)
      if spot_history:
          _check_spot_bid(spot_bid, spot_history)
      zones = ctx.ec2.get_all_zones()
      most_stable_zone = choose_spot_zone(zones, spot_bid, spot_history)
      logger.debug("Placing spot instances in zone %s.", most_stable_zone)
      return most_stable_zone
docs: Check whether the bid is sane and makes an effort to place the instance in a sensible zone.