PTAX
A currency converter backed by the Brazilian Central Bank (BCB) PTAX closing rates.
Installation
def deps do
[
{:ptax, "~> 2.0"}
]
endConfiguration
PTAX integrates with ex_money's exchange rate system. Add it to your config:
# config/config.exs
config :ex_money, api_module: PTAX.ExchangeRatesUsage
Convert using the latest known rates
iex> PTAX.exchange(Money.new!(:USD, "100"), :BRL)
{:ok, Money.new!(:BRL, "506.48")}Convert using rates for a specific date
iex> PTAX.exchange(Money.new!(:GBP, "50"), :BRL, ~D[2026-05-15])
{:ok, Money.new!(:BRL, "337.60")}
Dates with no BCB data (weekends, holidays) return {:error, {Money.ExchangeRateError, "404"}}. The latest-rates lookup automatically walks back up to 7 days to find the most recent available data.
See also
PTAX only provides the rate source. For richer operations, use ex_money directly:
Money.to_currency/2,3— convert between any two currenciesMoney.cross_rate/2— derive a cross rate between two currenciesMoney.ExchangeRates— access and configure the exchange rate backend