Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/api-reference/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"scripts": {
"build": "next build",
"fix": "pnpm fix:format && pnpm fix:lint",
"fix": "pnpm fix:lint && pnpm fix:format",
"fix:format": "prettier --write .",
"fix:lint": "eslint --fix .",
"pull:env": "VERCEL_ORG_ID=team_BKQrg3JJFLxZyTqpuYtIY0rj VERCEL_PROJECT_ID=prj_gbljYVzp0m5EpCuOF6nZpM4WMFM6 vercel env pull",
Expand Down
53 changes: 33 additions & 20 deletions apps/api-reference/src/apis/evm/get-ema-price-no-older-than.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,41 @@ export const getEmaPriceNoOlderThan = readApi<"id" | "age">({
summary:
"Get the exponentially weighted moving average (EMA) price object with a published timestamp from before than `age` seconds in the past.",
description: `
Get the latest exponentially-weighted moving average (EMA) price and confidence
interval for the requested price feed id. The price feed id is a 32-byte id
written as a hexadecimal string; see the [price feed
ids](https://pyth.network/developers/price-feed-ids) page to look up the id for
a given symbol. The returned price and confidence 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 \`publishTime\` which is the unix timestamp for the
price update. The EMA methodology is described in more detail in this [blog
post](https://pythnetwork.medium.com/whats-in-a-name-302a03e6c3e1).
This method returns the latest price object containing **exponentially-weighted moving average** price for the requested price feed ID, if
it has been updated sufficiently recently.

The caller provides an \`age\` argument that specifies how old the price can be.
The call reverts with a \`StalePriceError\` if the on-chain price is from more
than \`age\` seconds in the past (with respect to the current on-chain
timestamp). Call [updatePriceFeeds](updatePriceFeeds) to pull a fresh price
on-chain and solve this problem.
The caller provides an **\`age\`** argument that specifies how old the price can be.

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, calling
[updatePriceFeeds](updatePriceFeeds) will solve this problem.
The price object contains the following fields:
1. \`price\`: The latest price of the price feed.
2. \`conf\`: The confidence level of the price feed.
3. \`expo\`: The exponent of the price feed.
4. \`publishtime\`: The time when the price feed was last updated.

Sample \`price\` object:
\`\`\`json
{
price: 123456789n,
conf: 180726074n,
expo: -8,
publishTime: 1721765108n
}
\`\`\`

The \`price\` above is in the format of \`price * 10^expo\`. So, the \`price\` in above
mentioned sample represents the number \`123456789 * 10(-8) = 1.23456789\` in
this case.

### Error Response

The above method can return the following error response:
- \`StalePrice\`: The on-chain price has not been updated within the last
[\`getValidTimePeriod()\`](getValidTimePeriod) seconds. Try calling
[\`updatePriceFeeds()\`](updatePriceFeeds) to update the price feed with the
latest price.
- \`PriceFeedNotFound\`: The requested price feed has never received a price
update or does not exist. Try calling
[\`updatePriceFeeds()\`](updatePriceFeeds) to update the price feed.
`,
parameters: [
{
Expand Down
52 changes: 34 additions & 18 deletions apps/api-reference/src/apis/evm/get-ema-price-unsafe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,42 @@ export const getEmaPriceUnsafe = readApi<"id">({
summary:
"Get the **last updated** exponentially weighted moving average (EMA) price object for the requested price feed ID. _Caution: This function may return a price arbitrarily in the past_",
description: `
Get the latest exponentially-weighted moving average (EMA) price and confidence
interval for the requested price feed id. The price feed id is a 32-byte id
written as a hexadecimal string; see the [price feed
ids](https://pyth.network/developers/price-feed-ids) page to look up the id for
a given symbol. The returned price and confidence 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 \`publishTime\` which is the unix timestamp for the
price update. The EMA methodology is described in more detail in this [blog
post](https://pythnetwork.medium.com/whats-in-a-name-302a03e6c3e1).
This method returns the price object containing **last updated** exponentially-weighted moving average(EMA) price for the requested price feed ID.

**This function may return a price from arbitrarily far in the past.** It is the
caller's responsibility to check the returned \`publishTime\` to ensure that the
update is recent enough for their use case.
**This function may return a price from arbitrarily far in the past.** It is the
caller's responsibility to check the returned \`publishTime\` to ensure that the
update is recent enough for their use case. If you need the latest price, update the price using [\`updatePriceFeeds()\`](updatePriceFeeds) and then call [\`getEmaPrice()\`](getEmaPrice).

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, calling
[updatePriceFeeds](updatePriceFeeds) will solve this problem.
The price object contains the following fields:
1. \`price\`: The latest price of the price feed.
2. \`conf\`: The confidence level of the price feed.
3. \`expo\`: The exponent of the price feed.
4. \`publishtime\`: The time when the price feed was last updated.

Sample \`price\` object:
\`\`\`json
{
price: 123456789n,
conf: 180726074n,
expo: -8,
publishTime: 1721765108n
}
\`\`\`

The \`price\` above is in the format of \`price * 10^expo\`. So, the \`price\` in above
mentioned sample represents the number \`123456789 * 10(-8) = 1.23456789\` in
this case.

### Error Response

The above method can return the following error response:
- \`StalePrice\`: The on-chain price has not been updated within the last
[\`getValidTimePeriod()\`](getValidTimePeriod) seconds. Try calling
[\`updatePriceFeeds()\`](updatePriceFeeds) to update the price feed with the
latest price.
- \`PriceFeedNotFound\`: The requested price feed has never received a price
update or does not exist. Try calling
[\`updatePriceFeeds()\`](updatePriceFeeds) to update the price feed.
`,
parameters: [
{
Expand Down
52 changes: 29 additions & 23 deletions apps/api-reference/src/apis/evm/get-ema-price.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,37 @@ export const getEmaPrice = readApi<"id">({
summary:
"Get the **latest** exponentially weighted moving average (EMA) price object for the requested price feed ID.",
description: `
Get the latest exponentially-weighted moving average (EMA) price and confidence
interval for the requested price feed id. The price feed id is a 32-byte id
written as a hexadecimal string; see the [price feed
ids](https://pyth.network/developers/price-feed-ids) page to look up the id for
a given symbol. The returned price and confidence 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 \`publishTime\` which is the unix timestamp for the
price update. The EMA methodology is described in more detail in this [blog
post](https://pythnetwork.medium.com/whats-in-a-name-302a03e6c3e1).
This method returns the latest price object containing **exponentially-weighted moving average** price for the requested price feed ID.
The \`price\` object contains the following fields:
1. \`price\`: The latest **EMA** price of the price feed.
2. \`conf\`: The confidence level of the price feed.
3. \`expo\`: The exponent of the price feed.
4. \`publishtime\`: The time when the price feed was last updated.

This function reverts with a \`StalePrice\` error if the on-chain price has not
been updated within the last [getValidTimePeriod()](getValidTimePeriod) seconds.
The default valid time period is set to a reasonable default on each chain and
is typically around 1 minute. Call [updatePriceFeeds](updatePriceFeeds) to pull
a fresh price on-chain and solve this problem. If you would like to configure
the valid time period, see [getEmaPriceNoOlderThan](getEmaPriceNoOlderThan). If
you want the latest price regardless of when it was updated, see
[getEmaPriceUnsafe](getEmaPriceUnsafe).
Sample price object:
\`\`\`json
{
price: 123456789n,
conf: 180726074n,
expo: -8,
publishTime: 1721765108n
}
\`\`\`

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, calling
[updatePriceFeeds](updatePriceFeeds) will solve this problem.
The \`price\` above is in the format of \`price * 10^expo\`. So, the \`price\` in above
mentioned sample represents the number \`123456789 * 10(-8) = 1.23456789\` in
this case.

### Error Response

The above method can return the following error response:
- \`StalePrice\`: The on-chain price has not been updated within the last
[\`getValidTimePeriod()\`](getValidTimePeriod) seconds. Try calling
[\`updatePriceFeeds()\`](updatePriceFeeds) to update the price feed with the
latest price.
- \`PriceFeedNotFound\`: The requested price feed has never received a price
update or does not exist. Try calling
[\`updatePriceFeeds()\`](updatePriceFeeds) to update the price feed.
`,
parameters: [
{
Expand Down
52 changes: 33 additions & 19 deletions apps/api-reference/src/apis/evm/get-price-no-older-than.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,41 @@ export const getPriceNoOlderThan = readApi<"id" | "age">({
summary:
"Get the price object with a published timestamp from before than `age` seconds in the past.",
description: `
Get the latest price and confidence interval for the requested price feed id, if
it has been updated sufficiently recently. The price feed id is a 32-byte id
written as a hexadecimal string; see the [price feed
ids](https://pyth.network/developers/price-feed-ids) page to look up the id for
a given symbol. The returned price and confidence 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 \`publishTime\` which is the unix timestamp for the
price update.
This method returns the latest price object for the requested price feed ID, if
it has been updated sufficiently recently.

The caller provides an \`age\` argument that specifies how old the price can be.
The call reverts with a \`StalePriceError\` if the on-chain price is from more
than \`age\` seconds in the past (with respect to the current on-chain
timestamp). Call [updatePriceFeeds](updatePriceFeeds) to pull a fresh price
on-chain and solve this problem.
The caller provides an **\`age\`** argument that specifies how old the price can be.

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, calling
[updatePriceFeeds](updatePriceFeeds) will solve this problem.
The price object contains the following fields:
1. \`price\`: The latest price of the price feed.
2. \`conf\`: The confidence level of the price feed.
3. \`expo\`: The exponent of the price feed.
4. \`publishtime\`: The time when the price feed was last updated.

Sample \`price\` object:
\`\`\`json
{
price: 123456789n,
conf: 180726074n,
expo: -8,
publishTime: 1721765108n
}
\`\`\`

The \`price\` above is in the format of \`price * 10^expo\`. So, the \`price\` in above
mentioned sample represents the number \`123456789 * 10(-8) = 1.23456789\` in
this case.

### Error Response

The above method can return the following error response:
- \`StalePrice\`: The on-chain price has not been updated within the last
[\`getValidTimePeriod()\`](getValidTimePeriod) seconds. Try calling
[\`updatePriceFeeds()\`](updatePriceFeeds) to update the price feed with the
latest price.
- \`PriceFeedNotFound\`: The requested price feed has never received a price
update or does not exist. Try calling
[\`updatePriceFeeds()\`](updatePriceFeeds) to update the price feed.
`,
parameters: [
{
Expand Down
52 changes: 35 additions & 17 deletions apps/api-reference/src/apis/evm/get-price-unsafe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,43 @@ export const getPriceUnsafe = readApi<"id">({
summary:
"Get the **last updated** price object for the requested price feed ID. _Caution: This function may return a price from arbitrarily in the the past_",
description: `
Get the latest price and confidence interval for the requested price feed id.
The price feed id is a 32-byte id written as a hexadecimal string; see the
[price feed ids](https://pyth.network/developers/price-feed-ids) page to look up
the id for a given symbol. The returned price and confidence 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 \`publishTime\` which is the unix
timestamp for the price update.
This method returns the price object containing **last updated** price for the requested price feed ID.

**This function may return a price from arbitrarily far in the past.** It is the
caller's responsibility to check the returned \`publishTime\` to ensure that the
update is recent enough for their use case.
**This function may return a price from arbitrarily far in the past.** It is the
caller's responsibility to check the returned \`publishTime\` to ensure that the
update is recent enough for their use case. If you need the latest price, update the price using [\`updatePriceFeeds()\`](updatePriceFeeds) and then call [\`getPrice()\`](getPrice).

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, calling
[updatePriceFeeds](updatePriceFeeds) will solve this problem.
`,
The price object contains the following fields:
1. \`price\`: The latest price of the price feed.
2. \`conf\`: The confidence level of the price feed.
3. \`expo\`: The exponent of the price feed.
4. \`publishtime\`: The time when the price feed was last updated.

Sample \`price\` object:
\`\`\`json
{
price: 123456789n,
conf: 180726074n,
expo: -8,
publishTime: 1721765108n
}
\`\`\`

The \`price\` above is in the format of \`price * 10^expo\`. So, the \`price\` in above
mentioned sample represents the number \`123456789 * 10(-8) = 1.23456789\` in
this case.

### Error Response

The above method can return the following error response:
- \`StalePrice\`: The on-chain price has not been updated within the last
[\`getValidTimePeriod()\`](getValidTimePeriod) seconds. Try calling
[\`updatePriceFeeds()\`](updatePriceFeeds) to update the price feed with the
latest price.
- \`PriceFeedNotFound\`: The requested price feed has never received a price
update or does not exist. Try calling
[\`updatePriceFeeds()\`](updatePriceFeeds) to update the price feed.
`,
parameters: [
{
name: "id",
Expand Down
53 changes: 31 additions & 22 deletions apps/api-reference/src/apis/evm/get-price.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,39 @@ export const getPrice = readApi<"id">({
name: "getPrice",
summary: "Get the **latest** price object for the requested price feed ID.",
description: `
Get the latest price and confidence interval for the requested price feed id.
The price feed id is a 32-byte id written as a hexadecimal string; see the
[price feed ids](https://pyth.network/developers/price-feed-ids) page to look up
the id for a given symbol. The returned price and confidence 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 \`publishTime\` which is the unix
timestamp for the price update.
This method returns the latest price object for the requested price feed ID.

This function reverts with a \`StalePrice\` error if the on-chain price has not
been updated within the last [getValidTimePeriod()](getValidTimePeriod)
seconds. The default valid time period is set to a reasonable default on each
chain and is typically around 1 minute. Call
[updatePriceFeeds](updatePriceFeeds) to pull a fresh price on-chain and solve
this problem. If you would like to configure the valid time period, see
[getPriceNoOlderThan](getPriceNoOlderThan). If you want the latest price
regardless of when it was updated, see [getPriceUnsafe](getPriceUnsafe).
The price object contains the following fields:
1. \`price\`: The latest price of the price feed.
2. \`conf\`: The confidence level of the price feed.
3. \`expo\`: The exponent of the price feed.
4. \`publishtime\`: The time when the price feed was last updated.

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, calling
[updatePriceFeeds](updatePriceFeeds) will solve this problem.
`,
Sample \`price\` object:
\`\`\`json
{
price: 123456789n,
conf: 180726074n,
expo: -8,
publishTime: 1721765108n
}
\`\`\`

The \`price\` above is in the format of \`price * 10^expo\`. So, the \`price\` in above
mentioned sample represents the number \`123456789 * 10(-8) = 1.23456789\` in
this case.

### Error Response

The above method can return the following error response:
- \`StalePrice\`: The on-chain price has not been updated within the last
[\`getValidTimePeriod()\`](getValidTimePeriod) seconds. Try calling
[\`updatePriceFeeds()\`](updatePriceFeeds) to update the price feed with the
latest price.
- \`PriceFeedNotFound\`: The requested price feed has never received a price
update or does not exist. Try calling
[\`updatePriceFeeds()\`](updatePriceFeeds) to update the price feed.
`,
parameters: [
{
name: "id",
Expand Down
Loading