PTAX.Money.Pair (ptax v1.1.1)
Defines a Currency Pair
structure.
Link to this section Summary
Link to this section Types
@type t() :: %PTAX.Money.Pair{ amount: %{ask: PTAX.Money.amount(), bid: PTAX.Money.amount()}, base_currency: PTAX.Money.currency(), quoted_currency: PTAX.Money.currency() }
Link to this section Functions
Link to this function
combine(pair1, pair2)
@spec combine(pair, pair) :: pair when pair: t()
Combines two currency pairs, based on their common currency
examples
Examples:
# Type A / Type A
iex> PTAX.Money.Pair.combine(PTAX.Money.Pair.new(6.5673, 6.5691, :USD, :DKK), PTAX.Money.Pair.new(8.8365, 8.8395, :USD, :NOK))
PTAX.Money.Pair.new(1.3459869, 1.3451614, :DKK, :NOK)
# Type A / Type B
iex> PTAX.Money.Pair.combine(PTAX.Money.Pair.new(1.2813, 1.2815, :USD, :CAD), PTAX.Money.Pair.new(0.7232, 0.7236, :AUD, :USD))
PTAX.Money.Pair.new(1.0791722, 1.0791722, :CAD, :AUD)
# Type B / Type A
iex> PTAX.Money.Pair.combine(PTAX.Money.Pair.new(1.3402, 1.3406, :GBP, :USD), PTAX.Money.Pair.new(0.9185, 0.9192, :USD, :CHF))
PTAX.Money.Pair.new(1.2309737, 1.2309737, :GBP, :CHF)
# Type B / Type B
iex> PTAX.Money.Pair.combine(PTAX.Money.Pair.new(1.3402, 1.3406, :GBP, :USD), PTAX.Money.Pair.new(1.1319, 1.1323, :EUR, :USD))
PTAX.Money.Pair.new(1.1836086, 1.1843802, :GBP, :EUR)
Link to this function
new(bid, ask, base_currency, quoted_currency)
@spec new( bid :: value, ask :: value, base_currency :: currency, quoted_currency :: currency ) :: t() when currency: PTAX.Money.currency(), value: Decimal.decimal() | float()
Create a new currency pair.
examples
Examples:
iex> PTAX.Money.Pair.new(2, 2.1, :GBP, :USD)
%PTAX.Money.Pair{amount: %{bid: PTAX.Money.to_amount(2), ask: PTAX.Money.to_amount("2.1")}, base_currency: :GBP, quoted_currency: :USD}