Skip to content

Commit

Permalink
fix: example
Browse files Browse the repository at this point in the history
  • Loading branch information
tejasbadadare committed Jan 30, 2025
1 parent c9f700b commit f71d95a
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions lazer/sdk/rust/client/examples/subscribe_price_feeds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ async fn main() -> anyhow::Result<()> {
"YOUR_ACCESS_TOKEN",
)?;
let mut stream = client.start().await?;

// Create subscription request
let subscription_id = SubscriptionId(1);
let subscription_request = SubscribeRequest {
subscription_id: SubscriptionId(1),
subscription_id,
params: SubscriptionParams::new(SubscriptionParamsRepr {
price_feed_ids: vec![PriceFeedId(1), PriceFeedId(2), PriceFeedId(3)],
properties: vec![PriceFeedProperty::Price],
Expand All @@ -36,25 +36,20 @@ async fn main() -> anyhow::Result<()> {

println!("Subscribed to BTC/USD price feed. Waiting for updates...");

// Process the first 100 updates
// Process the first 50 updates
let mut count = 0;
while let Some(msg) = stream.next().await {
println!("Received update: {:?}", msg?);
count += 1;
if count >= 100 {
if count >= 50 {
break;
}
}

// Unsubscribe from all feeds before exiting
for feed_id in 1..=3 {
client.unsubscribe(SubscriptionId(feed_id)).await?;
println!("Unsubscribed from feed {}", feed_id);
// Add a small delay between unsubscribe requests
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
}
// Unsubscribe before exiting
client.unsubscribe(subscription_id).await?;
println!("Unsubscribed from {:?}", subscription_id);

// Wait a moment to ensure unsubscribe messages are sent
tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
Ok(())
}

0 comments on commit f71d95a

Please sign in to comment.