| 
1 |  | -use pyth_lazer_sdk::LazerClient;  | 
2 |  | -use pyth_lazer_protocol::subscription::{Request, SubscribeRequest, SubscriptionId, SubscriptionParams};  | 
3 | 1 | 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;  | 
4 | 8 | 
 
  | 
5 | 9 | #[tokio::main]  | 
6 | 10 | 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 {  | 
14 | 14 |         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?;  | 
20 | 30 | 
 
  | 
21 | 31 |     println!("Subscribed to BTC/USD price feed. Waiting for updates...");  | 
22 |  | -      | 
 | 32 | + | 
23 | 33 |     // Process the first 5 updates  | 
24 | 34 |     let mut count = 0;  | 
25 | 35 |     while let Some(msg) = stream.next().await {  | 
 | 
0 commit comments