@exodus/price-api

4.0.1 • Public • Published

@exodus/price-api

Util to fetch, validate and cache prices from server

Table of Contents

Installation

yarn add @exodus/price-api

Quick start

Module contains following useful utils:

fetchHistoricalPrices

Based on provided arguments prepares params for request to exodus pricing server. Depending on runtime cache and client long-term cache decides how much data needs to be fetched. Validates data and prepares result to defined data structure.

Arguments

prices cache example: [1502496000000, {close: 44}], [1502582400000, {close: 12}] ]

Name Type Description Optional Returns
api Function Function to make request to pricing server Promise
assetTickers Array Array of asset tickers to fetch
fiatTicker String fiat currency supported by Exodus, as well as BTC
granularity String Granularity of the historical data, values must be day or hour
getCacheFromStorage Function accepts tickerSymbol and returns array historical prices prices cache
hourlyLimit Number limits historical hourly prices to fetch. default=168 true
timestamp Number milliseconds since Unix Epoch to fetch price exact on this date true
getCurrentTime Function returns milliseconds since Unix Epoch true milliseconds
ignoreInvalidSymbols Bool ignore error when fetch prices for unsupported assets. Empty Map will be returned for this asset true
ignoreCache Bool refetch the entire price history, ignoring existent cached values true
runtimeCache Map storage for runtime cache true
getRuntimeCacheKey Function get key to access runtime cache true

Returns

Object with Maps with prices Maps by asset ticker. prices Map keyed by timestamp in milliseconds. historicalPricesMap includes prices from cache fetchedPricesMap includes only assets fetched from server. If asset had cache but new prices fetched from server this Map includes combined data

{
  historicalPricesMap: new Map([
 ['ZRX', new Map([ [1502496000000, {close: 44}], [1502582400000, {close: 12}] ])],
 ['BTC', new Map([ [1502496000000, {close: 10000}], [1502582400000, {close: 50000}] ])],
]),
  fetchedPricesMap: new Map([
 ['ZRX', new Map([ [1502496000000, {close: 44}], [1502582400000, {close: 12}] ])],
 ['BTC', new Map([ [1502496000000, {close: 10000}], [1502582400000, {close: 50000}] ])],
])
}

fetchPricesInterval

Setup interval to fetch prices. Daily prices updated on UTC day start, hourly every UTC and local hour start.

Arguments

Name Type Description Optional
func Function Function to make fetch prices
granularity Array Granularity of the historical data, values must be day or hour
getJitter Function Function that returns jitter (ms) to create delay in [0, jitter] range true
delay Number delay in milliseconds true
getCurrentTime Function returns milliseconds since Unix Epoch true

Readme

Keywords

Package Sidebar

Install

npm i @exodus/price-api

Weekly Downloads

2,383

Version

4.0.1

License

MIT

Unpacked Size

19.2 kB

Total Files

15

Last publish

Collaborators

  • juraex
  • kevva
  • doguhan
  • ps.mcnally
  • janwe
  • yevhenii_molodyk
  • javiexodus
  • ismamz
  • exojo
  • feri42
  • jprichardson
  • farisissa
  • ryanzim
  • headfire
  • gutenye
  • mosesbot
  • roccomuso
  • dcastagnoli
  • sonaye
  • ves
  • tenaciousmv
  • asyakost
  • bulgakovk
  • chalker
  • andrejb
  • jaydp17
  • olistic
  • joepie91
  • merlz
  • vbonini
  • mol0d
  • devopsrobot
  • jenish-sojitra
  • markoexodus
  • nachoalvarez
  • giovannirco
  • filipexodus
  • cryptosgr
  • andrescarreon
  • diegomura
  • lanre-mark
  • sunilagrawal
  • guillecura
  • mariosvlad
  • federico-po
  • akinncar
  • fboucquez
  • lanahizzle
  • kwwood
  • umito
  • mzndako
  • joshuabot
  • iaacek
  • meniem
  • skapala
  • awilson-rs
  • ezenwankwogabriel
  • ggabarrin-rs
  • ralph.ba
  • danh.t.vo
  • voltagebots
  • ryansquared-npm
  • alexandrbbm
  • sergii_bo
  • florianmathieu
  • angelloz
  • exodus-justin.za
  • alex.alexandrius
  • rec
  • rg911
  • jamiemaw
  • james-gre
  • shehryar6
  • geoffreyrousset
  • clarkexo
  • tunguyennnnn
  • jschopen
  • cawfree
  • marcos.kichel
  • andrewtoth-exodus
  • cdotta-exodus
  • exorich
  • mmehta-10
  • kryptkeep
  • 633kh4ck
  • mbaraniak-exodus
  • jeehahn
  • hasakura
  • awesomeniko
  • davidexodus
  • r4vn
  • nantoaqui
  • exoleo
  • ale-exo
  • frankliexodus
  • bekatd
  • ronaldcrb
  • muratso
  • metasal