currency

package
v0.0.0-...-a67d69f Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2018 License: MIT Imports: 8 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 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 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

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 IsFiatPair

func IsFiatPair(p pair.CurrencyPair) bool

IsFiatPair checks to see if the pair is a fiar pair. For example. EURUSD

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

func Update

func Update(input []string, cryptos bool)

Update updates the local crypto currency or base currency store

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