CurrencyConversion
Convert Money Amounts between currencies. This library uses an OTP worker to save current conversion rates.
Installation
The package can be installed by adding currency_conversion to your list of dependencies in mix.exs:
def deps do
[{:currency_conversion, "~> 0.1.1"}]
end
Configuration
There are two config options:
source- Configure which Data Source Should Be Used.- Type:
atom - Default:
CurrencyConversion.Source.Fixer
- Type:
refresh_interval- Configure how often the data should be refreshed. (in ms)- Type:
integer - Default:
86_400_000(Once per Day)
- Type:
config :currency_conversion,
source: CurrencyConversion.Source.Fixer,
refresh_interval: 86_400_000
Custom Source
A custom source can be implemented by using the behaviour CurrencyConversion.Source and reconfiguring the source config.
It only has to implement the function load/0, which produces a struct of type %CurrencyConversion.Rates{}.
Usage
Only the function CurrencyConversion.convert/3 is exposed to the user. The library money is used to represent money amounts.
Example
iex> CurrencyConversion.convert(Money.new(7_00, :CHF), :USD)
%Money{amount: 10_50, currency: :USD}