From e9d650630793e5b4e491358b0789c15328e20062 Mon Sep 17 00:00:00 2001 From: Aditya Arora Date: Thu, 21 Aug 2025 11:33:43 -0400 Subject: [PATCH 1/4] ic --- pages/_meta.json | 5 ----- pages/home/_meta.json | 7 +------ pages/home/index.mdx | 3 +-- 3 files changed, 2 insertions(+), 13 deletions(-) diff --git a/pages/_meta.json b/pages/_meta.json index 78954564..e04bd346 100644 --- a/pages/_meta.json +++ b/pages/_meta.json @@ -14,11 +14,6 @@ "type": "page" }, - "benchmarks": { - "title": "Benchmarks", - "type": "page" - }, - "express-relay": { "title": "Express Relay", "type": "page" diff --git a/pages/home/_meta.json b/pages/home/_meta.json index b67ff895..aaabc837 100644 --- a/pages/home/_meta.json +++ b/pages/home/_meta.json @@ -15,12 +15,7 @@ "title": "Lazer →", "href": "/lazer" }, - - "Benchmarks": { - "title": "Benchmarks →", - "href": "/benchmarks" - }, - + "Express Relay": { "title": "Express Relay →", "href": "/express-relay" diff --git a/pages/home/index.mdx b/pages/home/index.mdx index 49ddcade..62c8d51c 100644 --- a/pages/home/index.mdx +++ b/pages/home/index.mdx @@ -6,10 +6,9 @@ Pyth's market data is contributed by over [120+ first-party publishers](https:// Pyth Network offers several products for developers: -- [Price Feeds](../price-feeds) provide real-time prices for [1500+ assets](https://insights.pyth.network/price-feeds?utm_source=docs) on [100+ blockchain ecosystems](../price-feeds/contract-addresses), including Solana, many EVM chains, +- [Price Feeds](../price-feeds) provide **real-time and historical prices** for [2000+ assets](https://insights.pyth.network/price-feeds?utm_source=docs) on [100+ blockchain ecosystems](../price-feeds/contract-addresses), including Solana, many EVM chains, Aptos, Sui, NEAR, and several Cosmos chains. - [Lazer](../lazer) provides low-latency, highly customizable price feeds on Solana and EVM chains. -- [Benchmarks](../benchmarks) provides historical Pyth prices for both on- and off-chain use. - [Express Relay](../express-relay/) enables protocols to eliminate their MEV while gaining access to active searchers and liquidators. - [Entropy](../entropy) allows developers to generate secure random numbers on the blockchain. From 3d8c6528c3e087bf06238be2ae404d529c4ae2cb Mon Sep 17 00:00:00 2001 From: Aditya Arora Date: Thu, 21 Aug 2025 15:39:21 -0400 Subject: [PATCH 2/4] chore(benchmarks) Move the initial guide to price feeds --- pages/home/_meta.json | 2 +- pages/price-feeds/_meta.json | 1 + pages/price-feeds/api-reference.mdx | 1 + pages/price-feeds/rate-limits.mdx | 6 + pages/price-feeds/use-historic-price-data.mdx | 115 ++++++++++++++++++ 5 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 pages/price-feeds/rate-limits.mdx create mode 100644 pages/price-feeds/use-historic-price-data.mdx diff --git a/pages/home/_meta.json b/pages/home/_meta.json index aaabc837..8ca4ed81 100644 --- a/pages/home/_meta.json +++ b/pages/home/_meta.json @@ -15,7 +15,7 @@ "title": "Lazer →", "href": "/lazer" }, - + "Express Relay": { "title": "Express Relay →", "href": "/express-relay" diff --git a/pages/price-feeds/_meta.json b/pages/price-feeds/_meta.json index 218fcfc5..48c64841 100644 --- a/pages/price-feeds/_meta.json +++ b/pages/price-feeds/_meta.json @@ -24,6 +24,7 @@ }, "use-real-time-data": "Use Real-Time Price Data", + "use-historic-price-data": "Use Historic Price Data", "fetch-price-updates": "Fetch Price Updates", "schedule-price-updates": "Schedule Price Updates", "derive-cross-rate": "Derive Cross Rate", diff --git a/pages/price-feeds/api-reference.mdx b/pages/price-feeds/api-reference.mdx index 7fefe819..29ae3dcf 100644 --- a/pages/price-feeds/api-reference.mdx +++ b/pages/price-feeds/api-reference.mdx @@ -11,3 +11,4 @@ The following on-chain contracts are documented in the API reference: Hermes also has interactive API documentation hosted by the service itself: - [Hermes](https://hermes.pyth.network/docs/) +- [Benchmarks / Historical Prices](https://benchmarks.pyth.network/docs) diff --git a/pages/price-feeds/rate-limits.mdx b/pages/price-feeds/rate-limits.mdx new file mode 100644 index 00000000..7a0c624c --- /dev/null +++ b/pages/price-feeds/rate-limits.mdx @@ -0,0 +1,6 @@ +# Rate Limits + +In order to maximize the reliability of the Pyth Hermes and Benchmarks APIs, a request rate limit is enforced. +All endpoints limits are set at 30 requests every 10 seconds per IP address. + +One exception: the TradingView endpoint will allow 90 requests every 10 seconds. Clients issuing request above the limit will receive a 429 (Too Many Requests) response for the subsequent 60-second period. diff --git a/pages/price-feeds/use-historic-price-data.mdx b/pages/price-feeds/use-historic-price-data.mdx new file mode 100644 index 00000000..944943e7 --- /dev/null +++ b/pages/price-feeds/use-historic-price-data.mdx @@ -0,0 +1,115 @@ +import { Callout, Steps } from "nextra/components"; + +# Use Historic Price Data (Benchmarks) on EVM Chains + +This guide shows you how to integrate **Pyth Benchmarks to access historical price data** for your applications. +The Pyth Benchmarks API is available on all Pythnet chains. + + +This guide uses the term **Benchmarks** to refer to the historical price data service. + + +## Overview + +Pyth Benchmarks allows you to query historical prices at specific points in time. This is useful for: + +- **Contract Settlement**: Use historical prices for options, futures, or other derivative settlements. +- **Backtesting**: Test trading strategies with historical market data. +- **Audit & Compliance**: Verify past prices for regulatory requirements. +- **Analytics**: Analyze price movements and market behavior over time. + +Pyth Benchmarks can be used in two ways to fetch historical prices: + +1. Fetching historical prices from Benchmarks API +2. Verifying historical prices on-chain + + + +### 1. Fetching Historical Prices + +Fetching historical prices from the Benchmarks API is the most straightforward way to get historical prices. +Moreover, [Hermes also extends the Benchmarks API to allow you to fetch historical prices](https://hermes.pyth.network/docs/#/rest/timestamp_price_updates). + +Benchmarks APIs expose two endpoints to fetch historical prices: + +- [`/v1/updates/price/{timestamp}`](https://benchmarks.pyth.network/docs#/): Returns the price for all price feeds passed as query parameters at a given time. +- [`/v1/updates/price/{timestamp}/{interval}`](https://benchmarks.pyth.network/docs#/): Returns the price for the price feed passed as query parameter at a given time and with the specified interval. + + + +Time interval in seconds added to the provided timestamp for the requested price updates. +For example, if the timestamp is 1716400000 and the **interval is 60,** this function will return price updates from time 1716400000 to 1716400060, inclusive of both. **The time interval should not exceed 60 seconds.** + + + + +### Verifying Historical Prices on-chain + +Verifying Historical Prices on-chain is very similar to verifying real-time prices on-chain. +After fetching the price updates in the previous step, you need to pass the price update to the [`parsePriceFeedUpdates`](https://api-reference.pyth.network/price-feeds/evm/parsePriceFeedUpdates) function on the Pyth contract instead of the [`updatePriceFeeds`](https://api-reference.pyth.network/price-feeds/evm/updatePriceFeeds) function. + +```solidity copy +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import "@pythnetwork/pyth-sdk-solidity/IPyth.sol"; +import "@pythnetwork/pyth-sdk-solidity/PythStructs.sol"; + +contract HistoricalPriceConsumer { + IPyth public pyth; + + constructor(address _pyth) { + pyth = IPyth(_pyth); + } + + function settleWithHistoricalPrice( + bytes[] calldata priceUpdate, + uint256 priceId, + uint256 minPublishTime, + uint256 maxPublishTime, + ) external { + // The parsePriceFeedUpdates function requires a fee to be paid. + // The fee is the same as the fee for the updatePriceFeeds function. + uint fee = pyth.getUpdateFee(priceUpdate); + PythStructs.Price memory price = pyth.parsePriceFeedUpdates{value: fee}( + priceUpdate, + priceId, + minPublishTime, + maxPublishTime, + ); + + // Use the historical price for settlement + uint256 settlementPrice = uint256(price.price); + // ... settlement logic + } +} +``` + +The code snippet above does the following things differently from the [verifying real-time prices on-chain](./use-real-time-data.mdx): + +- It calls the `parsePriceFeedUpdates` function instead of the `updatePriceFeeds` function. +- It passes the price id to the `parsePriceFeedUpdates` function as well. The price feed id is needed to identify if the price update belongs to the price feed. +- It passes the **min publish time** and **max publish time** to the `parsePriceFeedUpdates` function. The min publish time and max publish time are the time range of the price update. If the price update is not within the time range, the function will revert with `PriceFeedNotFoundWithinRange`. + +Refer to the [parsePriceFeedUpdates](https://api-reference.pyth.network/price-feeds/evm/parsePriceFeedUpdates) function for more details. + + + + + + +## Additional Resources + +### API Reference + +- [Benchmark API Documentation](https://benchmarks.pyth.network/docs) +- Explore the [Pyth on-chain API documentation](https://api-reference.pyth.network/price-feeds/evm/parsePriceFeedUpdates) to learn more about parsing price updates on EVM chains. + + +### TradingView Integration + +- [TradingView integration](../benchmarks/how-to-create-tradingview-charts) for visualization. + +### Rate Limits + +- Benchmarks API has the same rate limits as the [Hermes API](./rate-limits). From 303b2ad86cd4f72a8174a70e15cf22bc8c8c4e3b Mon Sep 17 00:00:00 2001 From: Aditya Arora Date: Thu, 21 Aug 2025 15:42:09 -0400 Subject: [PATCH 3/4] pre-commiyt --- pages/benchmarks/rate-limits.mdx | 6 ------ pages/price-feeds/use-historic-price-data.mdx | 16 ++++++---------- 2 files changed, 6 insertions(+), 16 deletions(-) delete mode 100644 pages/benchmarks/rate-limits.mdx diff --git a/pages/benchmarks/rate-limits.mdx b/pages/benchmarks/rate-limits.mdx deleted file mode 100644 index 54a12a56..00000000 --- a/pages/benchmarks/rate-limits.mdx +++ /dev/null @@ -1,6 +0,0 @@ -# Rate Limits - -In order to maximize the reliability of the Pyth Benchmarks API, a request rate limit is enforced. -All endpoints limits are set at 30 requests every 10 seconds per IP address. -One exception: the TradingView endpoint will allow 90 requests every 10 seconds. Clients issuing request above the limit will receive a 429 (Too Many Requests) response for the subsequent 60-second period. -Users can access benchmark prices in several different ways, depending on the use case: diff --git a/pages/price-feeds/use-historic-price-data.mdx b/pages/price-feeds/use-historic-price-data.mdx index 944943e7..d8155199 100644 --- a/pages/price-feeds/use-historic-price-data.mdx +++ b/pages/price-feeds/use-historic-price-data.mdx @@ -6,7 +6,8 @@ This guide shows you how to integrate **Pyth Benchmarks to access historical pri The Pyth Benchmarks API is available on all Pythnet chains. -This guide uses the term **Benchmarks** to refer to the historical price data service. + This guide uses the term **Benchmarks** to refer to the historical price data + service. ## Overview @@ -37,12 +38,11 @@ Benchmarks APIs expose two endpoints to fetch historical prices: -Time interval in seconds added to the provided timestamp for the requested price updates. +Time interval in seconds added to the provided timestamp for the requested price updates. For example, if the timestamp is 1716400000 and the **interval is 60,** this function will return price updates from time 1716400000 to 1716400060, inclusive of both. **The time interval should not exceed 60 seconds.** - ### Verifying Historical Prices on-chain Verifying Historical Prices on-chain is very similar to verifying real-time prices on-chain. @@ -57,11 +57,11 @@ import "@pythnetwork/pyth-sdk-solidity/PythStructs.sol"; contract HistoricalPriceConsumer { IPyth public pyth; - + constructor(address _pyth) { pyth = IPyth(_pyth); } - + function settleWithHistoricalPrice( bytes[] calldata priceUpdate, uint256 priceId, @@ -77,7 +77,7 @@ contract HistoricalPriceConsumer { minPublishTime, maxPublishTime, ); - + // Use the historical price for settlement uint256 settlementPrice = uint256(price.price); // ... settlement logic @@ -95,9 +95,6 @@ Refer to the [parsePriceFeedUpdates](https://api-reference.pyth.network/price-fe - - - ## Additional Resources ### API Reference @@ -105,7 +102,6 @@ Refer to the [parsePriceFeedUpdates](https://api-reference.pyth.network/price-fe - [Benchmark API Documentation](https://benchmarks.pyth.network/docs) - Explore the [Pyth on-chain API documentation](https://api-reference.pyth.network/price-feeds/evm/parsePriceFeedUpdates) to learn more about parsing price updates on EVM chains. - ### TradingView Integration - [TradingView integration](../benchmarks/how-to-create-tradingview-charts) for visualization. From 203d14d55e4185ecb98429d9be7d39c0ce674da4 Mon Sep 17 00:00:00 2001 From: Aditya Arora Date: Thu, 21 Aug 2025 17:09:55 -0400 Subject: [PATCH 4/4] added trading-view guide --- pages/benchmarks/_meta.json | 33 ---------------- pages/benchmarks/index.mdx | 38 ------------------- pages/price-feeds/_meta.json | 1 + .../api-instances-and-providers/_meta.json | 1 + .../benchmarks.mdx} | 0 .../create-tradingview-charts.mdx} | 2 +- 6 files changed, 3 insertions(+), 72 deletions(-) delete mode 100644 pages/benchmarks/_meta.json delete mode 100644 pages/benchmarks/index.mdx rename pages/{benchmarks/api-instances.mdx => price-feeds/api-instances-and-providers/benchmarks.mdx} (100%) rename pages/{benchmarks/how-to-create-tradingview-charts.mdx => price-feeds/create-tradingview-charts.mdx} (99%) diff --git a/pages/benchmarks/_meta.json b/pages/benchmarks/_meta.json deleted file mode 100644 index 9f56c639..00000000 --- a/pages/benchmarks/_meta.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "documentation-home": { - "title": "← Documentation Home", - "href": "/home" - }, - - "-- Benchmarks": { - "title": "Benchmarks", - "type": "separator" - }, - "index": "Introduction", - - "-- How-To Guides": { - "title": "How-To Guides", - "type": "separator" - }, - - "how-to-create-tradingview-charts": "Create Charts with TradingView", - - "-- Reference Material": { - "title": "Reference Material", - "type": "separator" - }, - - "benchmarks-api-explorer": { - "title": "Benchmarks API Explorer ↗", - "href": "https://benchmarks.pyth.network/docs/", - "newWindow": true - }, - - "api-instances": "API Instances", - "rate-limits": "Rate Limits" -} diff --git a/pages/benchmarks/index.mdx b/pages/benchmarks/index.mdx deleted file mode 100644 index 16c7cab0..00000000 --- a/pages/benchmarks/index.mdx +++ /dev/null @@ -1,38 +0,0 @@ -# Benchmarks - -Pyth Benchmarks allows users to query a historical archive of prices from [Price Feeds](price-feeds). -For example, applications can retrieve the price of BTC/USD as of last Friday at 8:00 AM UTC. -This price can be used for contract settlement or any other application that requires historical price data. -Benchmarks data is signed and verifiable on-chain with the same trust assumptions as Price Feeds. - -## TradingView Integration - -There is a how-to guide for [integrating Pyth Benchmarks with TradingView](benchmarks/how-to-create-tradingview-charts). - -## Manual Browsing - -The [benchmarks page](https://pyth.network/benchmarks) of the pyth.network website allows users to search the archive of benchmark prices. -It also provides default options for common settlement dates and times. -Users can select a time and see all of the Pyth prices that were active at that time. -Technically, each displayed price corresponds to the Pyth price update published just before the selected time; this ensures that the displayed price is the one a user would have seen if they observed the Pyth price at that time. - -## On-Chain Contracts - -On-chain contracts can consume benchmark prices using the same pull model as [Pythnet Price Feeds](../price-feeds/price-feeds.mdx). -Integrators can follow these three steps: - -1. Use the [Hermes](pythnet-price-feeds/hermes) endpoint `/v2/updates/price/{price_time}` to retrieve a signed price update for the desired price feed and time. - This endpoint will return a signed price update, specifically the price update immediately after the queried time. - This step can be done in either a web frontend or a backend process, depending on who is expected to initiate the transaction. -2. Pass this price update to your on-chain contract as part of the transaction that needs the benchmark data. -3. In your on-chain contract, pass the price update to the `parsePriceFeedUpdates` function on the Pyth contract. - This function will check the validity of the update and return the price of the requested asset (if valid). - The price update will only be valid if the signatures are correct and the update falls within a user-configured time interval; integrators should set this time interval such that it matches their desired time. - -Note that this process is similar to the standard process for consuming pull updates. -The main differences are that users call the `/v2/updates/price/{price_time}` endpoint instead of `/v2/updates/price/latest`, and the on-chain contract calls `parsePriceFeedUpdates` instead of `updatePriceFeeds`. -The pyth-crosschain repo has [example code](https://github.com/pyth-network/pyth-crosschain/blob/main/target_chains/ethereum/sdk/js/src/examples/EvmBenchmark.ts) for an integration along the lines above for EVM chains. - -## API Documentation - -For a detailed overview of the API endpoints and their usage, please refer to the documentation available at [https://benchmarks.pyth.network/docs](https://benchmarks.pyth.network/docs). diff --git a/pages/price-feeds/_meta.json b/pages/price-feeds/_meta.json index 48c64841..8e90c268 100644 --- a/pages/price-feeds/_meta.json +++ b/pages/price-feeds/_meta.json @@ -27,6 +27,7 @@ "use-historic-price-data": "Use Historic Price Data", "fetch-price-updates": "Fetch Price Updates", "schedule-price-updates": "Schedule Price Updates", + "create-tradingview-charts": "Create TradingView Charts", "derive-cross-rate": "Derive Cross Rate", "migrate-an-app-to-pyth": "Migrate an App to Pyth", "use-pyth-for-morpho": "Use Pyth for Morpho Markets", diff --git a/pages/price-feeds/api-instances-and-providers/_meta.json b/pages/price-feeds/api-instances-and-providers/_meta.json index c7c060d6..4182c026 100644 --- a/pages/price-feeds/api-instances-and-providers/_meta.json +++ b/pages/price-feeds/api-instances-and-providers/_meta.json @@ -1,4 +1,5 @@ { "hermes": "Hermes", + "benchmarks": "Benchmarks / Historical Prices", "pythnet-rpc": "Pythnet RPC" } diff --git a/pages/benchmarks/api-instances.mdx b/pages/price-feeds/api-instances-and-providers/benchmarks.mdx similarity index 100% rename from pages/benchmarks/api-instances.mdx rename to pages/price-feeds/api-instances-and-providers/benchmarks.mdx diff --git a/pages/benchmarks/how-to-create-tradingview-charts.mdx b/pages/price-feeds/create-tradingview-charts.mdx similarity index 99% rename from pages/benchmarks/how-to-create-tradingview-charts.mdx rename to pages/price-feeds/create-tradingview-charts.mdx index 84adb650..6a2dcd3d 100644 --- a/pages/benchmarks/how-to-create-tradingview-charts.mdx +++ b/pages/price-feeds/create-tradingview-charts.mdx @@ -1,6 +1,6 @@ import { Tab, Tabs } from "nextra-theme-docs"; -# TradingView Integration +# How to Create TradingView Charts The TradingView integration allows users to view Pyth prices on their own website. All Pyth prices made available through the TradingView integration are originating from [Pythnet](/price-feeds/how-pyth-works/pythnet).