You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# How to Subscribe to Price Updates from Pyth Lazer
4
4
5
-
Pyth Lazer provides a [websocket API (TODO: Prod)](https://pyth-lazer-staging.dourolabs.app/docs)to fetch price updates.
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.
6
6
7
-
This guide explains how to **fetch** price updates, explore various **properties** of these updates, and configure the channel for **update frequency**. (TODO: Rewrite maybe)
8
-
9
-
Fetching price updates is a three-step process:
7
+
Subscribing to price updates is a three-step process:
10
8
11
9
1.**Acquire** an access token.
12
10
2.**Adjust** subscription parameters.
13
-
3.**Subscribe** to the price updates via websocket API.
11
+
3.**Subscribe** to the price updates via [websocket API](https://pyth-lazer-staging.dourolabs.app/docs).
14
12
15
-
The websocket server is available at `wss://pyth-lazer-staging.dourolabs.app/v1/stream`.
16
-
TODO: Add the prod URL.
13
+
The websocket server is available at `wss://pyth-lazer-staging.dourolabs.app/v1/stream{:bash}`.
17
14
18
15
<Steps>
19
16
20
17
### 1. Acquire an access token
21
18
22
19
Please fill out [this form](https://tally.so/r/nP2lG5) to contact the Pyth team and get the access token.
23
20
24
-
Use the access token to authenticate the websocket connection as a`Bearer {token}{:bash}`.
21
+
Use the access token to authenticate the websocket connection by passing it as an `Authorization{:bash}` header with the value`Bearer {token}{:bash}`.
25
22
26
23
### 2. Adjust subscription parameters
27
24
28
25
One can configure the request/subscription parameters to customize the received price updates. A sample request is shown below:
29
26
30
-
```json
31
-
client.send({
32
-
type: "subscribe",
33
-
subscriptionId: 1,
34
-
priceFeedIds: [1, 2],
35
-
properties: ["price"],
36
-
chains: ["solana"],
37
-
channel: "fixed_rate@200ms",
38
-
});
27
+
```js
28
+
client.send({
29
+
type:"subscribe",
30
+
subscriptionId:1,
31
+
priceFeedIds: [1, 2],
32
+
properties: ["price"],
33
+
chains: ["solana"],
34
+
channel:"fixed_rate@200ms",
35
+
});
39
36
```
40
37
41
38
Here:
42
39
43
-
-`subscriptionId` is an arbitrary numeric identifier one can choose for a subscription. It will eb returned back in response by the server. It doesn not affect the signed payload.
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.
44
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-feeds.mdx) for the supported price feeds.
45
-
-`properties` is the list of properties one can request, such as **price**, **bestBidPrice**, **bestAskPrice**, etc. TODO: Find more properties.
42
+
-`properties` is the list of properties one can request, such as **price**, **bestBidPrice**, **bestAskPrice**, etc.
46
43
-`chains` is the list of chains for which one need a signed payload, such as **evm**, **solana**, etc.
47
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.
48
45
@@ -53,7 +50,7 @@ There are also a few other parameters one may use. Refer to the [API documentati
53
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
51
55
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.
By default, price updates contain the `parsed` field that one can use to easily interpret the 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:
93
+
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:
97
94
98
95
```json
99
96
{
@@ -120,3 +117,17 @@ By default, price updates contain the `parsed` field that one can use to easily
120
117
```
121
118
122
119
</Steps>
120
+
121
+
122
+
123
+
## Additional Resources
124
+
125
+
You may find these additional resources helpful for subscribing to price updates from Pyth Lazer.
126
+
127
+
### Price Feed IDs
128
+
129
+
Pyth Lazer supports a wide range of price feeds. Consult the [Price Feed IDs](../price-feeds.mdx) page for a complete list of supported price feeds.
130
+
131
+
### Examples
132
+
133
+
[pyth-lazer-example-js](https://github.com/pyth-network/pyth-examples/tree/main/lazer/js) is a simple example for subscribing to the Pyth Lazer websocket.
0 commit comments