Skip to content

Commit

Permalink
Currency: Add new forex provider exchangerate.host (thrasher-corp#682)
Browse files Browse the repository at this point in the history
* Add new forex provider ExchangeRateHost.io

* Fix linter paramTypeComine

* Add templates and README files

* Convert all times to UTC

* Fix cosmetic issue and address nits

* Add support for fx exchangerate.host engine override

* Address nit plus use remove plural
  • Loading branch information
thrasher- authored May 5, 2021
1 parent 5d44599 commit 6ff453c
Show file tree
Hide file tree
Showing 20 changed files with 958 additions and 107 deletions.
1 change: 1 addition & 0 deletions cmd/documentation/currency_templates/fx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
+ Currency Layer support
+ Fixer.io support
+ Open Exchange Rates support
+ ExchangeRate.host support

### Please click GoDocs chevron above to view current GoDoc information for this package
{{template "contributions"}}
Expand Down
35 changes: 35 additions & 0 deletions cmd/documentation/currency_templates/fx_exchangeratehost.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{{define "currency forexprovider exchangerate.host" -}}
{{template "header" .}}
## Current Features for {{.Name}}

+ Fetches up to date curency data from [ExchangeRate.host API]("https://exchangerate.host")

### How to enable

+ [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-currency-via-config-example)

+ Individual package example below:
```go
import (
"github.com/thrasher-corp/gocryptotrader/currency/forexprovider/base"
"github.com/thrasher-corp/gocryptotrader/currency/forexprovider/exchangerate.host"
)

var c exchangeratehost.ExchangeRateHost

// Define configuration
newSettings := base.Settings{
Name: "ExchangeRateHost",
// ...
}

c.Setup(newSettings)

rates, err := c.GetRates("USD", "EUR,AUD")
// Handle error
```

### Please click GoDocs chevron above to view current GoDoc information for this package
{{template "contributions"}}
{{template "donations" .}}
{{- end}}
8 changes: 5 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1086,11 +1086,12 @@ func (c *Config) CheckCurrencyConfigValues() error {
count := 0
for i := range c.Currency.ForexProviders {
if c.Currency.ForexProviders[i].Enabled {
if c.Currency.ForexProviders[i].Name == "CurrencyConverter" &&
if (c.Currency.ForexProviders[i].Name == "CurrencyConverter" || c.Currency.ForexProviders[i].Name == "ExchangeRates") &&
c.Currency.ForexProviders[i].PrimaryProvider &&
(c.Currency.ForexProviders[i].APIKey == "" ||
c.Currency.ForexProviders[i].APIKey == DefaultUnsetAPIKey) {
log.Warnln(log.Global, "CurrencyConverter forex provider no longer supports unset API key requests. Switching to ExchangeRates FX provider..")
log.Warnf(log.Global, "%s forex provider no longer supports unset API key requests. Switching to %s FX provider..",
c.Currency.ForexProviders[i].Name, DefaultForexProviderExchangeRatesAPI)
c.Currency.ForexProviders[i].Enabled = false
c.Currency.ForexProviders[i].PrimaryProvider = false
c.Currency.ForexProviders[i].APIKey = DefaultUnsetAPIKey
Expand Down Expand Up @@ -1118,7 +1119,8 @@ func (c *Config) CheckCurrencyConfigValues() error {
if c.Currency.ForexProviders[x].Name == DefaultForexProviderExchangeRatesAPI {
c.Currency.ForexProviders[x].Enabled = true
c.Currency.ForexProviders[x].PrimaryProvider = true
log.Warnln(log.ConfigMgr, "Using ExchangeRatesAPI for default forex provider.")
log.Warnf(log.ConfigMgr, "No valid forex providers configured. Defaulting to %s.",
DefaultForexProviderExchangeRatesAPI)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ func TestGetForexProviders(t *testing.T) {
t.Error(err)
}

if r := cfg.GetForexProviders(); len(r) != 5 {
if r := cfg.GetForexProviders(); len(r) != 6 {
t.Error("unexpected length of forex providers")
}
}
Expand Down
2 changes: 1 addition & 1 deletion config/config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const (
DefaultUnsetAPIKey = "Key"
DefaultUnsetAPISecret = "Secret"
DefaultUnsetAccountPlan = "accountPlan"
DefaultForexProviderExchangeRatesAPI = "ExchangeRates"
DefaultForexProviderExchangeRatesAPI = "ExchangeRateHost"
)

// Variables here are used for configuration
Expand Down
2 changes: 1 addition & 1 deletion currency/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func TestGetRate(t *testing.T) {

c, err := NewConversion(from, to)
if err != nil {
t.Error(err)
t.Fatal(err)
}
rate, err := c.GetRate()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions currency/currency_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type BotOverrides struct {
FxCurrencyLayer bool
FxFixer bool
FxOpenExchangeRates bool
FxExchangeRateHost bool
}

// CoinmarketcapSettings refers to settings
Expand Down
1 change: 1 addition & 0 deletions currency/forexprovider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader
+ Currency Layer support
+ Fixer.io support
+ Open Exchange Rates support
+ ExchangeRate.host support

### Please click GoDocs chevron above to view current GoDoc information for this package

Expand Down
69 changes: 69 additions & 0 deletions currency/forexprovider/exchangerate.host/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# GoCryptoTrader package Exchangerate.Host

<img src="https://github.com/thrasher-corp/gocryptotrader/blob/master/web/src/assets/page-logo.png?raw=true" width="350px" height="350px" hspace="70">


[![Build Status](https://travis-ci.org/thrasher-corp/gocryptotrader.svg?branch=master)](https://travis-ci.org/thrasher-corp/gocryptotrader)
[![Software License](https://img.shields.io/badge/License-MIT-orange.svg?style=flat-square)](https://github.com/thrasher-corp/gocryptotrader/blob/master/LICENSE)
[![GoDoc](https://godoc.org/github.com/thrasher-corp/gocryptotrader?status.svg)](https://godoc.org/github.com/thrasher-corp/gocryptotrader/currency/forexprovider/exchangerate.host)
[![Coverage Status](http://codecov.io/github/thrasher-corp/gocryptotrader/coverage.svg?branch=master)](http://codecov.io/github/thrasher-corp/gocryptotrader?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/thrasher-corp/gocryptotrader)](https://goreportcard.com/report/github.com/thrasher-corp/gocryptotrader)


This exchangerate.host package is part of the GoCryptoTrader codebase.

## This is still in active development

You can track ideas, planned features and what's in progress on this Trello board: [https://trello.com/b/ZAhMhpOy/gocryptotrader](https://trello.com/b/ZAhMhpOy/gocryptotrader).

Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader Slack](https://join.slack.com/t/gocryptotrader/shared_invite/enQtNTQ5NDAxMjA2Mjc5LTc5ZDE1ZTNiOGM3ZGMyMmY1NTAxYWZhODE0MWM5N2JlZDk1NDU0YTViYzk4NTk3OTRiMDQzNGQ1YTc4YmRlMTk)

## Current Features for exchangerate.host

+ Fetches up to date curency data from [ExchangeRate.host API]("https://exchangerate.host")

### How to enable

+ [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-currency-via-config-example)

+ Individual package example below:
```go
import (
"github.com/thrasher-corp/gocryptotrader/currency/forexprovider/base"
"github.com/thrasher-corp/gocryptotrader/currency/forexprovider/exchangerate.host"
)

var c exchangeratehost.ExchangeRateHost

// Define configuration
newSettings := base.Settings{
Name: "ExchangeRateHost",
// ...
}

c.Setup(newSettings)

rates, err := c.GetRates("USD", "EUR,AUD")
// Handle error
```

### Please click GoDocs chevron above to view current GoDoc information for this package

## Contribution

Please feel free to submit any pull requests or suggest any desired features to be added.

When submitting a PR, please abide by our coding guidelines:

+ Code must adhere to the official Go [formatting](https://golang.org/doc/effective_go.html#formatting) guidelines (i.e. uses [gofmt](https://golang.org/cmd/gofmt/)).
+ Code must be documented adhering to the official Go [commentary](https://golang.org/doc/effective_go.html#commentary) guidelines.
+ Code must adhere to our [coding style](https://github.com/thrasher-corp/gocryptotrader/blob/master/doc/coding_style.md).
+ Pull requests need to be based on and opened against the `master` branch.

## Donations

<img src="https://github.com/thrasher-corp/gocryptotrader/blob/master/web/src/assets/donate.png?raw=true" hspace="70">

If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:

***bc1qk0jareu4jytc0cfrhr5wgshsq8282awpavfahc***
Loading

0 comments on commit 6ff453c

Please sign in to comment.