greven

greven

Forex - European Central Bank (ECB) exchange rates for Elixir

Hey, just released a small library called Forex, to retrieve the European Central Bank daily exchange rates.

The idea behind the library is to provide a simple, no API keys, no authentication, no rate limits, just a simple Elixir library that fetches the data from the European Central Bank and caches it for later use.

With this said take into account this is not aimed at building any type of transactional app, financial applications or any type of application that relies on to the second foreign exchange rates. The reference rates from the ECB are usually updated at around 16:00 CET every working day. This is useful for information purposes, for example, you might want to show on your job board how much is the role salary range in the user’s local currency, etc.

Usage

By default the base currency is the Euro (EUR), the same as the European Central Bank,
but you can change the base currency by passing the base option to the relevant functions.

Sample Usage

To fetch the latest exchange rates, you can use the current_rates/1 function:

iex> Forex.current_rates()
{:ok,
  %{
    base: :eur,
    date: ~D[2025-03-12],
    rates: %{
      usd: Decimal.new("1.1234"),
      jpy: Decimal.new("120.1234"),
      ...
      zar: Decimal.new("24.1442")
    }}
  }

If you use it and found a bug or have any suggestion, don’t hesitate to create an issue or post here. :slight_smile:

Thanks,

Nuno F.

Hex: forex | Hex
Repo:

Most Liked

Eiji

Eiji

Forex.base_currency_rate/0 is not documented. Looks like it’s used by other functions. Should it be defp instead or maybe @doc false (in case you use it in other modules too)?


I would rather suggest to return structs instead of maps in case you already know what keys and values you have to expect. This would save lots of time on debugging for trivial typos.


You should consider using typespecs now. I’ve got that’s not supposed to be a 1.0.0 release and it does not need to be a top #1 priority, but it would definitely affect the documentation. For example let’s take a look at Forex.options/1.

With a spec like:

@spec options(Keyword.t()) :: options
# or even
@spec options(input_options) :: options

You can define options type, move all options documentation there and finally use options type in spec for other functions. This way you don’t have to copy-paste same documentation as developers interested what options are supported would simply hover or click on the options type link in the function spec.

@spec current_rates(input_options | options) :: map

In this example both options types are just Keyword.t(), but with different @typedoc. The input_options only have to mention that options/1 function would be used to get validated options. This way documentation would be much easier to read.


Please do not use spaces before header syntax in markdown, see: Forex — forex v0.1.1


You should change this line:

to:

    source_ref: "v" <> @version,

This is because your tags have v before version (which is not bad at all) and you don’t have a branch with this version. I guess you have copy-pasted a “working” configuration, but forgot to work in the branch. Because of that tiny mistake all links to the source code does not work.


You may be interested in adding badges to your README.md file, see:


It would be amazing to have a function like Forex.exchange_historic_rate(historic_date). This way people can create an example sites (like shop template) with a real prices. In many cases there would be no need to update the prices because of inflation which may be especially useful if in such template are used base products like food.


Please keep in mind that’s a public post. You may already know what I wrote, but it may be helpful for others.

LostKobrakai

LostKobrakai

That’s actually quite nice. Usually that stuff comes with all of those limits. Also daily updates is actually fine for a lot of stuff.

greven

greven

Hmm weird. I’m releasing a new version soon with the changes I highlighted above. So keep tuned for that.

There is no configuration needed. That’s an SSL issue. By default I’m using Req as the client. The error is an issue I had but it’s already fixed in the next version. Dunno why there might be a certificate error with the request tho.

Thanks for reporting.

greven

greven

Thanks for your suggestions! This was just a first release, I actually forgot to delete the application mod, the library is supposed to be started in the supervision tree, of course.
So already doing some changes.

greven

greven

This is exactly what this library does, but with pluggable Cache and client and some extra utilities. :slight_smile:

Still rewriting some stuff, adding more tests and some extra utilities. Will release a new version soon.

Where Next?

Popular in Libraries Top

scohen
Lexical Lexical is a next-generation language server for the Elixir programming language. Features Context aware code completion As-you...
New
Crowdhailer
Raxx is an alternative to Plug and is inspired by projects such as Rack(Ruby) and Ring(Clojure). 1.0-rc.1 is now available. To use it re...
New
zoltanszogyenyi
Hey everyone :wave: Excited to join this forum - I am one of the founders and current project maintainers of a popular and open-source U...
New
achempion
Hi, I would like to tell about my initiative to further maintain and develop Waffle project which is the fork of Arc library. The progre...
New
tmbb
I’ve published the first version of my Makeup library. It’s a syntax highlighter for Elixir in the spirit of Pygments, Currently it highl...
New
mbuhot
EctoJob A transactional job queue built with Ecto, PostgreSQL and GenStage Available on Hex.pm: ecto_job | Hex Docs: API Reference — ec...
New
alisinabh
Hey everyone i’ve developed a library for Jalaali calendar for elixir which supports converting Gregorian dates to Jalaali and vice vers...
New
vic
Expat is a tiny experiment I did for extracting patterns and being able to reuse them (compose and share patterns between elixir librarie...
New
versilov
Could not wait for the missing Elixir ML libraries to appear, so, I wrote one myself, taking https://github.com/sdwolfz/exlearn as a foun...
New
bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
381 12391 119
New

Other popular topics Top

jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Sub Categories:

We're in Beta

About us Mission Statement