getPrice

getPrice method is used to fetch the latest price for a single or several tokens

Get the latest price for a single token

getPrice(symbol: string, opts?: GetPriceOptions): _Promise<_PriceData>

Returns the latest price for a single symbol

Parameters:

Returns: Promise<PriceData>

The latest price for the token

Defined in: limestone-api.ts:59

Get the latest price for several tokens

getPrice(symbols: string[], opts?: GetPriceOptions): Promise<{ [token: string]: PriceData; }>

Returns the latest price for several symbols

Parameters:

Returns: Promise<{ [token: string]: PriceData; }>

The latest price for the tokens

Defined in: limestone-api.ts:70

Examples

Get the latest price for a single token

const price = await limestone.getPrice("AR");

console.log(price.value); // latest price value for AR token (in USD)
console.log(price.timestamp); // the exact timestamp of the price

All the prices are denominated in USD. You can fetch price data for BTC, ETH, AR, EUR and any other of 100+ supported tokens

Price data format

  {
    value: 123.23, // Number: Price value in USD
    timestamp: 1617146511173, // Number: Timestamp (ms) for price
    provider: "I-5rWUehEv-MjdK9gFw09RxfSLQX9DIHxG614Wf8qo0", // String: Provider arweave address
    permawebTx: "V8FUU0BG4kVOJwKWHzgkn1aEFm-eanhqqEXfPFY7pmI", // String: Arweave transaction id
    source: {"coingecko": 123,"sushiswap": 123.23,"uniswap": 123.35}, // Object: Prices from different sources
  }

Fetch price using promises

  // As async/await is only a syntactic sugar on Javascript
  // Promises you can use them in a "standard" way
  const price = limestone.getPrice("AR").then((price) => {
    console.log(price.value); // latest price value for AR token
  });

Get the latest prices for several tokens

To fetch prices for several tokens use the getPrice method and pass an array with any subset of supported tokens.

const prices = await limestone.getPrice(["BTC", "ETH", "AR", "EUR"]);

console.log(prices); // Example output below
/*
{
  "BTC": {
    value: 58953.39,
    timestamp: 1617152802779,
    ...
  },
  "ETH": {
    value: 1856.75,
    timestamp: 1617152802779,
    ...
  },
  ...
}
*/


console.log(prices["BTC"].value); // latest price value for BTC
console.log(prices["ETH"].value); // latest price value for ETH
console.log(prices["AR"].value); // latest price value for AR

Last updated