PTAX (ptax v1.0.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
Link to this function
currencies()
@spec currencies() :: {:ok, [currency()]} | {:error, PTAX.Error.t()}
Returns a list of supported currencies
examples
Examples
iex> PTAX.currencies()
{:ok, ~w[GBP EUR 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.5247", :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.7297", :GBP)}
iex> PTAX.exchange(PTAX.Money.new("546.56", :GBP), to: :USD, date: ~D[2021-12-24])
{:ok, PTAX.Money.new("732.4997", :USD)}
iex> PTAX.exchange(PTAX.Money.new("15.69", :EUR), to: :GBP, date: ~D[2021-12-24])
{:ok, PTAX.Money.new("13.2474", :GBP)}