Skip to Content
Open SourceHydraLibraries@exodus/price-api

@exodus/price-api

Util to fetch, validate and cache prices from server

Installation

npm i @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}] ]

NameTypeDescriptionOptionalReturns
apiFunctionFunction to make request to pricing serverPromise
assetTickersArrayArray of asset tickers to fetch
fiatTickerStringfiat currency supported by Exodus, as well as BTC
granularityStringGranularity of the historical data, values must be day or hour
getCacheFromStorageFunctionaccepts tickerSymbol and returns array historical pricesprices cache
hourlyLimitNumberlimits historical hourly prices to fetch. default=168true
timestampNumbermilliseconds since Unix Epoch to fetch price exact on this datetrue
getCurrentTimeFunctionreturns milliseconds since Unix Epochtruemilliseconds
ignoreInvalidSymbolsBoolignore error when fetch prices for unsupported assets. Empty Map will be returned for this assettrue
ignoreCacheBoolrefetch the entire price history, ignoring existent cached valuestrue
runtimeCacheMapstorage for runtime cachetrue
getRuntimeCacheKeyFunctionget key to access runtime cachetrue

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

NameTypeDescriptionOptional
funcFunctionFunction to make fetch prices
granularityArrayGranularity of the historical data, values must be day or hour
getJitterFunctionFunction that returns jitter (ms) to create delay in [0, jitter] rangetrue
delayNumberdelay in millisecondstrue
getCurrentTimeFunctionreturns milliseconds since Unix Epochtrue
Last updated on

Start building

XO

Request Demo

Schedule a call with our team

Select a product
Arrow right