Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@apilayer/currencylayer

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apilayer/currencylayer

Currencylayer offers Reliable Exchange Rates & Currency Conversion for your Business

  • 0.1.6
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
4
Maintainers
2
Weekly downloads
 
Created
Source

currencylayer-js

Currencylayer offers Reliable Exchange Rates & Currency Conversion for your Business

Installation

Using npm

npm install --save @apilayer/currencylayer

or yarn

yarn add @apilayer/currencylayer

Getting Started

Head over to Currencylayer and create an account. Copy access key from dashboard.

import Currencylayer from '@apilayer/currencylayer';

const layer = new Currencylayer({
  key: "<your-access-key>"
  source: "USD",
  secure: false
})

Alternatively, you can change the default currency used by the library by:

layer.setSource("GBP")

Unsupported currency codes with throw an error.

If you're using typescript, you can import SourceType type.

import Currencylayer, { SourceType } from '@apilayer/currencylayer';

const layer = new Currencylayer({
  ...
  source: SourceType.USD,
})

Note:

RequestDate type represents a string matching "YYYY-mm-dd" or a date object

Live rates

To fetch current live rates, use the Live() method and pass in string slice of accepted currencies.

Signature:

live(sources: SourceType[]): Promise<LiveResponse>

Example:

const response = layer.live(["GBP", "NGN"])

console.log("response:", response)

Response:

{
	success: true,
	timestamp: 1566902074,
	source: "USD",
	quotes: {
    "USDGBP": "0.82",
    "USDNGN": "366.02",
  }
}

An unsupported currency code will cause an error.

Historical

To get rates for a currency pair at a date in the past, you should make a historical request:

Signature:

historical(date: RequestDate, sources: SourceType[] = []): Promise<HistoricalResponse>

Example:

const response = layer.historical("2019-01-21", ["GBP", "NGN"])

console.log("response:", response)

Response:

{
  success: true,
	historical: true,
	timestamp: 1566902074,
  source: "USD",
  date: "2019-06-01",
	quotes: {
    "USDGBP": "0.82",
    "USDNGN": "366.02",
  }
}

Auto Conversion

It is also possible to convert an amount from a currency to its equivalent value in another currency.

Signature:

convert(
  from: SourceType,
  to: SourceType,
  amount: number,
  date: RequestDate = new Date()
): Promise<ConvertResponse>

Example:

const response = layer.convert("USD", "GBP", 100.00)

console.log("response:", response)

The above call does a conversion of 100 USD to GBP as at the current date.

Response:

{
  success: true,
	info: {
    timestamp: 1566902074,
    quote: 82.00,
  },
  result: 82.00,
	query: {
    from: "USD",
    to: "GBP",
    amount: 100.00,
  },
	historical: false,
  date: "2019-06-01",
}

Alternatively, you can do a conversion for at a specific date

const response = layer.convert("USD", "GBP", 100.00, "2019-01-21")

Timeframe

Timeframe: you may request historical exchange rates for a time-period of your choice. (maximum range: 365 days)

Signature:

timeframe(
  start: RequestDate,
  end: RequestDate,
  sources: SourceType[]
): Promise<TimeframeResponse>

Example:

const response = layer.timeframe("2019-06-01", new Date(), ["GBP", "NGN"])

console.log("response:", response)

Response:

{
  success: true,
  timeframe: true,
	start_date: "2019-06-01",
	end_date: "2019-06-04",
	source: "USD",
	quotes: {
    "2019-06-01": {"USDGBP": 0.82, "USDNGN": 365.03},
    "2019-06-02": {"USDGBP": 0.82, "USDNGN": 366.51},
    "2019-06-03": {"USDGBP": 0.82, "USDNGN": 365.3},
    "2019-06-04": {"USDGBP": 0.82, "USDNGN": 366.01},
  }
}

Change

Change request the change (both margin and percentage) of one or more currencies, relative to a Source Currency, within a specific time-frame

Signature:

change(start: RequestDate, end: RequestDate, sources: SourceType[]): Promise<ChangeResponse>

Example:

const response = layer.change("2019-06-01", new Date(), ["GBP", "NGN"])

console.log("response:", response)

Response:

{
  success: true,
  change: bool
	start_date: "2019-06-01"
	end_date: "2019-06-02"
	source: "USD"
	quotes: {
    "USDGBP": {
      start_rate: 0.82,
      end_rate: 0.81,
      change: 0.01,
      change_pct: 1.21,
    },
    "USDNGN": {
      start_rate: 366.60,
      end_rate: 364.25,
      change: 2.35,
      change_pct: 0.64,
    }
  }
}

Supported Currencies

A list of all supported currencies can be displayed by:

layer.list()

Or, you can see a list of all supported currencies below:

