exchangerates

package
v1.0.16 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: MIT Imports: 12 Imported by: 0

README

GoCryptoTrader package Exchangeratesapi.io

Build Status Software License GoDoc Coverage Status Go Report Card

This exchangeratesapi.io package is part of the GoCryptoTrader codebase.

This is still in active development

You can track ideas, planned features and what's in progress on this Trello board: https://trello.com/b/ZAhMhpOy/gocryptotrader.

Join our slack to discuss all things related to GoCryptoTrader! GoCryptoTrader Slack

Current Features for exchangeratesapi.io

  • Fetches up to date currency data from Exchange rates API
How to enable
import (
	"github.com/aaabigfish/gocryptotrader/currency/forexprovider/base"
	"github.com/aaabigfish/gocryptotrader/currency/forexprovider/exchangerates"
)

c := exchangerates.ExchangeRates{}

// Define configuration
newSettings := base.Settings{
	Name:             "ExchangeRates",
	Enabled:          true,
	Verbose:          false,
	RESTPollingDelay: time.Duration,
	APIKey:           "key",
	APIKeyLvl:        "keylvl",
	PrimaryProvider:  true,
}

c.Setup(newSettings)

mapstringfloat, err := c.GetRates("USD", "EUR,CHY")
// Handle error
Please click GoDocs chevron above to view current GoDoc information for this package

Contribution

Please feel free to submit any pull requests or suggest any desired features to be added.

When submitting a PR, please abide by our coding guidelines:

  • Code must adhere to the official Go formatting guidelines (i.e. uses gofmt).
  • Code must be documented adhering to the official Go commentary guidelines.
  • Code must adhere to our coding style.
  • Pull requests need to be based on and opened against the master branch.

Donations

If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:

bc1qk0jareu4jytc0cfrhr5wgshsq8282awpavfahc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConvertCurrency

type ConvertCurrency struct {
	Query struct {
		From   string  `json:"from"`
		To     string  `json:"to"`
		Amount float64 `json:"amount"`
	} `json:"query"`
	Info struct {
		Timestamp int64   `json:"timestamp"`
		Rate      float64 `json:"rate"`
	} `json:"info"`
	Historical bool    `json:"historical"`
	Result     float64 `json:"result"`
}

ConvertCurrency stores the converted currency info

type ExchangeRates

type ExchangeRates struct {
	base.Base

	Requester *request.Requester
	// contains filtered or unexported fields
}

ExchangeRates stores the struct for the ExchangeRatesAPI API

func (*ExchangeRates) ConvertCurrency

func (e *ExchangeRates) ConvertCurrency(from, to string, amount float64, date time.Time) (*ConvertCurrency, error)

ConvertCurrency converts a currency based on the supplied params

func (*ExchangeRates) GetFluctuations

func (e *ExchangeRates) GetFluctuations(startDate, endDate time.Time, baseCurrency, symbols string) (*Fluctuations, error)

GetFluctuations returns rate fluctuations based on the supplied params

func (*ExchangeRates) GetHistoricalRates

func (e *ExchangeRates) GetHistoricalRates(date time.Time, baseCurrency string, symbols []string) (*HistoricalRates, error)

GetHistoricalRates returns historical exchange rate data for all available or a specific set of currencies. date - YYYY-MM-DD [required] A date in the past baseCurrency - USD [optional] The base currency to use for forex rates, defaults to EUR symbols - AUD,USD [optional] The symbols to query the forex rates for, default is all supported currencies

func (*ExchangeRates) GetLatestRates

func (e *ExchangeRates) GetLatestRates(baseCurrency, symbols string) (*Rates, error)

GetLatestRates returns a map of forex rates based on the supplied params baseCurrency - USD [optional] The base currency to use for forex rates, defaults to EUR symbols - AUD,USD [optional] The symbols to query the forex rates for, default is all supported currencies

func (*ExchangeRates) GetRates

func (e *ExchangeRates) GetRates(baseCurrency, symbols string) (map[string]float64, error)

GetRates is a wrapper function to return forex rates

func (*ExchangeRates) GetSupportedCurrencies

func (e *ExchangeRates) GetSupportedCurrencies() ([]string, error)

GetSupportedCurrencies returns the supported currency list

func (*ExchangeRates) GetSymbols

func (e *ExchangeRates) GetSymbols() (map[string]string, error)

GetSymbols returns a list of supported symbols

func (*ExchangeRates) GetTimeSeriesRates

func (e *ExchangeRates) GetTimeSeriesRates(startDate, endDate time.Time, baseCurrency string, symbols []string) (*TimeSeriesRates, error)

GetTimeSeriesRates returns daily historical exchange rate data between two specified dates for all available or a specific set of currencies. startDate - YYYY-MM-DD [required] A date in the past endDate - YYYY-MM-DD [required] A date in the past but greater than the startDate baseCurrency - USD [optional] The base currency to use for forex rates, defaults to EUR symbols - AUD,USD [optional] The symbols to query the forex rates for, default is all supported currencies

func (*ExchangeRates) SendHTTPRequest

func (e *ExchangeRates) SendHTTPRequest(endPoint string, values url.Values, result interface{}) error

SendHTTPRequest sends a HTTPS request to the desired endpoint and returns the result

func (*ExchangeRates) Setup

func (e *ExchangeRates) Setup(config base.Settings) error

Setup sets appropriate values for CurrencyLayer

type Fluctuations

type Fluctuations struct {
	Fluctuation bool                       `json:"fluctuation"`
	StartDate   string                     `json:"start_date"`
	EndDate     string                     `json:"end_date"`
	Base        string                     `json:"base"`
	Rates       map[string]FlucutationItem `json:"rates"`
}

Fluctuations stores a collection of rate fluctuations

type FlucutationItem

type FlucutationItem struct {
	StartRate        float64 `json:"start_rate"`
	EndRate          float64 `json:"end_rate"`
	Change           float64 `json:"change"`
	ChangePercentage float64 `json:"change_pct"`
}

FlucutationItem stores an individual rate fluctuation

type HistoricalRates

type HistoricalRates struct {
	Historical bool `json:"historical"`
	Rates
}

HistoricalRates stores the historical rate info

type Rates

type Rates struct {
	Base      string             `json:"base"`
	Timestamp int64              `json:"timestamp"`
	Date      string             `json:"date"`
	Rates     map[string]float64 `json:"rates"`
}

Rates holds the latest forex rates info

type TimeSeriesRates

type TimeSeriesRates struct {
	Timeseries bool                          `json:"timeseries"`
	StartDate  string                        `json:"start_date"`
	EndDate    string                        `json:"end_date"`
	Base       string                        `json:"base"`
	Rates      map[string]map[string]float64 `json:"rates"`
}

TimeSeriesRates stores time series rate info

Jump to

Keyboard shortcuts

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