API Reference

parsePriceFeedUpdates

Parse updateData to return prices if the prices are published within the given time range.

Description

This method parse updateData and return the price feeds for the given priceIds within, if they are all published between minPublishTime and maxPublishTime (minPublishTime <= publishTime <= maxPublishTime).

Use this function if you want to use a Pyth price for a fixed time and not the most recent price; otherwise, consider using updatePriceFeeds followed by getPrice or one of its variants.

Unlike updatePriceFeeds, calling this function will not update the on-chain price.

If you need to make sure the price update is the earliest update after the minPublishTime consider using parsePriceFeedUpdatesUnique.

This method requires the caller to pay a fee in wei; the required fee can be computed by calling getUpdateFee with updateData.

Error Response

The above method can return the following error response:

  • PriceFeedNotFoundWithinRange: No price feed was found within the given time range.
  • InvalidUpdateData: The provided update data is invalid or incorrectly signed.
  • InsufficientFee: The fee provided is less than the required fee. Try calling getUpdateFee to get the required fee.

Arguments

  • The price update data for the contract to verify. Fetch this data from Hermes API.

  • The price ids whose feeds will be returned.

  • The minimum timestamp for each returned feed.

  • The maximum timestamp for each returned feed.

  • The update fee in wei. This fee is sent as the value of the transaction.

Examples

import "@pythnetwork/pyth-sdk-solidity/IPyth.sol";
import "@pythnetwork/pyth-sdk-solidity/PythStructs.sol";
//
address contractAddress =
IPyth pyth = IPyth(contractAddress);
bytes[] memory updateData = new bytes[](1);
updateData[0] = /* <updateData> */;
bytes32[] memory priceIds = new bytes32[](1);
priceIds[0] = /* <priceId> */;
uint64 minPublishTime = /* <minPublishTime> */;
uint64 maxPublishTime = /* <maxPublishTime> */;
uint fee = /* <fee> */;
pyth.parsePriceFeedUpdates{value: fee}(updateData, priceIds, minPublishTime, maxPublishTime);