Skip to content

A small implementation for currency conversion using http://fixer.io/ in scala.

Notifications You must be signed in to change notification settings

AI-ME-GmbH/sfixer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SFixer

Sfixer is a type safe wrapper for currency conversions in scala pulled from fixer.io. Sfixer uses circe and Jodatime.

Sfixer is http framework agnostic in its core implementation, but will provide a (WIP) akka transport api.

Note: Currently Sfixer does not support querying by a subset of symbols. This is a work in progress library, and it is usable by pulling all rates (i.e pulling all symbols for historical rates, or using the default latest endpoint)

To use, first provide a Rates implementation. You can do this by consuming a Json from sfixer.fixer.io using Rates.consume, then unwrapping the option.

With the implicit rates, you can now perform any conversions in a type safe manner:

implicit val rates: Rates = ...

USD(100).convertTo[EUR] // Convert to typed Euros instance.
EUR(100).convertToValue[EUR] //Convert to unboxed Euros value 

You can also smash together a list of identifiers and values to generate a list of Currencies.

Assume a matrix with the form:

Identifier Value
0 EUR 1600
1 USD 12
2 AUD 1

Using Currency.smash(identifier)(value), you can retrieve a generic list of currencies, which you can then converge into one value, provided it is using the standard naming convention from the ECB

val unprocessed: List[(String, Double)] = ... //Assuming you have an identifier and a double

val currencyList: List[Currency] = unprocessed.map(u => Currency.smash(u._1)(u._2))

val audList : List[AUD] = currencyList.map(_.convertGenericToWrapped[AUD])

For more example usages: Look under the example in the akka package

About

A small implementation for currency conversion using http://fixer.io/ in scala.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages