PTAX.Rates behaviour (ptax v3.0.0)

Copy Markdown View Source

The source of the rates PTAX converts with.

Every conversion reads its rate through this behaviour, resolved for the pair from the bulletin BCB published for the date.

Each direction reads the side of the spread matching it, because BCB publishes a separate bid and ask for every currency.

Summary

Callbacks

Returns the rate converting from_currency into to_currency on date, or {:error, exception} if no rate is available for the pair.

Callbacks

rate(from_currency, to_currency, date)

@callback rate(
  from_currency :: Localize.Currency.currency_code(),
  to_currency :: Localize.Currency.currency_code(),
  date :: Date.t()
) :: {:ok, Decimal.t()} | {:error, Exception.t()}

Returns the rate converting from_currency into to_currency on date, or {:error, exception} if no rate is available for the pair.

The rate is how many units of to_currency one unit of from_currency buys, and the rate for the opposite direction is not its reciprocal.