CodeName
AEDUnited Arab Emirates Dirham
AFNAfghan Afghani
ALLAlbanian Lek
AMDArmenian Dram
ANGNetherlands Antillean Guilder
AOAAngolan Kwanza
ARSArgentine Peso
AUDAustralian Dollar
AWGAruban Florin
AZNAzerbaijani Manat
BAMBosnia-Herzegovina Convertible Mark
BBDBarbadian Dollar
BDTBangladeshi Taka
BGNBulgarian Lev
BHDBahraini Dinar
BIFBurundian Franc
BMDBermudan Dollar
BNDBrunei Dollar
BOBBolivian Boliviano
BRLBrazilian Real
BSDBahamian Dollar
BTCBitcoin
BTNBhutanese Ngultrum
BWPBotswanan Pula
BYRBelarusian Ruble
BZDBelize Dollar
CADCanadian Dollar
CDFCongolese Franc
CHFSwiss Franc
CLFChilean Unit of Account (UF)
CLPChilean Peso
CNYChinese Yuan
COPColombian Peso
CRCCosta Rican Colón
CUCCuban Convertible Peso
CUPCuban Peso
CVECape Verdean Escudo
CZKCzech Republic Koruna
DJFDjiboutian Franc
DKKDanish Krone
DOPDominican Peso
DZDAlgerian Dinar
EGPEgyptian Pound
ERNEritrean Nakfa
ETBEthiopian Birr
EUREuro
FJDFijian Dollar
FKPFalkland Islands Pound
GBPBritish Pound Sterling
GELGeorgian Lari
GGPGuernsey Pound
GHSGhanaian Cedi
GIPGibraltar Pound
GMDGambian Dalasi
GNFGuinean Franc
GTQGuatemalan Quetzal
GYDGuyanaese Dollar
HKDHong Kong Dollar
HNLHonduran Lempira
HRKCroatian Kuna
HTGHaitian Gourde
HUFHungarian Forint
IDRIndonesian Rupiah
ILSIsraeli New Sheqel
IMPManx pound
INRIndian Rupee
IQDIraqi Dinar
IRRIranian Rial
ISKIcelandic Króna
JEPJersey Pound
JMDJamaican Dollar
JODJordanian Dinar
JPYJapanese Yen
KESKenyan Shilling
KGSKyrgystani Som
KHRCambodian Riel
KMFComorian Franc
KPWNorth Korean Won
KRWSouth Korean Won
KWDKuwaiti Dinar
KYDCayman Islands Dollar
KZTKazakhstani Tenge
LAKLaotian Kip
LBPLebanese Pound
LKRSri Lankan Rupee
LRDLiberian Dollar
LSLLesotho Loti
LTLLithuanian Litas
LVLLatvian Lats
LYDLibyan Dinar
MADMoroccan Dirham
MDLMoldovan Leu
MGAMalagasy Ariary
MKDMacedonian Denar
MMKMyanma Kyat
MNTMongolian Tugrik
MOPMacanese Pataca
MROMauritanian Ouguiya
MURMauritian Rupee
MVRMaldivian Rufiyaa
MWKMalawian Kwacha
MXNMexican Peso
MYRMalaysian Ringgit
MZNMozambican Metical
NADNamibian Dollar
NGNNigerian Naira
NIONicaraguan Córdoba
NOKNorwegian Krone
NPRNepalese Rupee
NZDNew Zealand Dollar
OMROmani Rial
PABPanamanian Balboa
PENPeruvian Nuevo Sol
PGKPapua New Guinean Kina
PHPPhilippine Peso
PKRPakistani Rupee
PLNPolish Zloty
PYGParaguayan Guarani
QARQatari Rial
RONRomanian Leu
RSDSerbian Dinar
RUBRussian Ruble
RWFRwandan Franc
SARSaudi Riyal
SBDSolomon Islands Dollar
SCRSeychellois Rupee
SDGSudanese Pound
SEKSwedish Krona
SGDSingapore Dollar
SHPSaint Helena Pound
SLLSierra Leonean Leone
SOSSomali Shilling
SRDSurinamese Dollar
STDSão Tomé and Príncipe Dobra
SVCSalvadoran Colón
SYPSyrian Pound
SZLSwazi Lilangeni
THBThai Baht
TJSTajikistani Somoni
TMTTurkmenistani Manat
TNDTunisian Dinar
TOPTongan Paʻanga
TRYTurkish Lira
TTDTrinidad and Tobago Dollar
TWDNew Taiwan Dollar
TZSTanzanian Shilling
UAHUkrainian Hryvnia
UGXUgandan Shilling
USDUnited States Dollar
UYUUruguayan Peso
UZSUzbekistan Som
VEFVenezuelan Bolívar Fuerte
VNDVietnamese Dong
VUVVanuatu Vatu
WSTSamoan Tala
XAFCFA Franc BEAC
XAGSilver (troy ounce)
XAUGold (troy ounce)
XCDEast Caribbean Dollar
XDRSpecial Drawing Rights
XOFCFA Franc BCEAO
XPFCFP Franc
YERYemeni Rial
ZARSouth African Rand
ZMKZambian Kwacha (pre-2013)
ZMWZambian Kwacha
ZWLZimbabwean Dollar

License

MIT

FAQs

Package last updated on 01 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc