fx

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2018 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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