Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Rates ¶
type Rates struct { Base string `json:"base"` Date time.Time `json:"date"` Values map[string]float64 `json:"values"` }
Rates contains exchange rate values for a specific base currency on a particular date.
func Between ¶
Between returns exchange rates per day for the selected base currency, in the specified interval. Specific exchange rates can be requested by using the currencies parameter. If currencies is nil, all available exchange rates are returned.
Example ¶
package main import ( "fmt" "time" "github.com/adrg/exrates" ) func main() { start := time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC) end := time.Date(2019, 4, 22, 0, 0, 0, 0, time.UTC) // Get all available exchange rates. days, err := exrates.Between("USD", start, end, nil) if err != nil { // Treat error. return } // Get specific exchange rates. // days, err := exrates.Between("EUR", start, end, []string{"USD", "CAD"}) for _, day := range days { fmt.Printf("Exchange rates for %s on %s\n", day.Base, day.Date) for currency, value := range day.Values { fmt.Printf("%s: %f\n", currency, value) } } }
Output:
func Latest ¶
Latest returns the latest exchange rates for the selected base currency. Specific exchange rates can be requested by using the currencies parameter. If currencies is nil, all available exchange rates are returned.
Example ¶
package main import ( "fmt" "github.com/adrg/exrates" ) func main() { // Get all available exchange rates. rates, err := exrates.Latest("USD", nil) if err != nil { // Treat error. return } // Get specific exchange rates. // rates, err := exrates.Latest("EUR", []string{"USD", "CAD"}) fmt.Printf("Exchange rates for %s on %s\n", rates.Base, rates.Date) for currency, value := range rates.Values { fmt.Printf("%s: %f\n", currency, value) } }
Output:
func On ¶
On returns the exchange rates available on the specified date, for the selected base currency. Specific exchange rates can be requested by using the currencies parameter. If currencies is nil, all available exchange rates are returned.
Example ¶
package main import ( "fmt" "time" "github.com/adrg/exrates" ) func main() { date := time.Date(2019, 3, 8, 0, 0, 0, 0, time.UTC) // Get all available exchange rates. rates, err := exrates.On("USD", date, nil) if err != nil { // Treat error. return } // Get specific exchange rates. // rates, err := exrates.On("EUR", date, []string{"USD", "CAD"}) fmt.Printf("Exchange rates for %s on %s\n", rates.Base, rates.Date) for currency, value := range rates.Values { fmt.Printf("%s: %f\n", currency, value) } }
Output: