currency

package
v0.185.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2021 License: Apache-2.0 Imports: 12 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateCustomRates added in v0.184.0

func ValidateCustomRates(bidReqCurrencyRates *openrtb_ext.ExtRequestCurrency) error

ValidateCustomRates throws a bad input error if any of the 3-digit currency codes found in the bidRequest.ext.prebid.currency field is invalid, malfomed or does not represent any actual currency. No error is thrown if bidRequest.ext.prebid.currency is invalid or empty.

Types

type AggregateConversions added in v0.163.0

type AggregateConversions struct {
	// contains filtered or unexported fields
}

AggregateConversions contains both the request-defined currency rate map found in request.ext.prebid.currency and the currencies conversion rates fetched with the RateConverter object defined in rate_converter.go It implements the Conversions interface.

func NewAggregateConversions added in v0.163.0

func NewAggregateConversions(customRates, pbsRates Conversions) *AggregateConversions

NewAggregateConversions expects both customRates and pbsRates to not be nil

func (*AggregateConversions) GetRate added in v0.163.0

func (re *AggregateConversions) GetRate(from string, to string) (float64, error)

GetRate returns the conversion rate between two currencies prioritizing the customRates currency rate over that of the PBS currency rate service returns an error if both Conversions objects return error.

func (*AggregateConversions) GetRates added in v0.163.0

func (r *AggregateConversions) GetRates() *map[string]map[string]float64

GetRates is not implemented for AggregateConversions . There is no need to call this function for this scenario.

type ConstantRates

type ConstantRates struct{}

ConstantRates doesn't do any currency conversions and accepts only conversions where both currencies (from and to) are the same. If not the same currencies, it returns an error.

func NewConstantRates

func NewConstantRates() *ConstantRates

NewConstantRates creates a new ConstantRates object holding currencies rates

func (*ConstantRates) GetRate

func (r *ConstantRates) GetRate(from string, to string) (float64, error)

GetRate returns 1 if both currencies are the same. If not, it will return an error.

func (*ConstantRates) GetRates

func (r *ConstantRates) GetRates() *map[string]map[string]float64

GetRates returns current rates

type ConversionNotFoundError added in v0.166.0

type ConversionNotFoundError struct {
	FromCur, ToCur string
}

ConversionNotFoundError is thrown by the currency.Conversions GetRate(from string, to string) method when the conversion rate between the two currencies, nor its reciprocal, can be found.

func (ConversionNotFoundError) Error added in v0.166.0

func (err ConversionNotFoundError) Error() string

type Conversions

type Conversions interface {
	GetRate(from string, to string) (float64, error)
	GetRates() *map[string]map[string]float64
}

Conversions allows to get a conversion rate between two currencies. if one of the currency string is not a currency or if there is not conversion between those currencies, then an err is returned and rate is 0.

type ConverterInfo

type ConverterInfo interface {
	Source() string
	LastUpdated() time.Time
	Rates() *map[string]map[string]float64
	AdditionalInfo() interface{}
}

ConverterInfo holds information about converter setup

type RateConverter

type RateConverter struct {
	// contains filtered or unexported fields
}

RateConverter holds the currencies conversion rates dictionary

func NewRateConverter

func NewRateConverter(
	httpClient httpClient,
	syncSourceURL string,
	staleRatesThreshold time.Duration,
) *RateConverter

NewRateConverter returns a new RateConverter

func (*RateConverter) GetInfo

func (rc *RateConverter) GetInfo() ConverterInfo

GetInfo returns setup information about the converter

func (*RateConverter) LastUpdated

func (rc *RateConverter) LastUpdated() time.Time

LastUpdated returns time when currencies rates were updated

func (*RateConverter) Rates

func (rc *RateConverter) Rates() Conversions

Rates returns current conversions rates

func (*RateConverter) Run

func (rc *RateConverter) Run() error

type Rates

type Rates struct {
	Conversions map[string]map[string]float64 `json:"conversions"`
}

Rates holds data as represented on https://cdn.jsdelivr.net/gh/prebid/currency-file@1/latest.json note that `DataAsOfRaw` field is needed when parsing remote JSON as the date format if not standard and requires custom parsing to be properly set as Golang time.Time

func NewRates

func NewRates(conversions map[string]map[string]float64) *Rates

NewRates creates a new Rates object holding currencies rates

func (*Rates) GetRate

func (r *Rates) GetRate(from, to string) (float64, error)

GetRate returns the conversion rate between two currencies or:

  • An error if one of the currency strings is not well-formed
  • An error if any of the currency strings is not a recognized currency code.
  • A ConversionNotFoundError in case the conversion rate between the two given currencies is not in the currencies rates map

func (*Rates) GetRates

func (r *Rates) GetRates() *map[string]map[string]float64

GetRates returns current rates

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL