https://github.com/robotomize/gokuu
Gokuu is a library for getting up-to-date exchange rates and converting them on Go
https://github.com/robotomize/gokuu
convert convertion-rate currency exchange finance go golang
Last synced: about 2 months ago
JSON representation
Gokuu is a library for getting up-to-date exchange rates and converting them on Go
- Host: GitHub
- URL: https://github.com/robotomize/gokuu
- Owner: robotomize
- License: apache-2.0
- Created: 2021-06-22T08:52:15.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-11-24T10:43:30.000Z (over 1 year ago)
- Last Synced: 2025-02-08T14:15:59.663Z (3 months ago)
- Topics: convert, convertion-rate, currency, exchange, finance, go, golang
- Language: Go
- Homepage:
- Size: 106 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Gokuu
[](https://goreportcard.com/report/github.com/robotomize/gokuu)
[](https://codebeat.co/projects/github-com-robotomize-gokuu-main)
[](https://codecov.io/gh/robotomize/gokuu)
[](https://github.com/robotomize/gokuu/actions)
[](https://github.com/robotomize/gokuu/blob/master/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
```bash
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.```go
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
```go
g := gokuu.New(http.DefaultClient, gokuu.WithPriorityMergeStrategy())
```Calculate the arithmetic average of the currency pair from all providers
```go
g := gokuu.New(http.DefaultClient, gokuu.WithAverageMergeStrategy())
```You can also use the conversion function
```go
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
```go
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
```go
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](LICENSE) file for details.