Skip to content

Commit 0692f33

Browse files
committed
fix: fix example
1 parent 31a0959 commit 0692f33

File tree

3 files changed

+42
-33
lines changed

3 files changed

+42
-33
lines changed

lazer/Cargo.lock

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lazer/sdk/rust/sdk/examples/subscribe_price_feeds.rs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
1-
use pyth_lazer_sdk::LazerClient;
2-
use pyth_lazer_protocol::subscription::{Request, SubscribeRequest, SubscriptionId, SubscriptionParams};
31
use futures_util::StreamExt;
2+
use pyth_lazer_protocol::router::{
3+
Chain, Channel, DeliveryFormat, FixedRate, JsonBinaryEncoding, PriceFeedId, PriceFeedProperty,
4+
SubscriptionParams, SubscriptionParamsRepr,
5+
};
6+
use pyth_lazer_protocol::subscription::{Request, SubscribeRequest, SubscriptionId};
7+
use pyth_lazer_sdk::LazerClient;
48

59
#[tokio::main]
610
async fn main() -> anyhow::Result<()> {
7-
// Connect to the Pyth Lazer WebSocket endpoint
8-
let (mut client, mut stream) = LazerClient::start("wss://hermes.pyth.network").await?;
9-
10-
// Subscribe to BTC/USD price feed
11-
let btc_feed_id = "ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace";
12-
13-
client.subscribe(Request::Subscribe(SubscribeRequest {
11+
let (mut client, mut stream) = LazerClient::start("lazer_endpoint").await?;
12+
13+
let subscription_request = SubscribeRequest {
1414
subscription_id: SubscriptionId(1),
15-
params: SubscriptionParams {
16-
ids: vec![btc_feed_id.to_string()],
17-
binary_message_format: true,
18-
},
19-
})).await?;
15+
params: SubscriptionParams::new(SubscriptionParamsRepr {
16+
price_feed_ids: vec![PriceFeedId(1), PriceFeedId(2), PriceFeedId(3)],
17+
properties: vec![PriceFeedProperty::Price],
18+
chains: vec![Chain::Solana],
19+
delivery_format: DeliveryFormat::Binary,
20+
json_binary_encoding: JsonBinaryEncoding::default(),
21+
parsed: false,
22+
channel: Channel::FixedRate(FixedRate::from_ms(200).expect("unsupported update rate")),
23+
})
24+
.expect("invalid subscription params"),
25+
};
26+
27+
client
28+
.subscribe(Request::Subscribe(subscription_request))
29+
.await?;
2030

2131
println!("Subscribed to BTC/USD price feed. Waiting for updates...");
22-
32+
2333
// Process the first 5 updates
2434
let mut count = 0;
2535
while let Some(msg) = stream.next().await {

lazer/sdk/rust/sdk/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ impl LazerClient {
109109

110110
match magic {
111111
EVM_FORMAT_MAGIC => {
112-
evm =
113-
Some(EvmMessage::deserialize_slice(&data[pos..pos + len])?);
112+
evm = Some(EvmMessage::deserialize_slice(&data[pos..pos + len])?);
114113
}
115114
SOLANA_FORMAT_MAGIC_BE => {
116115
solana =

0 commit comments

Comments
 (0)