Skip to content

Commit

Permalink
Merge branch 'main' of github.com:robotomize/gokuu
Browse files Browse the repository at this point in the history
  • Loading branch information
robotomize committed Oct 17, 2021
2 parents b152601 + 96dd2fc commit 8a47b13
Showing 1 changed file with 69 additions and 46 deletions.
115 changes: 69 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,69 +1,92 @@
# Gokuu
Library for getting the latest exchange rates
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.

# Installation
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
## Features
* Currently supports 59 currency pairs
* Use your own data sources with provider.Source interface

# Usage
## Usage

Get actual exchange rates
```go
package main
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.

import (
"context"
"fmt"
"log"
"net/http"
```go
ctx := context.Background()
g := gokuu.New(http.DefaultClient)

"github.com/robotomize/gokuu"
"github.com/robotomize/gokuu/label"
)
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(),
)
}
```

func main() {
ctx := context.Background()
g := gokuu.New(http.DefaultClient)
With options you can change the strategy for merging data from multiple providers. For example, a merger based on priorities

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())
}
}
```go
g := gokuu.New(http.DefaultClient, gokuu.WithPriorityMergeStrategy())
```

Conversion from one currency to another
Calculate the arithmetic average of the currency pair from all providers

```go
package main
g := gokuu.New(http.DefaultClient, gokuu.WithAverageMergeStrategy())
```

import (
"context"
"fmt"
"log"
"net/http"
You can also use the conversion function
```go
ctx := context.Background()
g := gokuu.New(http.DefaultClient)

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

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

conv, err := g.Convert(
ctx, gokuu.ConvOpt{
From: label.USD,
To: label.RUB,
Value: 10,
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)
},
)
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")
```

## License

SOD is under the Apache 2.0 license. See the [LICENSE](LICENSE) file for details.

0 comments on commit 8a47b13

Please sign in to comment.