Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Colombian Peso and Polish Zloty in Money supported #435

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ scala> val exchangeRates = List(USD / CAD(1.05), USD / MXN(12.50), USD / JPY(100
exchangeRates: List[squants.market.CurrencyExchangeRate] = List(USD/CAD 1.05, USD/MXN 12.5, USD/JPY 100.0)

scala> implicit val moneyContext = defaultMoneyContext withExchangeRates exchangeRates
moneyContext: squants.market.MoneyContext = MoneyContext(DefaultCurrency(USD),Currencies(ARS,AUD,BRL,BTC,CAD,CHF,CLP,CNY,CZK,DKK,ETH,EUR,GBP,HKD,INR,JPY,KRW,LTC,MXN,MYR,NAD,NOK,NZD,RUB,SEK,USD,XAG,XAU,ZAR),ExchangeRates(USD/CAD 1.05,USD/JPY 100.0,USD/MXN 12.5),AllowIndirectConversions(true))
moneyContext: squants.market.MoneyContext = MoneyContext(DefaultCurrency(USD),Currencies(ARS,AUD,BRL,BTC,CAD,CHF,CLP,CNY,CZK,DKK,ETH,EUR,GBP,HKD,INR,JPY,KRW,LTC,MXN,MYR,NAD,NOK,NZD,RUB,SEK,USD,XAG,XAU,ZAR,COP,PLN),ExchangeRates(USD/CAD 1.05,USD/JPY 100.0,USD/MXN 12.5),AllowIndirectConversions(true))

scala> val energyPrice = USD(102.20) / MegawattHours(1)
energyPrice: squants.market.Price[squants.energy.Energy] = 102.2 USD/1.0 MWh
Expand Down Expand Up @@ -925,7 +925,7 @@ implicit val moneyContext = defaultMoneyContext

```scala
scala> implicit val moneyNum = new MoneyNumeric()
moneyNum: squants.market.MoneyConversions.MoneyNumeric = MoneyNumeric(MoneyContext(DefaultCurrency(USD),Currencies(ARS,AUD,BRL,BTC,CAD,CHF,CLP,CNY,CZK,DKK,ETH,EUR,GBP,HKD,INR,JPY,KRW,LTC,MXN,MYR,NAD,NOK,NZD,RUB,SEK,USD,XAG,XAU,ZAR),ExchangeRates(),AllowIndirectConversions(true)))
moneyNum: squants.market.MoneyConversions.MoneyNumeric = MoneyNumeric(MoneyContext(DefaultCurrency(USD),Currencies(ARS,AUD,BRL,BTC,CAD,CHF,CLP,CNY,CZK,DKK,ETH,EUR,GBP,HKD,INR,JPY,KRW,LTC,MXN,MYR,NAD,NOK,NZD,RUB,SEK,USD,XAG,XAU,ZAR,COP,PLN),ExchangeRates(),AllowIndirectConversions(true)))

scala> val sum = List(USD(100), USD(10)).sum
sum: squants.market.Money = 1.1E+2 USD
Expand Down Expand Up @@ -1322,7 +1322,7 @@ import squants.time.TimeConversions._

```scala
scala> implicit val moneyContext = defaultMoneyContext
moneyContext: squants.market.MoneyContext = MoneyContext(DefaultCurrency(USD),Currencies(ARS,AUD,BRL,BTC,CAD,CHF,CLP,CNY,CZK,DKK,ETH,EUR,GBP,HKD,INR,JPY,KRW,LTC,MXN,MYR,NAD,NOK,NZD,RUB,SEK,USD,XAG,XAU,ZAR),ExchangeRates(),AllowIndirectConversions(true))
moneyContext: squants.market.MoneyContext = MoneyContext(DefaultCurrency(USD),Currencies(ARS,AUD,BRL,BTC,CAD,CHF,CLP,CNY,CZK,DKK,ETH,EUR,GBP,HKD,INR,JPY,KRW,LTC,MXN,MYR,NAD,NOK,NZD,RUB,SEK,USD,XAG,XAU,ZAR,COP,PLN),ExchangeRates(),AllowIndirectConversions(true))

scala> val energyPrice: Price[Energy] = 45.25.money / megawattHour
energyPrice: squants.market.Price[squants.energy.Energy] = 45.25 USD/1.0 MWh
Expand Down
5 changes: 4 additions & 1 deletion shared/src/main/scala/squants/market/Money.scala
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,8 @@ object ETH extends Currency("ETH", "Ether", "\u039E", 15)
object LTC extends Currency("LTC", "Litecoin", "\u0141", 15)
object ZAR extends Currency("ZAR", "South African Rand", "R", 2)
object NAD extends Currency("NAD", "Namibian Dollar", "N$", 2)

object COP extends Currency("COP", "Colombian Peso", "$", 2)
object PLN extends Currency("PLN", "Polish Zloty", "zł", 2)
/**
* Support for Money DSL
*/
Expand Down Expand Up @@ -512,6 +513,8 @@ object MoneyConversions {
def litecoin = LTC
def ZAR = Money(n, squants.market.ZAR)
def NAD = Money(n, squants.market.NAD)
def COP = Money(n, squants.market.COP)
def PLN = Money(n, squants.market.PLN)
}

class MoneyNumeric()(implicit mc: MoneyContext) extends Numeric[Money] {
Expand Down
4 changes: 4 additions & 0 deletions shared/src/test/scala/squants/market/MoneySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class MoneySpec extends AnyFlatSpec with Matchers {
implicit val moneyContext = MoneyContext(USD, defaultCurrencySet, Nil)
Currency("USD") should be(Success(USD))
Currency("NAD") should be(Success(NAD))
Currency("COP") should be(Success(COP))
Currency("PLN") should be(Success(PLN))
Currency("DUM") should be(Failure(NoSuchCurrencyException("DUM", moneyContext)))
}

Expand Down Expand Up @@ -484,6 +486,8 @@ class MoneySpec extends AnyFlatSpec with Matchers {
d.litecoin should be(LTC(d))
d.ZAR should be(ZAR(d))
d.NAD should be(NAD(d))
d.COP should be(COP(d))
d.PLN should be(PLN(d))
}

it should "provide Numeric support within a MoneyContext with no Exchange Rates" in {
Expand Down