PTAX (ptax v0.4.0)

Gathers supported currency listing and conversion functions

Link to this section Summary

Functions

Returns a list of supported currencies

Similar to exchange/2, but throws an error if the amount cannot be converted.

Converts a value from one currency to another

Link to this section Functions

@spec currencies() :: {:ok, [currency()]} | {:error, PTAX.Error.t()}

Returns a list of supported currencies

examples

Examples

iex> PTAX.currencies()
{:ok, ~w[GBP USD]a}
Link to this function

exchange!(money, opts)

@spec exchange!(money(), opts :: exchange_opts()) :: money()

Similar to exchange/2, but throws an error if the amount cannot be converted.

examples

Examples

iex> PTAX.exchange!(PTAX.Money.new(15, :USD), to: :BRL, date: ~D[2021-12-24])
PTAX.Money.new(84.8115, :BRL)

iex> PTAX.exchange!(PTAX.Money.new(15.45, :USD), to: :GBP, date: ~D[2021-12-24])
PTAX.Money.new(11.5145, :GBP)

iex> PTAX.exchange!(PTAX.Money.new(15.45, :USD), to: :GBPS, date: ~D[2021-12-24])
** (PTAX.Error) Unknown error
Link to this function

exchange(money, opts)

@spec exchange(money(), opts :: exchange_opts()) :: {:ok, money()} | {:error, error()}

Converts a value from one currency to another

examples

Examples

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