fx

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2020 License: MIT Imports: 9 Imported by: 0

README

fx

Forex exchange implementation

Usage

OpenExchange API implementation

fx := fx.NewOpenExchange(API_KEY, cacheClient, 30*time.Second)
source := money.New(10000, "USD")
dest := money.GetCurrency("CAD")
info, err := fx.Exchange(source, dest)
fmt.Println("CAD: ", info.Dest.Amount())

Other exchanges can be added by implementing the interface:

type Exchange interface {
	Exchange(source *money.Money, dest *money.Currency) (info *Info, err error)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Exchange

type Exchange interface {
	Exchange(source *money.Money, dest *money.Currency) (info *Info, err error)
}

Exchange provider interface

func NewMockExchange

func NewMockExchange() (client Exchange)

func NewOpenExchange

func NewOpenExchange(apiKey string, cache *cache.Client, cacheTTL time.Duration) (client Exchange)

NewOpenExchange returns Open Exchange client

Usage:

fx := fx.NewOpenExchange(API_KEY, cacheClient, 30*time.Second)

type Info

type Info struct {
	Source *money.Money
	Dest   *money.Money
	Rate   int64
}

Info defines the response to an Exchange request. It contains the source, dest and the rate to which the conversion was done.

type MockExchange

type MockExchange struct{}

MockExchange for tests

func (*MockExchange) Exchange

func (e *MockExchange) Exchange(source *money.Money, dest *money.Currency) (info *Info, err error)

Exchange mocks rate exchange for tests

type OpenExchange

type OpenExchange struct {
	APIKey   string
	Cache    *cache.Client
	CacheTTL time.Duration
}

OpenExchange implements fx.Exchange This is an Open Exchange API implementation

func (*OpenExchange) Exchange

func (e *OpenExchange) Exchange(source *money.Money, dest *money.Currency) (info *Info, err error)

Exchange converts the source Money object to the dest currency.

Jump to

Keyboard shortcuts

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