This package is for learning purposes and its use in production is not yet recommended.
A currency converter that uses the API provided by the Brazilian Open Data Portal to perform quotes
This package can be installed by adding ptax to your list of dependencies in mix.exs:
def deps do
[
{:ptax, "~> 1.0"}
]
endInstall and configure a Tesla adapter:
# config/config.exs
config :tesla, adapter: Tesla.Adapter.HackneySee Tesla installation and adapters docs.
iex> PTAX.currencies()
{:ok, [:EUR, :GBP, ...]}iex> PTAX.Quotation.list(:GBP, Date.range(~D[2021-12-24], ~D[2021-12-26]))
{:ok, [%PTAX.Quotation{...}, ...]}iex> PTAX.Quotation.get(:GBP, ~D[2021-12-24], :closing)
{:ok, %PTAX.Quotation{...}}iex> PTAX.exchange(PTAX.Money.new(5, :GBP), to: :EUR, date: ~D[2021-12-24])
{:ok, #Money<5.918, EUR>}
iex> alias PTAX.Money.Pair
...> gbp_usd = Pair.new(1.3402, 1.3406, :GBP, :USD)
...> eur_usd = Pair.new(1.1319, 1.1323, :EUR, :USD)
...> Pair.combine(gbp_usd, eur_usd)
#Money.Pair<1.1836086/1.1843802, GBP/EUR>iex> alias PTAX.Money
...> pair = Money.Pair.new(1.1836086, 1.1843802, :GBP, :EUR)
...> Money.exchange(Money.new(5, :GBP), pair)
#Money<5.918, EUR>
...> Money.exchange(Money.new(5, :EUR), pair)
#Money<4.2216, GBP>