Developed by: Jay Rank
price-indexer
is a SDK built to fetch price feed data from Chainlink Oracles over EVM-compatible blockchains as well as from DIA Org over NEAR blockchain.
For installation, refer here or run the following command in your node project.
npm install price-indexer
1. Fetch Latest Price for ETH-USD
from Chainlink Oracles
This function returns the value of 1 Ethreum in terms of USD currency.
- Use this function when you simply want to fetch
ETH-USD
conversion.
const PriceIndexer = require('price-indexer');
let networkName = 'mainnet'; // Only works on 'mainnet' network over EVM.
let fetchPriceIndex;
async function getLatestPriceFeed() {
fetchPriceIndex = await new PriceIndexer(networkName).basePrice();
console.log(fetchPriceIndex);
}
getLatestPriceFeed();
2. Fetch Latest Price for any asset from Chainlink Oracles
This function returns the value of one asset/cryptocurrency in terms of other asset/cryptocurrency (e.g. in FTM-ETH
oracle, index of 1 FTM in terms of ETH is returned).
- Use this function when you want to fetch any asset except
USD
. - If the base assset is not
USD
, you can get the price inUSD
by setting the value tertiary variablefalse
.- For example: If the address holds for
FTM-ETH
, you can get the price inUSD
instead ofETH
by setting the value tertiary variablefalse
.
- For example: If the address holds for
const PriceIndexer = require('price-indexer');
let networkName = 'mainnet'; // 'mainnet', 'rinkeby', 'ropsten'
let oracleContractAddress = '0x2DE7E4a9488488e0058B95854CC2f7955B35dC9b'; // FTM-ETH oracle contract address
// Visit https://data.chain.link/ to find options for specific token/asset for oracle contract addresses.
let fetchPriceIndex;
async function getLatestPriceFeed() {
fetchPriceIndex = await new PriceIndexer(networkName, oracleContractAddress, false).assetPrice();
console.log(fetchPriceIndex);
}
getLatestPriceFeed();
3. Fetch Latest Price for any asset from DIA Org
This function returns the value of one asset/cryptocurrency directly via DIA Data APIs. Read more about these APIs here.
- Use this function when you simply want to fetch latest price from DIA Data APIs.
const PriceIndexer = require('price-indexer');
let assetName = 'FTM' // Visit https://docs.diadata.org to find more options for retriving price index of an asset.
let fetchPriceIndex;
async function getLatestPriceFeed() {
fetchPriceIndex = await new PriceIndexer(...[null, null, null], assetName).priceDIAData()
console.log(fetchPriceIndex);
}
getLatestPriceFeed();
4. Fetch Latest Price for any asset from Messari
This function returns the value of one asset/cryptocurrency directly via Messari Data APIs. Read more about these APIs here.
- Use this function when you simply want to fetch latest price from Messari Data APIs.
const PriceIndexer = require('price-indexer');
let assetName = 'FTM' // Visit https://messari.io/api to find more options for retriving price index of an asset.
let fetchPriceIndex;
async function getLatestPriceFeed() {
fetchPriceIndex = await new PriceIndexer(...[null, null, null], assetName).priceMESSARIData()
console.log(fetchPriceIndex);
}
getLatestPriceFeed();