Documentation ¶
Index ¶
- Constants
- Variables
- func ConvertCurrency(amount float64, from, to string) (float64, error)
- func FetchFixerCurrencyData() error
- func FetchYahooCurrencyData(currencyPairs []string) error
- func GetProvider() string
- func IsCryptoFiatPair(p pair.CurrencyPair) bool
- func IsCryptoPair(p pair.CurrencyPair) bool
- func IsCryptocurrency(currency string) bool
- func IsDefaultCryptocurrency(currency string) bool
- func IsDefaultCurrency(currency string) bool
- func IsFiatCurrency(currency string) bool
- func IsFiatPair(p pair.CurrencyPair) bool
- func MakecurrencyPairs(supportedCurrencies string) string
- func QueryYahooCurrencyValues(currencies string) error
- func SeedCurrencyData(fiatCurrencies string) error
- func SetProvider(yahooEnabled bool)
- func SwapProvider()
- func Update(input []string, cryptos bool)
- type FixerResponse
- type Rate
- type YahooJSONResponse
- type YahooJSONResponseInfo
Constants ¶
const ( // DefaultCurrencies has the default minimum of FIAT values DefaultCurrencies = "USD,AUD,EUR,CNY" // DefaultCryptoCurrencies has the default minimum of crytpocurrency values DefaultCryptoCurrencies = "BTC,LTC,ETH,DOGE,DASH,XRP,XMR" )
Variables ¶
var ( CurrencyStore map[string]Rate CurrencyStoreFixer map[string]float64 BaseCurrencies []string CryptoCurrencies []string ErrCurrencyDataNotFetched = errors.New("yahoo currency data has not been fetched yet") ErrCurrencyNotFound = errors.New("unable to find specified currency") ErrQueryingYahoo = errors.New("unable to query Yahoo currency values") ErrQueryingYahooZeroCount = errors.New("yahoo returned zero currency data") YahooEnabled = false )
Variables for package which includes base error strings & exportable queries
Functions ¶
func ConvertCurrency ¶
ConvertCurrency for example converts $1 USD to the equivalent Japanese Yen or vice versa.
func FetchFixerCurrencyData ¶
func FetchFixerCurrencyData() error
FetchFixerCurrencyData seeds the variable C
func FetchYahooCurrencyData ¶
FetchYahooCurrencyData seeds the variable CurrencyStore; this is a map[string]Rate
func GetProvider ¶
func GetProvider() string
GetProvider returns the currency exchange service used by the currency converter
func IsCryptoFiatPair ¶
func IsCryptoFiatPair(p pair.CurrencyPair) bool
IsCryptoFiatPair checks to see if the pair is a crypto fiat pair. For example, BTCUSD
func IsCryptoPair ¶
func IsCryptoPair(p pair.CurrencyPair) bool
IsCryptoPair checks to see if the pair is a crypto pair. For example, BTCLTC
func IsCryptocurrency ¶
IsCryptocurrency checks if the currency passed is an enabled CRYPTO currency.
func IsDefaultCryptocurrency ¶
IsDefaultCryptocurrency checks if the currency passed in matches the default CRYPTO currency
func IsDefaultCurrency ¶
IsDefaultCurrency checks if the currency passed in matches the default FIAT currency
func IsFiatCurrency ¶
IsFiatCurrency checks if the currency passed is an enabled FIAT currency
func IsFiatPair ¶
func IsFiatPair(p pair.CurrencyPair) bool
IsFiatPair checks to see if the pair is a fiar pair. For example. EURUSD
func MakecurrencyPairs ¶
MakecurrencyPairs takes all supported currency and turns them into pairs.
func QueryYahooCurrencyValues ¶
QueryYahooCurrencyValues takes in desired currencies, creates pairs then uses FetchYahooCurrencyData to seed CurrencyStore
func SeedCurrencyData ¶
SeedCurrencyData takes the desired FIAT currency string, if not defined the function will assign it the default values. The function will query yahoo for the currency values and will seed currency data.
func SetProvider ¶
func SetProvider(yahooEnabled bool)
SetProvider sets the currency exchange service used by the currency converter
func SwapProvider ¶
func SwapProvider()
SwapProvider swaps the currency exchange service used by the curency converter
Types ¶
type FixerResponse ¶
type FixerResponse struct { Base string `json:"base"` Date string `json:"date"` Rates map[string]float64 `json:"rates"` }
FixerResponse contains the data fields for the Fixer API response
type Rate ¶
type Rate struct { ID string `json:"id"` Name string `json:"Name"` Rate float64 `json:",string"` Date string `json:"Date"` Time string `json:"Time"` Ask float64 `json:",string"` Bid float64 `json:",string"` }
Rate holds the current exchange rates for the currency pair.
type YahooJSONResponse ¶
type YahooJSONResponse struct { Query struct { YahooJSONResponseInfo Results struct { Rate []Rate `json:"rate"` } } }
YahooJSONResponse holds Yahoo API responses