PTAX.Quotation (ptax v0.4.0)

Define a quotation structure for a currency

Link to this section Summary

Functions

Returns the quotation of a currency for the date

Returns a quotation list of a currency for a period

Link to this section Types

@type t() :: %PTAX.Quotation{
  ask: PTAX.Money.t(),
  bid: PTAX.Money.t(),
  bulletin: PTAX.Quotation.Bulletin.t(),
  quoted_in: DateTime.t()
}

Link to this section Functions

Link to this function

get(currency, date, bulletin \\ Bulletin.Closing)

@spec get(currency(), date(), bulletin() | nil) ::
  {:ok, t()} | {:error, PTAX.Error.t()}

Returns the quotation of a currency for the date

examples

Examples

iex> PTAX.Quotation.get(:USD, ~D[2021-12-24])
{
  :ok,
  %PTAX.Quotation{
    bid: PTAX.Money.new(5.6541, :BRL),
    ask: PTAX.Money.new(5.6591, :BRL),
    quoted_in: DateTime.from_naive!(~N[2021-12-24 11:04:02.178], "America/Sao_Paulo"),
    bulletin: PTAX.Quotation.Bulletin.Closing
  }
}
Link to this function

list(currency, period, bulletin \\ nil)

@spec list(
  currency(),
  period(),
  bulletin() | [bulletin()] | nil
) :: {:ok, [t()]} | {:error, PTAX.Error.t()}

Returns a quotation list of a currency for a period

examples

Examples

iex> PTAX.Quotation.list(:GBP, Date.range(~D[2021-12-24], ~D[2021-12-24]))
{
  :ok,
  [
   %PTAX.Quotation{
     bid: PTAX.Money.new(7.5605, :BRL),
     ask: PTAX.Money.new(7.5669, :BRL),
     quoted_in: DateTime.from_naive!(~N[2021-12-24 10:08:31.922], "America/Sao_Paulo"),
     bulletin: PTAX.Quotation.Bulletin.Opening
   },
   %PTAX.Quotation{
     bid: PTAX.Money.new(7.6032, :BRL),
     ask: PTAX.Money.new(7.6147, :BRL),
     quoted_in: DateTime.from_naive!(~N[2021-12-24 11:04:02.173], "America/Sao_Paulo"),
     bulletin: PTAX.Quotation.Bulletin.Intermediary
   },
   %PTAX.Quotation{
     bid: PTAX.Money.new(7.5776, :BRL),
     ask: PTAX.Money.new(7.5866, :BRL),
     quoted_in: DateTime.from_naive!(~N[2021-12-24 11:04:02.178], "America/Sao_Paulo"),
     bulletin: PTAX.Quotation.Bulletin.Closing
   }
  ]
}

iex> PTAX.Quotation.list(:GBP, Date.range(~D[2021-12-24], ~D[2021-12-24]), PTAX.Quotation.Bulletin.Opening)
{
  :ok,
  [
   %PTAX.Quotation{
     bid: PTAX.Money.new(7.5605, :BRL),
     ask: PTAX.Money.new(7.5669, :BRL),
     quoted_in: DateTime.from_naive!(~N[2021-12-24 10:08:31.922], "America/Sao_Paulo"),
     bulletin: PTAX.Quotation.Bulletin.Opening
   }
  ]
}