Skip to content

Commit 0eb047c

Browse files
committed
lazer doc updates
1 parent edc19d7 commit 0eb047c

File tree

2 files changed

+39
-37
lines changed

2 files changed

+39
-37
lines changed

pages/lazer/integrate-as-consumer/svm.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Integrating with Pyth Lazer in smart contracts as a consumer is a three-step pro
1212

1313
<Steps>
1414

15-
### Use Pyth Lazer SDK into smart contracts
15+
### Use Pyth Lazer SDK in smart contracts
1616

1717
Pyth Lazer provides a [Solana SDK](https://docs.rs/pyth-lazer-solana-contract/latest/pyth_lazer_solana_contract/), which allows consumers to parse and verify the price updates on Solana-compatible chains.
1818

pages/lazer/subscribe-price-updates.mdx

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { Callout, Steps } from "nextra/components";
22

33
# How to Subscribe to Price Updates from Pyth Lazer
44

5-
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.
5+
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.
66

77
Subscribing to price updates is a three-step process:
88

99
1. **Acquire** an access token.
10-
2. **Adjust** subscription parameters.
10+
2. **Configure** subscription parameters.
1111
3. **Subscribe** to the price updates via [websocket API](https://pyth-lazer.dourolabs.app/docs).
1212

1313
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
2020

2121
Use the access token to authenticate the websocket connection by passing it as an `Authorization{:bash}` header with the value `Bearer {token}{:bash}`.
2222

23-
### 2. Adjust subscription parameters
23+
### 2. Configure subscription parameters
2424

25-
One can configure the request/subscription parameters to customize the received price updates. A sample request is shown below:
25+
Lazer supports several request/subscription parameters to customize the received price updates.
26+
These parameters are configured by sending a subscription message to the webservice.
27+
A sample request (using the Lazer SDK client -- see step 3) is shown below:
2628

27-
```js
29+
```js copy
2830
client.send({
2931
type: "subscribe",
3032
subscriptionId: 1,
@@ -35,64 +37,64 @@ client.send({
3537
});
3638
```
3739

38-
Here:
40+
The most significant parameters are:
3941

40-
- `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.
41-
- `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.
42-
- `properties` is the list of properties one can request, such as **price**, **bestBidPrice**, **bestAskPrice**, etc.
43-
- `chains` is the list of chains for which one need a signed payload, such as **evm**, **solana**, etc.
44-
- `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.
42+
- `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.
43+
- `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.
44+
- `properties` is the list of properties to retrieve, such as **price**, **bestBidPrice**, **bestAskPrice**, etc.
45+
- `chains` is the list of chains to receive a signed payload for, such as **evm**, **solana**, etc.
46+
- `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.
4547

46-
There are also a few other parameters one may use. Refer to the [API documentation](https://pyth-lazer.dourolabs.app/docs) for more details.
48+
There are also a few other configuration parameters -- see the [API documentation](https://pyth-lazer.dourolabs.app/docs) for more details.
49+
50+
Determine the most suitable values for your application -- they will be used in the next step.
4751

4852
### 3. Subscribe to the price updates
4953

50-
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.
54+
To subscribe to the price updates, send a request to the websocket server. The server will respond with a signed price update.
5155

52-
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.
53-
It can be installed using the following command:
56+
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.
57+
Install it using the following command:
5458

55-
```bash
59+
```bash copy
5660
npm install --save @pythnetwork/pyth-lazer-sdk
5761
```
5862

59-
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.
63+
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:
6064

61-
```js
65+
```js copy
6266
import { PythLazerClient } from "@pythnetwork/pyth-lazer-sdk";
6367

64-
const client = new PythLazerClient(
65-
"wss://pyth-lazer.dourolabs.app/v1/stream",
66-
"ctoken1"
68+
const client = await PythLazerClient.create(
69+
["wss://pyth-lazer.dourolabs.app/v1/stream"],
70+
"YOUR_ACCESS_TOKEN"
6771
);
6872
```
6973

70-
3. After the client is created, one can adjust the subscription parameters and subscribe to the price updates.
71-
72-
```js
73-
client.ws.addEventListener("open", () => {
74-
client.send({
75-
type: "subscribe",
76-
subscriptionId: 1,
77-
priceFeedIds: [1, 2],
78-
properties: ["price"],
79-
chains: ["solana"],
80-
channel: "fixed_rate@200ms",
81-
});
74+
3. After the client is created, subscribe to updates (using the configuration parameters from step 2):
75+
76+
```js copy
77+
client.subscribe({
78+
type: "subscribe",
79+
subscriptionId: 1,
80+
priceFeedIds: [1, 2],
81+
properties: ["price"],
82+
chains: ["solana"],
83+
channel: "fixed_rate@200ms",
8284
});
8385
```
8486

85-
4. One the connection is established, the server will start sending the price updates to the client.
87+
4. Once the connection is established, the server will start sending the price updates to the client:
8688

87-
```js
89+
```js copy
8890
client.addMessageListener((message) => {
8991
console.log(message);
9092
});
9193
```
9294

9395
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:
9496

95-
```json
97+
```json copy
9698
{
9799
"type": "streamUpdated",
98100
"subscriptionId": 1,

0 commit comments

Comments
 (0)