currency

package
v0.0.0-...-c5d5a31 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package currency fetches foreign exchange quotes

Index

Constants

This section is empty.

Variables

View Source
var (
	// USD is a Currency
	USD = Currency{"USD", "US Dollar"}
	// AUD is a Currency
	AUD = Currency{"AUD", "Australian Dollar"}
	// BGN is a Currency
	BGN = Currency{"BGN", "Bulgarian Lev"}
	// BRL is a Currency
	BRL = Currency{"BRL", "Brazilian Real"}
	// CAD is a Currency
	CAD = Currency{"CAD", "Canadian Dollar"}
	// CHF is a Currency
	CHF = Currency{"CHF", "Swiss Franc"}
	// CNY is a Currency
	CNY = Currency{"CNY", "Chinese Yuan"}
	// CZK is a Currency
	CZK = Currency{"CZK", "Czech Republic Koruna"}
	// DKK is a Currency
	DKK = Currency{"DKK", "Danish Krone"}
	// EUR is a Currency
	EUR = Currency{"EUR", "Euro"}
	// GBP is a Currency
	GBP = Currency{"GBP", "British Pound Sterling"}
	// HKD is a Currency
	HKD = Currency{"HKD", "Hong Kong Dollar"}
	// HRK is a Currency
	HRK = Currency{"HRK", "Croatian Kuna"}
	// HUF is a Currency
	HUF = Currency{"HUF", "Hungarian Forint"}
	// IDR is a Currency
	IDR = Currency{"IDR", "Indonesian Rupiah"}
	// ILS is a Currency
	ILS = Currency{"ILS", "Israeli New Sheqel"}
	// INR is a Currency
	INR = Currency{"INR", "Indian Rupee"}
	// ISK is a Currency
	ISK = Currency{"ISK", "Iceland Krona"}
	// JPY is a Currency
	JPY = Currency{"JPY", "Japanese Yen"}
	// KRW is a Currency
	KRW = Currency{"KRW", "South Korean Won"}
	// LTL is a Currency
	LTL = Currency{"LTL", "Lithuanian Litas"}
	// MXN is a Currency
	MXN = Currency{"MXN", "Mexican Peso"}
	// MYR is a Currency
	MYR = Currency{"MYR", "Malaysian Ringgit"}
	// NOK is a Currency
	NOK = Currency{"NOK", "Norwegian Krone"}
	// NZD is a Currency
	NZD = Currency{"NZD", "New Zealand Dollar"}
	// PHP is a Currency
	PHP = Currency{"PHP", "Philippine Peso"}
	// PLN is a Currency
	PLN = Currency{"PLN", "Polish Zloty"}
	// RON is a Currency
	RON = Currency{"RON", "Romanian Leu"}
	// RUB is a Currency
	RUB = Currency{"RUB", "Russian Ruble"}
	// SEK is a Currency
	SEK = Currency{"SEK", "Swedish Krona"}
	// SGD is a Currency
	SGD = Currency{"SGD", "Singapore Dollar"}
	// THB is a Currency
	THB = Currency{"THB", "Thai Baht"}
	// TRY is a Currency
	TRY = Currency{"TRY", "Turkish Lira"}
	// ZAR is a Currency
	ZAR = Currency{"ZAR", "South African Rand"}
)

fx currencies

View Source
var (
	BTC  = Currency{"BTC", "Bitcoin"}
	DOGE = Currency{"DOGE", "Dogecoin"}
	ETH  = Currency{"ETH", "Ethereum"}
	LTC  = Currency{"LTC", "Litecoin"}
	XMR  = Currency{"XMR", "Monero"}
	XRP  = Currency{"XRP", "Ripple"}
)

crypto currencies

View Source
var CryptoCompareProvider provider = "CryptoCompare"

CryptoCompareProvider is a currency provider

View Source
var CryptoCurrencies = []Currency{
	BTC,
	DOGE,
	ETH,
	LTC,
	XMR,
	XRP,
}

CryptoCurrencies are valid crypto currencies

View Source
var ECBProvider provider = "European Central Bank"

ECBProvider is a currency provider

View Source
var ErrInvalidCurrency = fmt.Errorf("invalid currency")

ErrInvalidCurrency indicates the currency was invalid

View Source
var ForexCurrencies = []Currency{
	AUD,
	BGN,
	BRL,
	CAD,
	CHF,
	CNY,
	CZK,
	DKK,
	EUR,
	GBP,
	HKD,
	HRK,
	HUF,
	IDR,
	ILS,
	INR,
	ISK,
	JPY,
	KRW,
	LTL,
	MXN,
	MYR,
	NOK,
	NZD,
	PHP,
	PLN,
	RON,
	RUB,
	SEK,
	SGD,
	THB,
	TRY,
	USD,
	ZAR,
}

ForexCurrencies are valid forex currencies

Functions

This section is empty.

Types

type CryptoCompare

type CryptoCompare struct {
	*http.Client
	UserAgent string
}

CryptoCompare holds settings for the CryptoCompare api CryptoCompare allows 8K historical requests/hr (133/minute).

func (*CryptoCompare) Fetch

func (c *CryptoCompare) Fetch() (*Response, error)

Fetch retrieves a cryptocurrency quotes from CryptoCompare

type CryptoCompareResponse

type CryptoCompareResponse struct {
	Response   string `json:"Response"`
	Type       int    `json:"Type"`
	Aggregated bool   `json:"Aggregated"`
	Data       []struct {
		Time       int     `json:"time"`
		High       float64 `json:"high"`
		Low        float64 `json:"low"`
		Open       float64 `json:"open"`
		Volumefrom float64 `json:"volumefrom"`
		Volumeto   float64 `json:"volumeto"`
		Close      float64 `json:"close"`
	} `json:"Data"`
	TimeTo            int  `json:"TimeTo"`
	TimeFrom          int  `json:"TimeFrom"`
	FirstValueInArray bool `json:"FirstValueInArray"`
	ConversionType    struct {
		Type             string `json:"type"`
		ConversionSymbol string `json:"conversionSymbol"`
	} `json:"ConversionType"`
}

CryptoCompareResponse is the raw CryptoCompare response

type CryptoFetcher

type CryptoFetcher interface {
	Fetch() (*Response, error)
}

CryptoFetcher retrieves cryptocurrency quotes

type Currency

type Currency struct {
	Short string
	Long  string
}

Currency is an FX currency

func Valid

func Valid(c string) (bool, Currency)

Valid checks if a given currency is supported

type ECB

type ECB struct{}

ECB holds settings for ECB via openprovider

func (*ECB) Fetch

func (e *ECB) Fetch() (*Response, error)

Fetch retrieves currency quotes from the ECB via openprovider

type FXFetcher

type FXFetcher interface {
	Fetch() (*Response, error)
}

FXFetcher retrieves fx quotes

type Rate

type Rate struct {
	DateTime time.Time
	Rate     float64
}

Rate is an currency quote

type Response

type Response struct {
	Base           Currency // the base currency
	History        map[string][]*Rate
	ForexProvider  provider
	CryptoProvider provider
}

Response is a currency response

func New

func New() *Response

New returns a new Response with the base currency set to USD

func (*Response) Sort

func (r *Response) Sort() *Response

Sort sorts the historical rates by date in Asc order

Jump to

Keyboard shortcuts

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