ilp-exchange-rate

0.2.0 • Public • Published

ILP Exchange Rate

Description

Converts a given amount, assetCode, and asset Scale to the ILP provider's assetCode and assetScale. Alternatively, you can fetch the exchange rate of two assets given their assetCode and assetScale.

Usage

const Exchange = require('ilp-exchange-rate')

const foreignAssetCode = 'USD'
const foreignAssetScale = 2
const amount = 100            //1 USD

async function conversion () {
  const convertedAsset = await Exchange.convert(amount, foreignAssetCode, foreignAssetScale)
  console.log(convertedAsset)
}

const ownAssetCode = 'XRP'
const ownAssetScale = 6

async function fetchRate () {
  const exchangeRate = await Exchange.fetchRate (foreignAssetCode, foreignAssetScale, ownAssetCode, ownAssetScale)
  console.log(exchangeRate)
}

conversion()
// { amount: 2540000000, assetCode: 'XRP', assetScale: 9 }
fetchRate()
// 25400

Advanced Usage

The module comes with the following exchange rate APIs

You may choose your preferred API

async function conversion () {
  const convertedAsset = await Exchange.convert(amount, foreignAssetCode, foreignAssetScale, 'bitstamp')
  console.log(convertedAsset)

async function fetchRate () {
  const exchangeRate = await Exchange.fetchRate (foreignAssetCode, foreignAssetScale, ownAssetCode, ownAssetScale, 'bitstamp')
  console.log(exchangeRate)
}

conversion()
// { amount: 2540521314, assetCode: 'XRP', assetScale: 9 }

fetchRate()
// 25405.213149738323

Readme

Keywords

none

Package Sidebar

Install

npm i ilp-exchange-rate

Weekly Downloads

1

Version

0.2.0

License

ISC

Unpacked Size

5.57 kB

Total Files

3

Last publish

Collaborators

  • sabinebertram