Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Currency support] Map currency from bid request #880

Merged
merged 1 commit into from
Apr 30, 2019

Conversation

benjaminch
Copy link
Contributor

This CL aims to take into account `request.Cur. It's yet another step forward the full currency support CF #280.

Please let me know what you think about this one and whether I forgot anything.

Cheers :)

This CL introduces the mapping of bid request currencies in the currency
conversion workflow.

CF: prebid#280
var conversionRate float64
var err error
for _, bidReqCur := range request.Cur {
if conversionRate, err = conversions.GetRate(bidResponse.Currency, bidReqCur); err == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we worry that the typical case is bidResponse.Currency == bidReqCur, or is the processing to get out the conversion rate 1 light enough that the performance hit isn't worth an extra check at this point to skip GetRate() or the loop entirely?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey !
Well, for sure the processing is more than a plain inline if here, but I think it worth passing via the method rather than inline for following:

  • The method does also check currency iso code existence (bad currencies names would end up being discarded using the rates method where it won't be unless adding more logic inline doing pretty much the same with the same perfs hit)
  • Having the logic / responsibility in one place (also easier to test :))
  • Finally, for the perfs hit, I guess it won't be much is both currencies are the same, costing 2 currencies parsing and string comparison: https://github.com/prebid/prebid-server/blob/master/currencies/rates.go#L50
// GetRate returns the conversion rate between two currencies
// returns an error in case the conversion rate between the two given currencies is not in the currencies rates map
func (r *Rates) GetRate(from string, to string) (float64, error) {
	var err error
	fromUnit, err := currency.ParseISO(from)
	if err != nil {
		return 0, err
	}
	toUnit, err := currency.ParseISO(to)
	if err != nil {
		return 0, err
	}
	if fromUnit.String() == toUnit.String() {
		return 1, nil
	}
	if r.Conversions != nil {
		if conversion, present := r.Conversions[fromUnit.String()][toUnit.String()]; present == true {
			return conversion, err
		}

		return 0, fmt.Errorf("Currency conversion rate not found: '%s' => '%s'", fromUnit.String(), toUnit.String())
	}
	return 0, errors.New("rates are nil")
}

What do you guys think?

Copy link
Contributor

@guscarreon guscarreon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passes test cases, changes are minimal, and defensive. Makes total sense.

@hhhjort hhhjort merged commit b28407f into prebid:master Apr 30, 2019
@benjaminch
Copy link
Contributor Author

Thanks @hhhjort ;)

katsuo5 pushed a commit to flux-dev-team/prebid-server-1 that referenced this pull request Dec 1, 2020
This CL introduces the mapping of bid request currencies in the currency
conversion workflow.

CF: prebid#280
katsuo5 pushed a commit to flux-dev-team/prebid-server-1 that referenced this pull request Dec 2, 2020
This CL introduces the mapping of bid request currencies in the currency
conversion workflow.

CF: prebid#280
katsuo5 pushed a commit to flux-dev-team/prebid-server-1 that referenced this pull request Dec 4, 2020
This CL introduces the mapping of bid request currencies in the currency
conversion workflow.

CF: prebid#280
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants