Gets an asset's price from the Compound Protocol open price feed. The price
of the asset can be returned in any other supported asset value, including
all cTokens and underlyings.
example
const compound = new Compound(window.ethereum);
let price;
(asyncfunction () {
price = await compound.getPrice(Compound.WBTC);
console.log('WBTC in USD', price); // 6 decimals, see Open Price Feed docs
price = await compound.getPrice(Compound.BAT, Compound.USDC); // supports cTokens tooconsole.log('BAT in USDC', price);
})().catch(console.error);
Parameters
asset: string
A string of a supported asset in which to find the
current price.
Default value inAsset: string = constants.USDC
Returns Promise<any>
Returns a string of the numeric value of the asset.
Gets an asset's price from the Compound Protocol open price feed. The price of the asset can be returned in any other supported asset value, including all cTokens and underlyings.
const compound = new Compound(window.ethereum); let price; (async function () { price = await compound.getPrice(Compound.WBTC); console.log('WBTC in USD', price); // 6 decimals, see Open Price Feed docs price = await compound.getPrice(Compound.BAT, Compound.USDC); // supports cTokens too console.log('BAT in USDC', price); })().catch(console.error);