Categorygithub.com/robotomize/gokuu
modulepackage
0.1.1
Repository: https://github.com/robotomize/gokuu.git
Documentation: pkg.go.dev

# README

Gokuu

Go Report codebeat badge codecov Build status GitHub license

Gokuu is a library for getting up-to-date exchange rates and converting them on Go. Gokuu is a controller and plug-in data sources that work with a specific financial institution.

Right now, Gokuu can retrieve data from the European central bank, the Russian central bank and the central bank of the United Arab Emirates. Altogether, these sources cover exchange rates for 59 currencies

Installation

go get github.com/robotomize/gokuu

Features

  • Currently supports 59 currency pairs
  • Use your own data sources with provider.Source interface

Usage

If you want to get all current exchange rates, you can use the following GetLatest method. When you match currency pairs from different providers, Gokuu by default saves the data from the provider who gave it faster.

ctx := context.Background()
g := gokuu.New(http.DefaultClient)

latest := g.GetLatest(ctx)
for _, r := range latest.Result {
	fmt.Printf("from: %s, to: %s, rate: %f, date: %v", 
		r.From().Symbol, r.To().Symbol, r.Rate(), r.Time(),
	)
}

With options you can change the strategy for merging data from multiple providers. For example, a merger based on priorities

g := gokuu.New(http.DefaultClient, gokuu.WithPriorityMergeStrategy())

Calculate the arithmetic average of the currency pair from all providers

g := gokuu.New(http.DefaultClient, gokuu.WithAverageMergeStrategy())

You can also use the conversion function

ctx := context.Background()
g := gokuu.New(http.DefaultClient)

conv, err := g.Convert(
	ctx, gokuu.ConvOpt{
		From:  label.USD,
		To:    label.RUB,
		Value: 10,
	},
)
if err != nil {
	log.Fatalln(err)
}
fmt.Println(conv)

Use your caching function for better performance. For example like this

g := gokuu.New(http.DefaultClient, gokuu.WithAverageMergeStrategy())
latest := g.GetLatest(ctx)
conv, err := g.Convert(
	ctx, gokuu.ConvOpt{
		From:  label.USD,
		To:    label.RUB,
		Value: 10,
		CacheFn: func(ctx context.Context) gokuu.LatestResponse {
			return latest
		},
	},
)
if err != nil {
	log.Fatalln(err)
}
fmt.Println(conv)

You can also use the helper functions from the package github.com/robotomize/gokuu/label

label.GetSymbols()
label.GetCountries()
label.GetCurrencies()
label.GetCountriesUsingCurrency("currency-symbol")
label.GetCurrenciesUsedCountry("countryname")

Contributing

welcome

License

SOD is under the Apache 2.0 license. See the LICENSE file for details.

# Packages

Code generated by gocygen.
Package provider is a generated GoMock package.
No description provided by the author

# Functions

New return exchanger.
WithAverageMergeStrategy use the merge strategy to calculate the average Value of exchange rates with a large number of providers.
WithMergeFunc set the custom currency merge function.
WithPriorityMergeStrategy use a strategy of merging by priority.
WithRaceMergeStrategy use the "who's the fastest" merger strategy.
WithRequestTimeout set a timeout for source requests.
WithRetryDuration max retry backoff.
WithRetryNum set number of repeated requests for data retrieval errors from the source.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ProviderNameCAE source name for the UAE central bank.
ProviderNameECB source name for European central bank.
ProviderNameRCB source name for the Russia central bank.
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author