PTAX (ptax v2.0.0)

Copy Markdown

Converts between currencies using the Brazilian Central Bank's PTAX rates.

Summary

Functions

Exchanges a Money amount to the given currency using the latest known PTAX rates.

Exchanges a Money amount to the given currency using PTAX rates for the given date.

Functions

exchange(money, currency)

@spec exchange(Money.t(), Money.currency_reference()) ::
  {:ok, Money.t()} | {:error, {module(), binary()}}

Exchanges a Money amount to the given currency using the latest known PTAX rates.

Returns {:ok, Money.t()} on success, or {:error, reason} if the rates are unavailable or the currency is not supported.

Examples

iex> {:ok, %Money{}} = PTAX.exchange(Money.new!(:USD, "100"), :BRL)

exchange(money, currency, date)

@spec exchange(Money.t(), Money.currency_reference(), Date.t()) ::
  {:ok, Money.t()} | {:error, {module(), binary()}}

Exchanges a Money amount to the given currency using PTAX rates for the given date.

Returns {:ok, Money.t()} on success, or {:error, reason} if the rates are unavailable or the currency is not supported.

Examples

iex> PTAX.exchange(Money.new!(:GBP, "50"), :BRL, ~D[2026-05-15])
{:ok, Money.new!(:BRL, "7.41")}