Price Feeds
PriceFeed

Price Feed

Get the latest value for the requested price feed id, including the current price, confidence interval and EMA. The price feed id is a 32-byte id written as a hexadecimal string; see the price feed ids (opens in a new tab) page to look up the id for a given symbol. The returned prices and confidence intervals are decimal numbers written in the form a * 10^e, where e is an exponent included in the result. For example, a price of 1234 with an exponent of -2 represents the number 12.34. The result also includes a publish_time which is the unix timestamp for the price update.

This query may return a price from arbitrarily far in the past. It is the caller's responsibility to check the returned publish_time to ensure that the update is recent enough for their use case. The pyth_sdk_cw crate includes some convenience methods (opens in a new tab) for performing these checks.

This function reverts with a PriceFeedNotFound error if the requested feed id has never received a price update. This error could either mean that the provided price feed id is incorrect, or (more typically) that this is the first attempted use of that feed on-chain. In the second case, executing UpdatePriceFeeds will solve this problem.

ArgumentInputDescription

id*

hex

The ID of the price feed you want to read
Examples

Example Code

use pyth_sdk_cw::{
  query_price_feed,
  PriceFeed,
  PriceFeedResponse,
  PriceIdentifier,
};
use cosmwasm_std::{
  Addr,
  Deps,
};
 
fn example_function(deps: &Deps) -> () {
  let price_feed_response: PriceFeedResponse = query_price_feed(
    &deps.querier,
    Addr::unchecked("neutron1m2emc93m9gpwgsrsf2vylv9xvgqh654630v7dfrhrkmr5slly53spg85wv"),
    PriceIdentifier::from_hex("<id>").unwrap()
  ).unwrap();
  // PriceFeed has many convenience methods for working with Pyth Network prices
  let price_feed: PriceFeed = price_feed_response.price_feed;
}
Last updated on