Giter Club home page Giter Club logo

exchange-app's Introduction

ExchangeApp

A Google Apps Script library to exchange currencies based on updated rates.

clasp npm (scoped)

var value = ExchangeApp.convert(20, 'USD', 'BRL');

The fluent way

var value = ExchangeApp.exchange(20).from('USD').to('BRL').convert();

Default rates endpoint

The default rates endpoint is set latest rates from openexchangerate.org and supports around 200 global currencies, including unofficial, black market and alternative digital currencies, such as Bitcoin, Etherum and so on.

Here is a full list of supported codes.

Rates are updated once per hour. Read the FAQ for more details.

Changing rates endpoint

You can change the currency endpoint if you need to implement your own endpoint to query historical rates, or different precision. The endpoint response JSON format should be:

{
  base: string;
  date: string;
  rates: {
    [key: string]: number;
  }
}

Example:

{
  "base": "EUR",
  "rates": {
    "CAD": 1.565,
    "CHF": 1.1798,
    "GBP": 0.87295,
    "SEK": 10.2983,
    "EUR": 1.092,
    "USD": 1.2234,
  }
}

Any base can be used.

Example

A free and realiable rates endpoint you can use is exchangeratesapi.io, which provides current and historical foreign exchange rates published by the European Central Bank.

To convert 20 USD to BRL based on rates of day 2018-04-08:

ExchangeApp.setRatesEndpoint('https://api.exchangeratesapi.io/2018-04-08', 3600//cache)

var value = ExchangeApp.exchange(20).from('USD').to('BRL').convert();

Setup

This library is already published as an Apps Script, making it easy to include in your project.

To add it to your script, do the following in the Apps Script code editor:

  1. Click on the menu item "Resources > Libraries..."
  2. In the "Add a Library" text box, enter the Script ID "12pPyeoZrmRDHjGnm4brpl-uIr424_bjAtFMjedtr5aJc_Pt7vKg3IGwy" and click the "Select" button.
  3. Choose a version in the dropdown box (usually best to pick the latest version).
  4. Click the "Save" button.

Typescript Definitions for autocomplete:

1) Add the package:
npm i -S @bkper/exchange-app-types

or

yarn add --dev @bkper/exchange-app-types
2) Configure tsconfig.json:
{
    "compilerOptions": {
        "typeRoots" : ["node_modules/@bkper", "node_modules/@types" ]
    }
}

Learn more about @types, typeRoots and types

exchange-app's People

Contributors

maelcaldas avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  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.