currency

package
v0.0.0-...-cf2d4bb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2017 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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 CheckAndAddCurrency

func CheckAndAddCurrency(input []string, check string) []string

CheckAndAddCurrency checks the string you passed with the input string array, if not already added, checks to see if it is part of the default currency list and returns the appended string.

func ContainsBaseCurrency

func ContainsBaseCurrency(baseCurrencies []string, currency string) bool

ContainsBaseCurrency checks the currency against the baseCurrencies and returns a bool

func ContainsBaseCurrencyIndex

func ContainsBaseCurrencyIndex(baseCurrencies []string, currency string) (bool, string)

ContainsBaseCurrencyIndex checks the currency against the baseCurrencies and returns a bool and its corresponding basecurrency.

func ContainsSeparator

func ContainsSeparator(input string) (bool, string)

ContainsSeparator checks to see if the string passed contains "-" or "_" separated strings and returns what the separators were.

func ConvertCurrency

func ConvertCurrency(amount float64, from, to string) (float64, error)

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

func FetchYahooCurrencyData(currencyPairs []string) error

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 IsCryptocurrency

func IsCryptocurrency(currency string) bool

IsCryptocurrency checks if the currency passed is an enabled CRYPTO currency.

func IsDefaultCryptocurrency

func IsDefaultCryptocurrency(currency string) bool

IsDefaultCryptocurrency checks if the currency passed in matches the default CRYPTO currency

func IsDefaultCurrency

func IsDefaultCurrency(currency string) bool

IsDefaultCurrency checks if the currency passed in matches the default FIAT currency

func IsFiatCurrency

func IsFiatCurrency(currency string) bool

IsFiatCurrency checks if the currency passed is an enabled FIAT currency

func MakecurrencyPairs

func MakecurrencyPairs(supportedCurrencies string) string

MakecurrencyPairs takes all supported currency and turns them into pairs.

func QueryYahooCurrencyValues

func QueryYahooCurrencyValues(currencies string) error

QueryYahooCurrencyValues takes in desired currencies, creates pairs then uses FetchYahooCurrencyData to seed CurrencyStore

func SeedCurrencyData

func SeedCurrencyData(fiatCurrencies string) error

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

type YahooJSONResponseInfo

type YahooJSONResponseInfo struct {
	Count   int       `json:"count"`
	Created time.Time `json:"created"`
	Lang    string    `json:"lang"`
}

YahooJSONResponseInfo is a sub type that holds JSON response info

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL