openexchangerates

package
v0.0.0-...-83dca6d Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: MIT Imports: 11 Imported by: 0

README

GoCryptoTrader package Openexchangerates

Build Status Software License GoDoc Coverage Status Go Report Card

This openexchangerates 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 openexchangerates

How to enable
import (
	"github.com/thrasher-corp/gocryptotrader/currency/forexprovider/base"
	"github.com/thrasher-corp/gocryptotrader/currency/forexprovider/openexchangerates"
)

c := openexchangerates.OXR{}

// Define configuration
newSettings := base.Settings{
	Name:             "openexchangerates",
	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

View Source
const (
	APIDeveloperAccess = iota
	APIEnterpriseAccess
	APIUnlimitedAccess

	APIURL                = "https://openexchangerates.org/api/"
	APIEndpointLatest     = "latest.json"
	APIEndpointHistorical = "historical/%s.json"
	APIEndpointCurrencies = "currencies.json"
	APIEndpointTimeSeries = "time-series.json"
	APIEndpointConvert    = "convert/%s/%s/%s"
	APIEndpointOHLC       = "ohlc.json"
	APIEndpointUsage      = "usage.json"
)

These consts contain endpoint information

Variables

This section is empty.

Functions

This section is empty.

Types

type Convert

type Convert struct {
	Disclaimer string `json:"disclaimer"`
	License    string `json:"license"`
	Request    struct {
		Query  string  `json:"query"`
		Amount float64 `json:"amount"`
		From   string  `json:"from"`
		To     string  `json:"to"`
	} `json:"request"`
	Meta struct {
		Timestamp int64   `json:"timestamp"`
		Rate      float64 `json:"rate"`
	}
	Response    float64 `json:"response"`
	Error       bool    `json:"error"`
	Status      int     `json:"status"`
	Message     string  `json:"message"`
	Description string  `json:"description"`
}

Convert holds historic rate data

type Historical

type Historical struct {
	Disclaimer  string             `json:"disclaimer"`
	License     string             `json:"license"`
	Timestamp   int64              `json:"timestamp"`
	Base        string             `json:"base"`
	Rates       map[string]float64 `json:"rates"`
	Error       bool               `json:"error"`
	Status      int                `json:"status"`
	Message     string             `json:"message"`
	Description string             `json:"description"`
}

Historical holds historic rate data

type Latest

type Latest struct {
	Disclaimer  string             `json:"disclaimer"`
	License     string             `json:"license"`
	Timestamp   int64              `json:"timestamp"`
	Base        string             `json:"base"`
	Rates       map[string]float64 `json:"rates"`
	Error       bool               `json:"error"`
	Status      int                `json:"status"`
	Message     string             `json:"message"`
	Description string             `json:"description"`
}

Latest holds latest rate data

type OHLC

type OHLC struct {
	Disclaimer  string                 `json:"disclaimer"`
	License     string                 `json:"license"`
	StartDate   string                 `json:"start_date"`
	EndDate     string                 `json:"end_date"`
	Base        string                 `json:"base"`
	Rates       map[string]interface{} `json:"rates"`
	Error       bool                   `json:"error"`
	Status      int                    `json:"status"`
	Message     string                 `json:"message"`
	Description string                 `json:"description"`
}

OHLC holds open high low close values

type OXR

type OXR struct {
	base.Base
	Requester *request.Requester
}

OXR is a foreign exchange rate provider at https://openexchangerates.org/ this is the overarching type across this package DOCs : https://docs.openexchangerates.org/docs

func (*OXR) ConvertCurrency

func (o *OXR) ConvertCurrency(amount float64, from, to string) (float64, error)

ConvertCurrency converts any money value from one currency to another at the latest API rates

func (*OXR) GetCurrencies

func (o *OXR) GetCurrencies(showInactive, prettyPrint, showAlternative bool) (map[string]string, error)

GetCurrencies returns a list of all currency symbols available from the Open Exchange Rates API,

func (*OXR) GetHistoricalRates

func (o *OXR) GetHistoricalRates(date, baseCurrency string, symbols []string, prettyPrint, showAlternative bool) (map[string]float64, error)

GetHistoricalRates returns historical exchange rates for any date available from the Open Exchange Rates API.

func (*OXR) GetLatest

func (o *OXR) GetLatest(baseCurrency, symbols string, prettyPrint, showAlternative bool) (map[string]float64, error)

GetLatest returns the latest exchange rates available from the Open Exchange Rates

func (*OXR) GetOHLC

func (o *OXR) GetOHLC(startTime, period, baseCurrency string, symbols []string, prettyPrint bool) (map[string]interface{}, error)

GetOHLC returns historical Open, High Low, Close (OHLC) and Average exchange rates for a given time period, ranging from 1 month to 1 minute, where available.

func (*OXR) GetRates

func (o *OXR) GetRates(baseCurrency, symbols string) (map[string]float64, error)

GetRates is a wrapper function to return rates

func (*OXR) GetSupportedCurrencies

func (o *OXR) GetSupportedCurrencies() ([]string, error)

GetSupportedCurrencies returns a list of supported currencies

func (*OXR) GetTimeSeries

func (o *OXR) GetTimeSeries(baseCurrency, startDate, endDate string, symbols []string, prettyPrint, showAlternative bool) (map[string]interface{}, error)

GetTimeSeries returns historical exchange rates for a given time period, where available.

func (*OXR) GetUsageStats

func (o *OXR) GetUsageStats(prettyPrint bool) (Usage, error)

GetUsageStats returns basic plan information and usage statistics for an Open Exchange Rates App ID

func (*OXR) SendHTTPRequest

func (o *OXR) SendHTTPRequest(endpoint string, values url.Values, result interface{}) error

SendHTTPRequest sends a HTTP request

func (*OXR) Setup

func (o *OXR) Setup(config base.Settings) error

Setup sets values for the OXR object

type TimeSeries

type TimeSeries struct {
	Disclaimer  string                 `json:"disclaimer"`
	License     string                 `json:"license"`
	StartDate   string                 `json:"start_date"`
	EndDate     string                 `json:"end_date"`
	Base        string                 `json:"base"`
	Rates       map[string]interface{} `json:"rates"`
	Error       bool                   `json:"error"`
	Status      int                    `json:"status"`
	Message     string                 `json:"message"`
	Description string                 `json:"description"`
}

TimeSeries holds historic rate data

type Usage

type Usage struct {
	Status int `json:"status"`
	Data   struct {
		AppID  string `json:"app_id"`
		Status string `json:"status"`
		Plan   struct {
			Name            string `json:"name"`
			Quota           string `json:"quota"`
			UpdateFrequency string `json:"update_frequency"`
			Features        struct {
				Base         bool `json:"base"`
				Symbols      bool `json:"symbols"`
				Experimental bool `json:"experimental"`
				Timeseries   bool `json:"time-series"`
				Convert      bool `json:"convert"`
			} `json:"features"`
		} `json:"plaab"`
	} `json:"data"`
	Usages struct {
		Requests          int64 `json:"requests"`
		RequestQuota      int   `json:"requests_quota"`
		RequestsRemaining int   `json:"requests_remaining"`
		DaysElapsed       int   `json:"days_elapsed"`
		DaysRemaining     int   `json:"days_remaining"`
		DailyAverage      int   `json:"daily_average"`
	}
	Error       bool   `json:"error"`
	Message     string `json:"message"`
	Description string `json:"description"`
}

Usage holds usage statistical data

Jump to

Keyboard shortcuts

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