PTAX.Quotation (ptax v1.0.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: bulletin(),
  currency: currency(),
  pairs: %{bid: PTAX.Money.Pair.t(), ask: PTAX.Money.Pair.t(), type: atom()},
  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{
    currency: :USD,
    bid: PTAX.Money.new(5.6541, :BRL),
    ask: PTAX.Money.new(5.6591, :BRL),
    pairs: %{
      type: :A,
      bid: PTAX.Money.Pair.new(1.0, :USD, :USD),
      ask: PTAX.Money.Pair.new(1.0, :USD, :USD)
    },
    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{
      currency: :GBP,
      bid: PTAX.Money.new(7.5605, :BRL),
      ask: PTAX.Money.new(7.5669, :BRL),
      pairs: %{
        type: :B,
        bid: PTAX.Money.Pair.new(1.3417, :GBP, :USD),
        ask: PTAX.Money.Pair.new(1.3421, :GBP, :USD)
      },
      quoted_in: DateTime.from_naive!(~N[2021-12-24 10:08:31.922], "America/Sao_Paulo"),
      bulletin: PTAX.Quotation.Bulletin.Opening
    },
    %PTAX.Quotation{
      currency: :GBP,
      bid: PTAX.Money.new(7.6032, :BRL),
      ask: PTAX.Money.new(7.6147, :BRL),
      pairs: %{
        type: :B,
        bid: PTAX.Money.Pair.new(1.3402, :GBP, :USD),
        ask: PTAX.Money.Pair.new(1.3406, :GBP, :USD)
      },
      quoted_in: DateTime.from_naive!(~N[2021-12-24 11:04:02.173], "America/Sao_Paulo"),
      bulletin: PTAX.Quotation.Bulletin.Intermediary
    },
    %PTAX.Quotation{
      currency: :GBP,
      bid: PTAX.Money.new(7.5776, :BRL),
      ask: PTAX.Money.new(7.5866, :BRL),
      pairs: %{
        type: :B,
        bid: PTAX.Money.Pair.new(1.3402, :GBP, :USD),
        ask: PTAX.Money.Pair.new(1.3406, :GBP, :USD)
      },
      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{
      currency: :GBP,
      bid: PTAX.Money.new(7.5605, :BRL),
      ask: PTAX.Money.new(7.5669, :BRL),
      pairs: %{
        type: :B,
        bid: PTAX.Money.Pair.new(1.3417, :GBP, :USD),
        ask: PTAX.Money.Pair.new(1.3421, :GBP, :USD)
      },
      quoted_in: DateTime.from_naive!(~N[2021-12-24 10:08:31.922], "America/Sao_Paulo"),
      bulletin: PTAX.Quotation.Bulletin.Opening
    }
  ]
}