PTAX (ptax v1.1.1)

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 Types

@type currency() :: PTAX.Money.currency()
@type error() :: PTAX.Error.t()
Link to this type

exchange_opts()

@type exchange_opts() ::
  [to: currency(), date: Date.t()] | %{to: currency(), date: Date.t()}
@type money() :: PTAX.Money.t()

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[BRL EUR 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(10, :USD), to: :BRL, date: ~D[2021-12-24])
PTAX.Money.new("56.541", :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)}