-
Notifications
You must be signed in to change notification settings - Fork 753
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
Conversation
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this 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.
Thanks @hhhjort ;) |
This CL introduces the mapping of bid request currencies in the currency conversion workflow. CF: prebid#280
This CL introduces the mapping of bid request currencies in the currency conversion workflow. CF: prebid#280
This CL introduces the mapping of bid request currencies in the currency conversion workflow. CF: prebid#280
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 :)