Skip to content

openprovider/ecbrates

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 

The European Central Bank exchange rates

A package to get the ECB exchange rates for use with Go (golang) services

Build Status GoDoc

Examples

Check a current exchange rate

package main

import (
	"fmt"
	"log"

	"github.com/openprovider/ecbrates"
)

func main() {
	r, err := ecbrates.New()
	if err != nil {
		log.Fatal("Error: ", err)
	}

	// Case 1: get dollar rate relative to euro
	if value, ok := r.Rate[ecbrates.USD].(string); ok {
		fmt.Println("Exchange rate", r.Date, ": EUR 1 -> USD", value)
	}

	// Case 2: convert of 100 euros to dollars
	if value, err := r.Convert(100, ecbrates.EUR, ecbrates.USD); err == nil {
		fmt.Println("Exchange rate", r.Date, ": EUR 100.0 -> USD", value)
	}

	// Case 3: convert of 100 dollars to yens
	if value, err := r.Convert(100, ecbrates.USD, ecbrates.JPY); err == nil {
		fmt.Println("Exchange rate", r.Date, ": USD 100.0 -> JPY", value)
	}
}

Show history of exchange rates for EUR -> USD

package main

import (
	"fmt"
	"log"

	"github.com/openprovider/ecbrates"
)

func main() {
	rates, err := ecbrates.Load() // 90 days history
	// rates, err := ecbrates.LoadAll() // ALL history
	if err != nil {
		log.Fatal("Error: ", err)
	}

	for _, r := range rates {
		if value, ok := r.Rate[ecbrates.USD].(string); ok {
			fmt.Println("Exchange rate", r.Date, ": EUR 1 -> USD", value)
		}
	}
}

Contributors (unsorted)

All the contributors are welcome. If you would like to be the contributor please accept some rules.

  • The pull requests will be accepted only in "develop" branch
  • All modifications or additions should be tested

Thank you for your understanding!

License

MIT Public License

About

Openprovider: The European Central Bank exchange rates

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages