Coding Dojo

Edit on Gitlab

Wallet

Subject

Given a Wallet containing Stocks, build a function that compute the value of wallet in a currency.

The Stocks have a quantity and a StockType. The StockType can be for example petroleum, Euros, bitcoins and Dollars.

To value the portfilio in a Currency you can use external api to provide rate exchanges (some are provided below).

Object sample

Value value = Wallet(Stock(5, PETROLEUM)).value(EUR, rateProvider)

With rateProvider an implementation of this interface :

rateProvider.rate(from: StockType, to: Currency) -> double

and PETROLEUM is a StockType and EUR is a Currency.

Functional sample

Value value = compute_value(Wallet(Stock(5, PETROLEUM), EUR, rateProvider))

Where rateProvider is a function with this signature :

rateProvider(from: StockType, to: Currency) -> double

and PETROLEUM is a StockType and EUR is a Currency.

Suggested rates sources

Some APIs can be used to provides rates: