parsePriceFeedUpdatesUnique
Parse updateData
to return the first updated 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 the first updates published between minPublishTime
and
maxPublishTime
That is to say, if prevPublishTime < minPublishTime <= publishTime <= maxPublishTime
where prevPublishTime
is
the publish time of the previous update for the given price feed.
These updates are unique per priceId
and minPublishTime
. This will guarantee no
updates exist for the given priceIds
earlier than the returned updates and
still in the given time range. If you do not need the uniqueness guarantee,
consider using parsePriceFeedUpdates instead.
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 getPriceNoOlderThan or one of its variants.
Unlike updatePriceFeeds, calling this function will not update the on-chain price.
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.parsePriceFeedUpdatesUnique{value: fee}(updateData, priceIds, minPublishTime, maxPublishTime);