PTAX

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

installation

Installation

This package can be installed by adding ptax to your list of dependencies in mix.exs:

def deps do
  [
    {:ptax, "~> 0.1"}
  ]
end

configuration

Configuration

Install and configure a Tesla adapter:

# config/config.exs

config :tesla, adapter: Tesla.Adapter.Hackney

See Tesla installation and adapters docs.

usage

Usage

listing-supported-currencies

Listing supported currencies

iex> PTAX.currencies()
{:ok, [:EUR, :GBP, ...]}

listing-a-currency-quotation-for-a-date-range

Listing a currency quotation for a date range

iex> PTAX.Quotation.list(:GBP, Date.range(~D[2021-12-24], ~D[2021-12-26]))
{:ok, [%PTAX.Quotation{...}, ...]}

getting-a-currency-quotation-for-a-specific-date-and-bulletin

Getting a currency quotation for a specific date and bulletin

iex> PTAX.Quotation.get(:GBP, ~D[2021-12-24], PTAX.Quotation.Bulletin.Closing)
{:ok, %PTAX.Quotation{...}}

exchange-a-currency-amount-to-another

Exchange a currency amount to another

iex> PTAX.exchange(PTAX.Money.new(5, :GBP), to: :EUR, date: ~D[2021-12-24])
{:ok, #Money<5.918, EUR>}

combine-two-currency-pairs-based-on-usd-as-the-common-currency

Combine two currency pairs, based on USD as the common currency

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>

exchange-a-currency-amount-given-the-currency-pair

Exchange a currency amount given the currency pair

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>