currencylayer

package
Version: v0.0.0-...-6a9f9bf Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: MIT Imports: 10 Imported by: 0

README

GoCryptoTrader package Forexprovider

Build Status Software License GoDoc Coverage Status Go Report Card

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

How to enable
import (
	"github.com/yurulab/gocryptotrader/currency/forexprovider/base"
	"github.com/yurulab/gocryptotrader/currency/forexprovider/currencylayer"
)

c := currencylayer.CurrencyLayer{}

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

Overview

Package currencylayer provides a simple REST API with real-time and historical exchange rates for 168 world currencies, delivering currency pairs in universally usable JSON format - compatible with any of your applications. Spot exchange rate data is retrieved from several major forex data providers in real-time, validated, processed and delivered hourly, every 10 minutes, or even within the 60-second market window. Providing the most representative forex market value available ("midpoint" value) for every API request, the currencylayer API powers currency converters, mobile applications, financial software components and back-office systems all around the world. https://currencylayer.com/product for product information https://currencylayer.com/documentation for API documentation and supported functionality

Index

Constants

View Source
const (
	AccountFree = iota
	AccountBasic
	AccountPro
	AccountEnterprise

	APIEndpointURL        = "http://apilayer.net/api/"
	APIEndpointURLSSL     = "https://apilayer.net/api/"
	APIEndpointList       = "list"
	APIEndpointLive       = "live"
	APIEndpointHistorical = "historical"
	APIEndpointConversion = "convert"
	APIEndpointTimeframe  = "timeframe"
	APIEndpointChange     = "change"
)

const declarations consist of endpoints and APIKey privileges

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangeRate

type ChangeRate struct {
	Success   bool               `json:"success"`
	Error     Error              `json:"error"`
	Terms     string             `json:"terms"`
	Privacy   string             `json:"privacy"`
	Change    bool               `json:"change"`
	StartDate string             `json:"start_date"`
	EndDate   string             `json:"end_date"`
	Source    string             `json:"source"`
	Quotes    map[string]Changes `json:"quotes"`
}

ChangeRate is the response type that holds rate change data.

type Changes

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

Changes is a sub-type of ChangeRate that holds the actual changes of rates.

type ConversionRate

type ConversionRate struct {
	Success bool   `json:"success"`
	Error   Error  `json:"error"`
	Privacy string `json:"privacy"`
	Terms   string `json:"terms"`
	Query   struct {
		From   string  `json:"from"`
		To     string  `json:"to"`
		Amount float64 `json:"amount"`
	} `json:"query"`
	Info struct {
		Timestamp int64   `json:"timestamp"`
		Quote     float64 `json:"quote"`
	} `json:"info"`
	Historical bool    `json:"historical"`
	Date       string  `json:"date"`
	Result     float64 `json:"result"`
}

ConversionRate is a response type holding a converted rate.

type CurrencyLayer

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

CurrencyLayer is a foreign exchange rate provider at https://currencylayer.com NOTE default base currency is USD when using a free account. Has automatic upgrade to a SSL connection.

func (*CurrencyLayer) Convert

func (c *CurrencyLayer) Convert(from, to, date string, amount float64) (float64, error)

Convert converts one currency amount to another currency amount.

func (*CurrencyLayer) GetHistoricalData

func (c *CurrencyLayer) GetHistoricalData(date string, currencies []string, source string) (map[string]float64, error)

GetHistoricalData returns historical exchange rate data for every past day of the last 16 years.

func (*CurrencyLayer) GetRates

func (c *CurrencyLayer) GetRates(baseCurrency, symbols string) (map[string]float64, error)

GetRates is a wrapper function to return rates for GoCryptoTrader

func (*CurrencyLayer) GetSupportedCurrencies

func (c *CurrencyLayer) GetSupportedCurrencies() ([]string, error)

GetSupportedCurrencies returns supported currencies

func (*CurrencyLayer) GetliveData

func (c *CurrencyLayer) GetliveData(currencies, source string) (map[string]float64, error)

GetliveData returns live quotes for foreign exchange currencies

func (*CurrencyLayer) QueryCurrencyChange

func (c *CurrencyLayer) QueryCurrencyChange(startDate, endDate, baseCurrency string, currencies []string) (map[string]Changes, error)

QueryCurrencyChange returns the change (both margin and percentage) of one or more currencies, relative to a Source Currency, within a specific time-frame (optional).

func (*CurrencyLayer) QueryTimeFrame

func (c *CurrencyLayer) QueryTimeFrame(startDate, endDate, baseCurrency string, currencies []string) (map[string]interface{}, error)

QueryTimeFrame returns historical exchange rates for a time-period. (maximum range: 365 days)

func (*CurrencyLayer) SendHTTPRequest

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

SendHTTPRequest sends a HTTP request, if account is not free it automatically upgrades request to SSL.

func (*CurrencyLayer) Setup

func (c *CurrencyLayer) Setup(config base.Settings) error

Setup sets appropriate values for CurrencyLayer

type Error

type Error struct {
	Code int    `json:"code"`
	Info string `json:"info"`
}

Error Defines the response error if an error occurred

type HistoricalRates

type HistoricalRates struct {
	Success    bool               `json:"success"`
	Error      Error              `json:"error"`
	Terms      string             `json:"terms"`
	Privacy    string             `json:"privacy"`
	Historical bool               `json:"historical"`
	Date       string             `json:"date"`
	Timestamp  int64              `json:"timestamp"`
	Source     string             `json:"source"`
	Quotes     map[string]float64 `json:"quotes"`
}

HistoricalRates is a response type holding rates priced from the past.

type LiveRates

type LiveRates struct {
	Success   bool               `json:"success"`
	Error     Error              `json:"error"`
	Terms     string             `json:"terms"`
	Privacy   string             `json:"privacy"`
	Timestamp int64              `json:"timestamp"`
	Source    string             `json:"source"`
	Quotes    map[string]float64 `json:"quotes"`
}

LiveRates is a response type holding rates priced now.

type SupportedCurrencies

type SupportedCurrencies struct {
	Success    bool              `json:"success"`
	Error      Error             `json:"error"`
	Terms      string            `json:"terms"`
	Privacy    string            `json:"privacy"`
	Currencies map[string]string `json:"currencies"`
}

SupportedCurrencies holds supported currency information

type TimeFrame

type TimeFrame struct {
	Success   bool                   `json:"success"`
	Error     Error                  `json:"error"`
	Terms     string                 `json:"terms"`
	Privacy   string                 `json:"privacy"`
	Timeframe bool                   `json:"timeframe"`
	StartDate string                 `json:"start_date"`
	EndDate   string                 `json:"end_date"`
	Source    string                 `json:"source"`
	Quotes    map[string]interface{} `json:"quotes"`
}

TimeFrame is a response type holding exchange rates for a time period

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL