GithubHelp home page GithubHelp logo

currency's Introduction

@brave-intl/currency

a currency conversion ratio cache

installation

npm install --save @brave-intl/currency

testing

npm install
npm test

instantiation

the following are valid ways to create a new currency instance

const instance1 = new Currency({ /* options */ })
const instance2 = Currency({ /* options */ })

the following will get you the global instance to be shared.

const globl = Currency.global()

Options

  • rates - (object)
    • url - (string) url that points to previous instances of the rates endpoint
    • access_token - (string) the access token needed for the above url
  • oxr - (object)
    • apiId - (string) oxr app id supplied by registering with oxr

Members

  • prices - (function -> Promise) a function to fetch prices
  • BigNumber - (Constructor -> BigNumber) a bignumber.js instance that will be used in each ratio computation

API

ready

ready(options) -> Promise

Returns a Promise that resolves when the oxr and binance data have been fetched, or immediately if there are already values.

  • Object? (historical)
    • date - date to get data for
    • currency - altcurrency to get historical data for. only used if retrieving date.
    • base - base currency to check against

update

update(options) -> Promise

Forcefully refreshes the prices.

base

base() -> String

returns the base currency against which all others are measured.

fiat

fiat(currency: String) -> BigNumber
fiat(currency: String) -> null

Returns the ratio of the passed fiat currency to the base provided by open exchange rates. If the value does not exist (because ready has not finished or because the key is not found) null will be returned.

alt

alt(currency: String) -> BigNumber
alt(currency: String) -> null

Returns the ratio of the passed alt currency to the base provided by binance. If the value does not exist (because ready has not finished or because the key is not found) null will be returned.

ratio

ratio(A: String, B: String) -> BigNumber
ratio(A: String, B: String) -> null

Returns the ratio of B over A. An easy way to think about this is how many of, "With 1A, I can get xBs", where x is the result in the form of a BigNumber Object. Null is returned if one of the currencies is not

has

has(currency: String) -> Boolean

Checks whether a value exists for the given currency.

lastUpdated

lastUpdated() -> Date[ISO]

A Number representing a Date in ms denotes the last time the currencies were fetched. If 0 is returned, then the currencies have not yet finished their first fetching.

rates

rates(base?: String) -> Object[BigNumber]
rates(base?: String) -> null

All altrates and fiatrates in one object with the values as BigNumber(s). Null is returned if the base, is not found.

currency's People

Contributors

maikelmclauflin avatar porteron avatar nvonpentz avatar dependabot[bot] avatar orspetol avatar thypon avatar evq avatar

Stargazers

Hudson Newey avatar

Watchers

Brendan Eich avatar Marshall T. Rose avatar James Cloos avatar Terry Mancey avatar jenn avatar  avatar Matthew Williams avatar  avatar Jon Staples avatar  avatar

Forkers

isabella232

currency's Issues

update packages

the following packages have warnings issued when yarn is run

warning @brave-intl/currency > @hapi/[email protected]: This version has been deprecated and is no longer supported or maintained
warning @brave-intl/currency > [email protected]: This module has moved and is now available at @hapi/wreck. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
warning @brave-intl/currency > @hapi/boom > @hapi/[email protected]: This version has been deprecated and is no longer supported or maintained
warning @brave-intl/currency > wreck > [email protected]: This module has moved and is now available at @hapi/bourne. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
warning @brave-intl/currency > @hapi/[email protected]: Switch to 'npm install joi'
warning @brave-intl/currency > @hapi/joi > @hapi/[email protected]: This version has been deprecated and is no longer supported or maintained
warning @brave-intl/currency > wreck > [email protected]: This module has moved and is now available at @hapi/boom. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
warning @brave-intl/currency > wreck > [email protected]: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
warning @brave-intl/currency > wreck > boom > [email protected]: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
warning @brave-intl/currency > @hapi/joi > @hapi/[email protected]: Moved to 'npm install @sideway/address'
warning @brave-intl/currency > @hapi/joi > @hapi/[email protected]: This version has been deprecated and is no longer supported or maintained
warning @brave-intl/currency > @hapi/joi > @hapi/topo > @hapi/[email protected]: This version has been deprecated and is no longer supported or maintained
warning @brave-intl/currency > @hapi/joi > @hapi/[email protected]: This version has been deprecated and is no longer supported or maintained
warning @brave-intl/currency > oxr > [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
warning @brave-intl/currency > oxr > request > [email protected]: this library is no longer supported
warning @brave-intl/currency > node-binance-api > [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142

swap binance for uphold

uphold has a public api for tickers, which is the provider we use anyway. so might as well just use it for ticker prices so the prices understood through the whole system are consistent

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.