From 0cd20804e98256d672e77e7262138f8b18638494 Mon Sep 17 00:00:00 2001 From: Adrian Gallagher Date: Sat, 10 Feb 2018 19:13:06 +1100 Subject: [PATCH] Add IsFiatPair function --- currency/currency.go | 5 +++++ currency/currency_test.go | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/currency/currency.go b/currency/currency.go index 21a3c5e8..747e2154 100644 --- a/currency/currency.go +++ b/currency/currency.go @@ -146,6 +146,11 @@ func IsCryptoFiatPair(p pair.CurrencyPair) bool { !IsCryptocurrency(p.FirstCurrency.String()) && IsCryptocurrency(p.SecondCurrency.String()) } +// IsFiatPair checks to see if the pair is a fiar pair. For example. EURUSD +func IsFiatPair(p pair.CurrencyPair) bool { + return IsFiatCurrency(p.FirstCurrency.String()) && IsFiatCurrency(p.SecondCurrency.String()) +} + // Update updates the local crypto currency or base currency store func Update(input []string, cryptos bool) { for x := range input { diff --git a/currency/currency_test.go b/currency/currency_test.go index 119bb776..a4202360 100644 --- a/currency/currency_test.go +++ b/currency/currency_test.go @@ -199,6 +199,28 @@ func TestIsCryptoFiatPair(t *testing.T) { } } +func TestIsFiatPair(t *testing.T) { + CryptoCurrencies = []string{"BTC", "LTC", "DASH"} + BaseCurrencies = []string{"USD", "AUD", "EUR"} + + if !IsFiatPair(pair.NewCurrencyPair("AUD", "USD")) { + t.Error("Test Failed. TestIsFiatPair. Expected true result") + } + + if IsFiatPair(pair.NewCurrencyPair("BTC", "AUD")) { + t.Error("Test Failed. TestIsFiatPair. Expected false result") + } +} + +func TestIsRelatablePairs(t *testing.T) { + CryptoCurrencies = []string{"BTC", "XBT", "LTC", "DASH"} + BaseCurrencies = []string{"USD", "AUD", "EUR"} + + if !IsRelatablePairs(pair.NewCurrencyPair("XBT", "USD"), pair.NewCurrencyPair("BTC", "USD")) { + t.Error("Test Failed. TestIsFiatPair. Expected true result") + } +} + func TestUpdate(t *testing.T) { CryptoCurrencies = []string{"BTC", "LTC", "DASH"} BaseCurrencies = []string{"USD", "AUD"}