All Projects → jshmrtn → currency-conversion

jshmrtn / currency-conversion

Licence: MIT license
Convert Money Amounts between currencies.

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to currency-conversion

SimpleTypes
The universal PHP library to convert any values and measures (money, weight, currency converter, length, etc.).
Stars: ✭ 56 (+194.74%)
Mutual labels:  money, currencies
Prices
Python price handling for humans.
Stars: ✭ 248 (+1205.26%)
Mutual labels:  money, currencies
Nodamoney
NodaMoney provides a library that treats Money as a first class citizen and handles all the ugly bits like currencies and formatting.
Stars: ✭ 144 (+657.89%)
Mutual labels:  money, currencies
Javamoney Lib
JavaMoney financial libraries, extending and complementing JSR 354
Stars: ✭ 104 (+447.37%)
Mutual labels:  money, currencies
EasyMoney-Widgets
The widgets (EditText and TextView) for support of money requirements like currency, number formatting, comma formatting etc.
Stars: ✭ 91 (+378.95%)
Mutual labels:  money, currencies
Exchanger
🏢 Currency exchange rates framework for PHP
Stars: ✭ 133 (+600%)
Mutual labels:  money, conversion
Fixer
A foreign exchange rates and currency conversion API
Stars: ✭ 2,545 (+13294.74%)
Mutual labels:  money, currencies
currency-converter
💰 Easily convert between 32 currencies
Stars: ✭ 16 (-15.79%)
Mutual labels:  money, currencies
pesa
A JS money lib whose precision goes up to 11 (and beyond).
Stars: ✭ 38 (+100%)
Mutual labels:  money, conversion
latinum
Latinum is a framework for resource and currency calculations.
Stars: ✭ 109 (+473.68%)
Mutual labels:  money, currencies
Countries
Countries - ISO 3166 (ISO3166-1, ISO3166, Digit, Alpha-2 and Alpha-3) countries codes and names (on eng and rus), ISO 4217 currency designators, ITU-T E.164 IDD calling phone codes, countries capitals, UN M.49 regions codes, ccTLD countries domains, IOC/NOC and FIFA letters codes, VERY FAST, NO maps[], NO slices[], NO init() funcs, NO external links/files/data, NO interface{}, NO specific dependencies, Databases/JSON/GOB/XML/CSV compatible, Emoji countries flags and currencies support, full support ISO-3166-1, ISO-4217, ITU-T E.164, Unicode CLDR and ccTLD standarts.
Stars: ✭ 85 (+347.37%)
Mutual labels:  money, currencies
stockholm
💵 Modern Python library for working with money and monetary amounts. Human friendly and flexible approach for development. 100% test coverage + built-in support for GraphQL and Protocol Buffers transports using current best-practices.
Stars: ✭ 26 (+36.84%)
Mutual labels:  money, currencies
Oxr
💱 Node.js wrapper for the Open Exchange Rates API
Stars: ✭ 72 (+278.95%)
Mutual labels:  money, currencies
Django Prices
Django fields for the prices module
Stars: ✭ 135 (+610.53%)
Mutual labels:  money, currencies
react-local-currency
💵 💴Shows the price of your services in the customer's currency 💶 💷
Stars: ✭ 21 (+10.53%)
Mutual labels:  money, currencies
Cash Cli
💰💰 Convert currency rates directly from your terminal!
Stars: ✭ 168 (+784.21%)
Mutual labels:  money, currencies
Alfred Convert
Convert between different units in Alfred
Stars: ✭ 560 (+2847.37%)
Mutual labels:  conversion, currencies
money
Crystal shard for dealing with money and currency conversion
Stars: ✭ 26 (+36.84%)
Mutual labels:  money, conversion
bank2ynab
Easily convert and import your bank's statements into YNAB. This project consolidates other conversion efforts into one universal tool.
Stars: ✭ 197 (+936.84%)
Mutual labels:  money, conversion
monetized
A lightweight solution for handling and storing money.
Stars: ✭ 46 (+142.11%)
Mutual labels:  money, currencies

CurrencyConversion

GitHub license Hex.pm Version Coverage Status

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, "~> 1.0"},
    {:jason, "~> 1.1"}, # When usig Fixer / Exchange Rates API,
    {:httpotion, "~> 3.1"}, # When usig Fixer / Exchange Rates API
  ]
end

Setup

CurrencyConversion is a wrapper around the currency conversion. We can define an implementation as follows:

defmodule MyApp.CurrencyConversion do
  use CurrencyConversion, otp_app: :my_app
end

If your application was generated with a supervisor (by passing --sup to mix new) you will have a lib/my_app/application.ex file containing the application start callback that defines and starts your supervisor. You just need to edit the start/2 function to start the converter as a supervisor on your application's supervisor:

def start(_type, _args) do
  children = [
    {MyApp.CurrencyConversion, []}
  ]
  opts = [strategy: :one_for_one, name: MyApp.Supervisor]
  Supervisor.start_link(children, opts)
end

Configuration

  • source - Configure which Data Source Should Be Used.
    • Type: atom
    • Default: CurrencyConversion.Source.ExchangeRatesApi
    • Restrictions: Must implement CurrencyConversion.Source behaviour
    • Given Implementations:
      • CurrencyConversion.Source.Fixer - Fixer
      • CurrencyConversion.Source.ExchangeRatesApi - Exchange Rates API
      • CurrencyConversion.Source.Test - Test Source
  • base_currency - Change the base currency that is requested when fetching rates
    • Type: atom
    • Default: :EUR
  • refresh_interval - Configure how often the data should be refreshed (in ms) or turn auto-refresh off.
    • Type: integer | :manual
    • Default: 86_400_000 (Once per Day)
    • :manual turns auto-refresh off, do refresh yourself
  • seed - Deliver the rates data manually.
    • Type: (Keyword.t() -> {:ok, CurrencyConversion.Rates.t()} | {:error, binary}) | {module :: atom, function :: atom, arity :: 1}
    • Default: Load from source
  • test_rates - Configure rates for CurrencyConversion.Source.Test source
    • Type: {atom, %{atom: float}}
    • Default: see CurrencyConversion.Source.Test.@default_rates
    • Example: {:EUR, %{CHF: 7.0}}
config :my_app, MyApp.CurrencyConversion,
  source: CurrencyConversion.Source.Fixer,
  source_api_key: "FIXER_ACCESS_KEY",
  source_protocol: "https",
  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{}.

Test

To prevent HTTP calls in the Tests, configure the Test Source. (See the configuration test_rates for custom test rates.)

config :my_app, MyApp.CurrencyConversion,
  source: CurrencyConversion.Source.Test,
  refresh_interval: 86_400_000

Usage

Only the callbacks from CurrencyConversion are exposed to the user. The library money is used to represent money amounts.

Example

Change 7 swiss franks to dollars:

iex> MyApp.CurrencyConversion.convert(Money.new(7_00, :CHF), :USD)
%Money{amount: 10_50, currency: :USD}

Get supported currencies:

iex> MyApp.CurrencyConversion.get_currencies()
[:EUR, :USD, :CHF, ...]

Manually refresh exchange rates:

iex> MyApp.CurrencyConversion.refresh_rates()
:ok
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].