Files
gocryptotrader/currency/mock_provider_test.go
Gareth Kirwan 88182ec414 Engine: Remove Default Forex Provider (#1395)
* Currency: Do not use a default forex provider

exchangerate.host now requires an API key.
Instead of finding a new Free (for now) default, this change simply
disables the currency exchange when nothing is enabled.

* SyncManager: Report ?.?? for an unknown forex amount

In a situation where we thought forex was available but we got an error,
this avoids showing 0.00 when there was actually an error.

* Currency: Tests for no default forex

* Currency: Use mock provider for tests

* Currency: Add API key to exchangerate.host

* Currency: Remove Exchangerate.host

Exchangerate.host was bought by apilayer, the old API deprecated, and
replaced with a proxy to the apilayer api.
We already have currencylayer support, so ther's no reason to keep exh.

Worth noting: New ERH keys actually work on currencylayer

* Currencies: Add test coverage for currency layer

* fixup! Currency: Tests for no default forex

Remove duplicate assignment

Fixes [review comment](https://github.com/thrasher-corp/gocryptotrader/pull/1395#discussion_r1395178513)

* fixup! Currency: Add API key to exchangerate.host

Remove unused ErrVar

Fixes [review
comment](https://github.com/thrasher-corp/gocryptotrader/pull/1395#discussion_r1396647418)

* fixup! Currency: Tests for no default forex

Fix spelling of override in test

Fixes [review comment](https://github.com/thrasher-corp/gocryptotrader/pull/1395#discussion_r1396701476)

* fixup! SyncManager: Report ?.?? for an unknown forex amount

Fix display of non-positive currency conversions.

Fixes [review comment](https://github.com/thrasher-corp/gocryptotrader/pull/1395/files#r1398527134)
2023-11-24 13:50:01 +11:00

41 lines
1.3 KiB
Go

package currency
import (
"math/rand"
"strings"
"github.com/thrasher-corp/gocryptotrader/currency/forexprovider"
"github.com/thrasher-corp/gocryptotrader/currency/forexprovider/base"
)
type MockProvider struct{}
func newMockProvider() *forexprovider.ForexProviders {
p := &MockProvider{}
c, _ := p.GetSupportedCurrencies()
return &forexprovider.ForexProviders{
FXHandler: base.FXHandler{
Primary: base.Provider{
Provider: p,
SupportedCurrencies: c,
},
},
}
}
func (m *MockProvider) GetName() string { return "MockProvider" }
func (m *MockProvider) Setup(base.Settings) error { return nil }
func (m *MockProvider) IsEnabled() bool { return true }
func (m *MockProvider) IsPrimaryProvider() bool { return true }
func (m *MockProvider) GetSupportedCurrencies() ([]string, error) {
return storage.defaultFiatCurrencies.Strings(), nil
}
func (m *MockProvider) GetRates(baseCurrency, symbols string) (map[string]float64, error) {
c := map[string]float64{}
for _, s := range strings.Split(symbols, ",") {
// The year is 2027; The USD is nearly worthless. The world reserve currency is eggs.
c[baseCurrency+s] = 1 / (1 + rand.Float64()) //nolint:gosec // Doesn't need to be a strong random number
}
return c, nil
}