github.com/prebid/prebid-server/v2@v2.18.0/currency/currency.go (about)

     1  package currency
     2  
     3  import (
     4  	"github.com/prebid/prebid-server/v2/openrtb_ext"
     5  )
     6  
     7  func GetAuctionCurrencyRates(currencyConverter *RateConverter, requestRates *openrtb_ext.ExtRequestCurrency) Conversions {
     8  	if currencyConverter == nil && requestRates == nil {
     9  		return nil
    10  	}
    11  
    12  	if requestRates == nil {
    13  		// No bidRequest.ext.currency field was found, use PBS rates as usual
    14  		return currencyConverter.Rates()
    15  	}
    16  
    17  	// currencyConverter will never be nil, refer main.serve(), adding this check for future usecases
    18  	if currencyConverter == nil {
    19  		return NewRates(requestRates.ConversionRates)
    20  	}
    21  
    22  	// If bidRequest.ext.currency.usepbsrates is nil, we understand its value as true. It will be false
    23  	// only if it's explicitly set to false
    24  	usePbsRates := requestRates.UsePBSRates == nil || *requestRates.UsePBSRates
    25  
    26  	if !usePbsRates {
    27  		// At this point, we can safely assume the ConversionRates map is not empty because
    28  		// validateCustomRates(bidReqCurrencyRates *openrtb_ext.ExtRequestCurrency) would have
    29  		// thrown an error under such conditions.
    30  		return NewRates(requestRates.ConversionRates)
    31  	}
    32  
    33  	// Both PBS and custom rates can be used, check if ConversionRates is not empty
    34  	if len(requestRates.ConversionRates) == 0 {
    35  		// Custom rates map is empty, use PBS rates only
    36  		return currencyConverter.Rates()
    37  	}
    38  
    39  	// Return an AggregateConversions object that includes both custom and PBS currency rates but will
    40  	// prioritize custom rates over PBS rates whenever a currency rate is found in both
    41  	return NewAggregateConversions(NewRates(requestRates.ConversionRates), currencyConverter.Rates())
    42  }