GithubHelp home page GithubHelp logo

fawadkhanse / java-exchange-rates Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ritaja/java-exchange-rates

0.0 0.0 0.0 142 KB

JAVA Library for currency conversion

License: Apache License 2.0

Java 100.00%

java-exchange-rates's Introduction

Build Status

Jitpack

Java exchange rates API

A Java library which provides API for currency conversion. It uses different web based servivces to obtain live conversion rates, store them and allow offline currency conversions.

To allow offline conversion, this library stores conversion rates obtained from the web-service and uses the stored exchange rates for offline conversion. Each time the Library is run it checks if the conversion rates stored are outdated. If it finds outdated exchange rates it updates the stored exchange rates (using the web-service defined) and then completes the conversion task. To instuct the code when to consider exchange rates as outdated set the refreshRate parameter. An example code below explains this scenario.

supported web-services:

  1. currencyLayer API (A access token is required to use this service, a free token can be obtained from here.)
  2. Yahoo finance currency exchange rate service

Example Use:

using the yahoo finance endpoint

// create the appropriate servive object
private CurrencyConverter converter = new CurrencyConverterBuilder()
				.strategy(Strategy.YAHOO_FINANCE_FILESTORE)
				.buildConverter();

// set the refresh rate  to set timer to update new exchange rates
converter.setRefreshRateSeconds(86400);

// convert between currencies
// general format of conversion is convertCurrency(amount, fromCurrency, toCurrency)
// example conversion of 100 USD to EUR is:
converter.convertCurrency(new BigDecimal("100"), Currency.USD, Currency.EUR)
// Thats how easy it is......

using the currency layer endpoint (needs access key)

// create the appropriate servive object
private CurrencyConverter converter = new CurrencyConverterBuilder()
				.strategy(Strategy.CURRENCY_LAYER_FILESTORE)
				.accessKey(YOUR_ACCESS_KEY)
				.buildConverter();

// set the refresh rate  to set timer to update new exchange rates
converter.setRefreshRateSeconds(86400);

// convert between currencies
// general format of conversion is convertCurrency(amount, fromCurrency, toCurrency)
// example conversion of 100 USD to EUR is:
converter.convertCurrency(new BigDecimal("100"), Currency.USD, Currency.EUR)
// Thats how easy it is......

Yahoo finance endpoint has different timestamps for each currency exchange rate. This library checks for the updated exchange rate for the desiered currencies efore the conversion task. This behaviour is controlled by the refreshRate parameter.

To set the file path where files should be stored on disk, simply use:

converter.setResourceFilepath(DESIERED_FILEPATH);

The default filepath is picked up from Java System.getProperty("java.io.tmpdir");

This library can be grabbed using Jitpack.io:

MAVEN

<repository>
	    <id>jitpack.io</id>
	    <url>https://jitpack.io</url>
</repository>

and then add dependancy

<dependency>
	    <groupId>com.github.Ritaja</groupId>
	    <artifactId>java-exchange-rates</artifactId>
	    <version>1.0</version>
</dependency>

GRADLE

 repositories {
        // ...
        maven { url "https://jitpack.io" }
    }

and then add dependancy

dependencies {
	        compile 'com.github.Ritaja:java-exchange-rates:1.0'
	}

The list of supported currencies at the moment limited to service provided by currecyLayer API which includes the following 168 currencies:

