Coder Social home page Coder Social logo

ecb-fx-rates's Introduction

ecb-fx-rates

Simple and lightweight library for get current and historical fx rates.

Install

Node

npm install ecb-fx-rates --save

Usage

let getRatesFunc = require('ecb-fx-rates');

let currencyName = 'JPY';
let crossCurrencyName = 'JPY/BGN';

let historicalData = new Date().getTime() - 24 * 1000 * 60 * 60 * 24; //get fx rate for 24 days before

Promises examples

//Get historical data for cross-currency
getRatesFunc({currency: crossCurrencyName, date: historicalData}).then(console.info.bind(console, `Historical rate for ${crossCurrencyName}`));

//Get current data for currency
getRatesFunc(currencyName).then(console.info.bind(console, `Current fx rate for ${currencyName}`));
//or
getRatesFunc({currency: currencyName}).then(console.info.bind(console, `Current fx rate for ${currencyName}`));

Callback examples

//Get historical data for cross-currency
getRatesFunc({currency: crossCurrencyName, date: historicalData}, function (err, rate) {
    if (err) {
        return console.error(err);
    }
    
    console.info(`Historical rate for ${crossCurrencyName}`, rate);
});

//Get current data for currency
getRatesFunc(currencyName, function (err, rate) {
    if (err) {
        return console.error(err);
    }
    
    console.info(`Current fx rate for ${currencyName}`, rate);
});
//or
getRatesFunc({currency: currencyName}, function (err, rate) {
    if (err) {
        return console.error(err);
    }
    
    console.info(`Current fx rate for ${currencyName}`, rate)
});

Description

Syntax

//JSDOC descriptions for common types

/**
 * @typedef {number} FormattedDate
 * @description ms of start of the day
 */

/**
 * @typedef {{}} fxRateOpts
 * @property {boolean} [exactDate=false] if true - returns only date, that asked, else - returns exchange rate from the last nearest date if no data
 * @property {Date} [date=new Date()] - date for get historical exchange rates
 * @property {string} currency
 * @property {boolean} [ignoreCache=false]
 * @property {boolean} [dontStoreCache=false]
 */

/**
 * @callback GetFxRateCallback
 * @param {?err} error
 * @param {?number} data
 */

/**
 * @typedef {Object<string, number>} fxRateData
 */
 
//MAIN FUNCTION DESCRIPTION

/**
 * Get foreign exchange rate
 * @param {fxRateOpts|string} optsOrTicker
 * @param {GetFxRateCallback} [cb]
 * @returns Promise<number>
 */
let getRatesFunc = require('ecb-fx-rate');

Test

Test

npm install
npm run test

Change list

Version 1.0.0

  • Initial commit

ecb-fx-rates's People

Watchers

James Drew 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.