-
Notifications
You must be signed in to change notification settings - Fork 35
Lazer doc updates #569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Lazer doc updates #569
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,12 @@ import { Callout, Steps } from "nextra/components"; | |
|
||
# How to Subscribe to Price Updates from Pyth Lazer | ||
|
||
This guide explains how to subscribe to price updates from Pyth Lazer. This guide will also explain various properties and channels that one can use to customize the price updates. | ||
This guide explains how to subscribe to price updates from Pyth Lazer. This guide will also explain various properties and configuration options to customize the price updates. | ||
|
||
Subscribing to price updates is a three-step process: | ||
|
||
1. **Acquire** an access token. | ||
2. **Adjust** subscription parameters. | ||
2. **Configure** subscription parameters. | ||
3. **Subscribe** to the price updates via [websocket API](https://pyth-lazer.dourolabs.app/docs). | ||
|
||
The websocket server is available at `wss://pyth-lazer.dourolabs.app/v1/stream{:bash}`. | ||
|
@@ -20,11 +20,13 @@ Please fill out [this form](https://tally.so/r/nP2lG5) to contact the Pyth team | |
|
||
Use the access token to authenticate the websocket connection by passing it as an `Authorization{:bash}` header with the value `Bearer {token}{:bash}`. | ||
|
||
### 2. Adjust subscription parameters | ||
### 2. Configure subscription parameters | ||
|
||
One can configure the request/subscription parameters to customize the received price updates. A sample request is shown below: | ||
Lazer supports several request/subscription parameters to customize the received price updates. | ||
These parameters are configured by sending a subscription message to the webservice. | ||
A sample request (using the Lazer SDK client -- see step 3) is shown below: | ||
|
||
```js | ||
```js copy | ||
client.send({ | ||
type: "subscribe", | ||
subscriptionId: 1, | ||
|
@@ -35,64 +37,64 @@ client.send({ | |
}); | ||
``` | ||
|
||
Here: | ||
The most significant parameters are: | ||
|
||
- `subscriptionId` is an arbitrary numeric identifier one can choose for a subscription. It will be returned back in response by the server. It doesn not affect the signed payload. | ||
- `priceFeedIds` is the list of price feeds one like to receive. Data for all price feeds will be present in the signed price updates generated. Refer to the [Price Feed IDs list](./price-feed-ids.mdx) for the supported price feeds. | ||
- `properties` is the list of properties one can request, such as **price**, **bestBidPrice**, **bestAskPrice**, etc. | ||
- `chains` is the list of chains for which one need a signed payload, such as **evm**, **solana**, etc. | ||
- `channel` allows to configure the update rate: updates in the **real_time** channel are sent as frequently as possible, while **fixed_rate@200ms** and **fixed_rate@50ms** channels are updated at fixed rates. | ||
- `subscriptionId` is an arbitrary numeric identifier for a subscription. It will be returned back in response by the server. It does not affect the signed payload. | ||
- `priceFeedIds` is the list of price feeds to receive updates for. Data for all price feeds will be present in the signed price updates generated. Refer to the [Price Feed IDs list](./price-feed-ids.mdx) for the supported price feeds. | ||
- `properties` is the list of properties to retrieve, such as **price**, **bestBidPrice**, **bestAskPrice**, etc. | ||
- `chains` is the list of chains to receive a signed payload for, such as **evm**, **solana**, etc. | ||
- `channel` determines the update rate: updates in the **real_time** channel are sent as frequently as possible, while **fixed_rate@200ms** and **fixed_rate@50ms** channels are updated at fixed rates. | ||
|
||
There are also a few other parameters one may use. Refer to the [API documentation](https://pyth-lazer.dourolabs.app/docs) for more details. | ||
There are also a few other configuration parameters -- see the [API documentation](https://pyth-lazer.dourolabs.app/docs) for more details. | ||
|
||
Determine the most suitable values for your application -- they will be used in the next step. | ||
|
||
### 3. Subscribe to the price updates | ||
|
||
To subscribe to the price updates, one needs to send the request to the websocket server. The server will respond with a signed price update. | ||
To subscribe to the price updates, send a request to the websocket server. The server will respond with a signed price update. | ||
|
||
1. Pyth Lazer provides a [SDK](https://github.com/pyth-network/pyth-crosschain/tree/main/lazer/sdk/js) to seamlessly integrate the websocket API into your application. | ||
It can be installed using the following command: | ||
1. Pyth Lazer provides an [SDK](https://github.com/pyth-network/pyth-crosschain/tree/main/lazer/sdk/js) to seamlessly integrate the websocket API into your application. | ||
Install it using the following command: | ||
|
||
```bash | ||
```bash copy | ||
npm install --save @pythnetwork/pyth-lazer-sdk | ||
``` | ||
|
||
2. Then create a [`PythLazerClient`](https://github.com/pyth-network/pyth-crosschain/blob/main/lazer/sdk/js/src/client.ts#L32) object using the URL and the access token requested from the Pyth team in the first step. | ||
2. Then create a [`PythLazerClient`](https://github.com/pyth-network/pyth-crosschain/blob/main/lazer/sdk/js/src/client.ts#L32) object using the URL and the access token requested from the Pyth team in the first step: | ||
|
||
```js | ||
```js copy | ||
import { PythLazerClient } from "@pythnetwork/pyth-lazer-sdk"; | ||
|
||
const client = new PythLazerClient( | ||
"wss://pyth-lazer.dourolabs.app/v1/stream", | ||
"ctoken1" | ||
const client = await PythLazerClient.create( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it looks like the SDK interface changed since this was written (by the way the example is wrong now as well) |
||
["wss://pyth-lazer.dourolabs.app/v1/stream"], | ||
"YOUR_ACCESS_TOKEN" | ||
); | ||
``` | ||
|
||
3. After the client is created, one can adjust the subscription parameters and subscribe to the price updates. | ||
|
||
```js | ||
client.ws.addEventListener("open", () => { | ||
client.send({ | ||
type: "subscribe", | ||
subscriptionId: 1, | ||
priceFeedIds: [1, 2], | ||
properties: ["price"], | ||
chains: ["solana"], | ||
channel: "fixed_rate@200ms", | ||
}); | ||
3. After the client is created, subscribe to updates (using the configuration parameters from step 2): | ||
|
||
```js copy | ||
client.subscribe({ | ||
type: "subscribe", | ||
subscriptionId: 1, | ||
priceFeedIds: [1, 2], | ||
properties: ["price"], | ||
chains: ["solana"], | ||
channel: "fixed_rate@200ms", | ||
}); | ||
``` | ||
|
||
4. One the connection is established, the server will start sending the price updates to the client. | ||
4. Once the connection is established, the server will start sending the price updates to the client: | ||
|
||
```js | ||
```js copy | ||
client.addMessageListener((message) => { | ||
console.log(message); | ||
}); | ||
``` | ||
|
||
By default, price updates contain the `parsed` field that one can use to easily interpret the price update in their backend or frontend, as well as `evm` and/or `solana` fields that contain data that one should include in the on-chain transaction: | ||
|
||
```json | ||
```json copy | ||
{ | ||
"type": "streamUpdated", | ||
"subscriptionId": 1, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the "one" wording in this doc was weird. I made everything imperative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I tried not to use personal "You" and "your" initially.