Code Name
AED United Arab Emirates Dirham
AFN Afghan Afghani
ALL Albanian Lek
AMD Armenian Dram
ANG Netherlands Antillean Guilder
AOA Angolan Kwanza
ARS Argentine Peso
AUD Australian Dollar
AWG Aruban Florin
AZN Azerbaijani Manat
BAM Bosnia-Herzegovina Convertible Mark
BBD Barbadian Dollar
BDT Bangladeshi Taka
BGN Bulgarian Lev
BHD Bahraini Dinar
BIF Burundian Franc
BMD Bermudan Dollar
BND Brunei Dollar
BOB Bolivian Boliviano
BRL Brazilian Real
BSD Bahamian Dollar
BTC Bitcoin
BTN Bhutanese Ngultrum
BWP Botswanan Pula
BYR Belarusian Ruble
BZD Belize Dollar
CAD Canadian Dollar
CDF Congolese Franc
CHF Swiss Franc
CLF Chilean Unit of Account (UF)
CLP Chilean Peso
CNY Chinese Yuan
COP Colombian Peso
CRC Costa Rican Colón
CUC Cuban Convertible Peso
CUP Cuban Peso
CVE Cape Verdean Escudo
CZK Czech Republic Koruna
DJF Djiboutian Franc
DKK Danish Krone
DOP Dominican Peso
DZD Algerian Dinar
EEK Estonian Kroon
EGP Egyptian Pound
ERN Eritrean Nakfa
ETB Ethiopian Birr
EUR Euro
FJD Fijian Dollar
FKP Falkland Islands Pound
GBP British Pound Sterling
GEL Georgian Lari
GGP Guernsey Pound
GHS Ghanaian Cedi
GIP Gibraltar Pound
GMD Gambian Dalasi
GNF Guinean Franc
GTQ Guatemalan Quetzal
GYD Guyanaese Dollar
HKD Hong Kong Dollar
HNL Honduran Lempira
HRK Croatian Kuna
HTG Haitian Gourde
HUF Hungarian Forint
IDR Indonesian Rupiah
ILS Israeli New Sheqel
IMP Manx pound
INR Indian Rupee
IQD Iraqi Dinar
IRR Iranian Rial
ISK Icelandic Króna
JEP Jersey Pound
JMD Jamaican Dollar
JOD Jordanian Dinar
JPY Japanese Yen
KES Kenyan Shilling
KGS Kyrgystani Som
KHR Cambodian Riel
KMF Comorian Franc
KPW North Korean Won
KRW South Korean Won
KWD Kuwaiti Dinar
KYD Cayman Islands Dollar
KZT Kazakhstani Tenge
LAK Laotian Kip
LBP Lebanese Pound
LKR Sri Lankan Rupee
LRD Liberian Dollar
LSL Lesotho Loti
LTL Lithuanian Litas
LVL Latvian Lats
LYD Libyan Dinar
MAD Moroccan Dirham
MDL Moldovan Leu
MGA Malagasy Ariary
MKD Macedonian Denar
MMK Myanma Kyat
MNT Mongolian Tugrik
MOP Macanese Pataca
MRO Mauritanian Ouguiya
MUR Mauritian Rupee
MVR Maldivian Rufiyaa
MWK Malawian Kwacha
MXN Mexican Peso
MYR Malaysian Ringgit
MZN Mozambican Metical
NAD Namibian Dollar
NGN Nigerian Naira
NIO Nicaraguan Córdoba
NOK Norwegian Krone
NPR Nepalese Rupee
NZD New Zealand Dollar
OMR Omani Rial
PAB Panamanian Balboa
PEN Peruvian Nuevo Sol
PGK Papua New Guinean Kina
PHP Philippine Peso
PKR Pakistani Rupee
PLN Polish Zloty
PYG Paraguayan Guarani
QAR Qatari Rial
RON Romanian Leu
RSD Serbian Dinar
RUB Russian Ruble
RWF Rwandan Franc
SAR Saudi Riyal
SBD Solomon Islands Dollar
SCR Seychellois Rupee
SDG Sudanese Pound
SEK Swedish Krona
SGD Singapore Dollar
SHP Saint Helena Pound
SLL Sierra Leonean Leone
SOS Somali Shilling
SRD Surinamese Dollar
STD São Tomé and Príncipe Dobra
SVC Salvadoran Colón
SYP Syrian Pound
SZL Swazi Lilangeni
THB Thai Baht
TJS Tajikistani Somoni
TMT Turkmenistani Manat
TND Tunisian Dinar
TOP Tongan Paʻanga
TRY Turkish Lira
TTD Trinidad and Tobago Dollar
TWD New Taiwan Dollar
TZS Tanzanian Shilling
UAH Ukrainian Hryvnia
UGX Ugandan Shilling
USD United States Dollar
UYU Uruguayan Peso
UZS Uzbekistan Som
VEF Venezuelan Bolívar Fuerte
VND Vietnamese Dong
VUV Vanuatu Vatu
WST Samoan Tala
XAF CFA Franc BEAC
XAG Silver (troy ounce)
XAU Gold (troy ounce)
XCD East Caribbean Dollar
XDR Special Drawing Rights
XOF CFA Franc BCEAO
XPF CFP Franc
YER Yemeni Rial
ZAR South African Rand
ZMK Zambian Kwacha (pre-2013)
ZMW Zambian Kwacha
ZWL Zimbabwean Dollar

java-exchange-rates's People

Contributors

ritaja avatar vetal232 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.