Skip to content
forked from mattevans/dinero

๐Ÿ“ˆ ๐Ÿ’ฐ A golang interface for the Open Exchange Rates API

License

Notifications You must be signed in to change notification settings

refurbed/dinero

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

10 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

dinero

GoDoc Build Status Go Report Card license

dinero is a Go client library for accessing the Open Exchange Rates API (https://docs.openexchangerates.org/docs/).

Upon request of forex rates these will be cached (in-memory), keyed by base currency. With a two hour expiry window, subsequent requests will use cached data or fetch fresh data accordingly.

Installation

go get -u github.com/mattevans/dinero

Usage

Get All

// Init dinero client.
client := NewClient(os.Getenv("OPEN_EXCHANGE_APP_ID"))

// Set a base currency to work with.
client.Rates.SetBaseCurrency("AUD")

// Get latest forex rates using AUD as a base currency.
response, err := client.Rates.All()
if err != nil {
  return err
}
{
   "rates":{
      "AED":2.702388,
      "AFN":48.893275,
      "ALL":95.142814,
      "AMD":356.88691,
      ...
   },
   "updated_at":"2016-12-16T11:25:47.38290048+13:00",
   "base":"AUD"
}

Get Single

// Init dinero client.
client := NewClient(os.Getenv("OPEN_EXCHANGE_APP_ID"))

// Set a base currency to work with.
client.Rates.SetBaseCurrency("AUD")

// Get latest forex rate for NZD using AUD as a base currency.
response, err := client.Rates.Single("NZD")
if err != nil {
  return err
}
1.045545

Expire in-memory cache

The following will expire the in-memory cache for the set base currency.

client.Cache.Expire()

Contributing

If you've found a bug or would like to contribute, please create an issue here on GitHub, or better yet fork the project and submit a pull request!

About

๐Ÿ“ˆ ๐Ÿ’ฐ A golang interface for the Open Exchange Rates API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%