ECBRates
This library fetches historic EUR rates from the European Central Bank (ECB).
It’s heavily inspired by the Elixir OpenExchangeRates library
Installation
The package can be installed by adding ecb_rates to your list of dependencies in mix.exs:
def deps do
[
{:ecb_rates, "~> 0.1.0"}
]
endConfiguration options
Please note that the library provides sensible defaults for all configuration options, so changing them is entirely optional.
config :ecb_rates, :cache_file, "/tmp/ecb_rates_cache.json" # must be writable
config :ecb_rates, :url, "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.xml"
config :ecb_rates, :cache_time_in_minutes, 1440 # 24 hoursUsage
iex(1)> ECBRates.fetch("2024-10-10")
{:ok,
%{
"AUD" => "1.6276",
"BGN" => "1.9558",
"BRL" => "6.1061",
"CAD" => "1.5031",
"CHF" => "0.9393",
"CNY" => "7.7376",
"CZK" => "25.317",
"DKK" => "7.4592",
"GBP" => "0.83686",
"HKD" => "8.496",
"HUF" => "400.4",
"IDR" => "17165.59",
"ILS" => "4.1238",
"INR" => "91.7985",
"ISK" => "148.5",
"JPY" => "162.85",
"KRW" => "1477.51",
"MXN" => "21.2788",
"MYR" => "4.6915",
"NOK" => "11.792",
"NZD" => "1.7998",
"PHP" => "62.762",
"PLN" => "4.3048",
"RON" => "4.9756",
"SEK" => "11.3655",
"SGD" => "1.43",
"THB" => "36.721",
"TRY" => "37.4017",
"USD" => "1.0932",
"ZAR" => "19.2391"
}}iex(1)> ECBRates.fetch("2024-10-10", "PLN")
{:ok, "4.3048"}iex(1)> ECBRates.fetch(~D[2024-10-10])
{:ok,
%{
"AUD" => "1.6276",
"BGN" => "1.9558",
"BRL" => "6.1061",
"CAD" => "1.5031",
"CHF" => "0.9393",
"CNY" => "7.7376",
"CZK" => "25.317",
"DKK" => "7.4592",
"GBP" => "0.83686",
"HKD" => "8.496",
"HUF" => "400.4",
"IDR" => "17165.59",
"ILS" => "4.1238",
"INR" => "91.7985",
"ISK" => "148.5",
"JPY" => "162.85",
"KRW" => "1477.51",
"MXN" => "21.2788",
"MYR" => "4.6915",
"NOK" => "11.792",
"NZD" => "1.7998",
"PHP" => "62.762",
"PLN" => "4.3048",
"RON" => "4.9756",
"SEK" => "11.3655",
"SGD" => "1.43",
"THB" => "36.721",
"TRY" => "37.4017",
"USD" => "1.0932",
"ZAR" => "19.2391"
}}iex(1)> ECBRates.fetch(~D[2024-10-10], "PLN")
{:ok, "4.3048"}Licence
ISC License
Copyright (c) 2024 Music Glue
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
A copy of the licence text is also included in the file LICENSE