@@ -14,10 +14,10 @@ async fn main() -> anyhow::Result<()> {
1414 "YOUR_ACCESS_TOKEN" ,
1515 ) ?;
1616 let mut stream = client. start ( ) . await ?;
17-
1817 // Create subscription request
18+ let subscription_id = SubscriptionId ( 1 ) ;
1919 let subscription_request = SubscribeRequest {
20- subscription_id : SubscriptionId ( 1 ) ,
20+ subscription_id,
2121 params : SubscriptionParams :: new ( SubscriptionParamsRepr {
2222 price_feed_ids : vec ! [ PriceFeedId ( 1 ) , PriceFeedId ( 2 ) , PriceFeedId ( 3 ) ] ,
2323 properties : vec ! [ PriceFeedProperty :: Price ] ,
@@ -36,25 +36,20 @@ async fn main() -> anyhow::Result<()> {
3636
3737 println ! ( "Subscribed to BTC/USD price feed. Waiting for updates..." ) ;
3838
39- // Process the first 100 updates
39+ // Process the first 50 updates
4040 let mut count = 0 ;
4141 while let Some ( msg) = stream. next ( ) . await {
4242 println ! ( "Received update: {:?}" , msg?) ;
4343 count += 1 ;
44- if count >= 100 {
44+ if count >= 50 {
4545 break ;
4646 }
4747 }
4848
49- // Unsubscribe from all feeds before exiting
50- for feed_id in 1 ..=3 {
51- client. unsubscribe ( SubscriptionId ( feed_id) ) . await ?;
52- println ! ( "Unsubscribed from feed {}" , feed_id) ;
53- // Add a small delay between unsubscribe requests
54- tokio:: time:: sleep ( tokio:: time:: Duration :: from_millis ( 100 ) ) . await ;
55- }
49+ // Unsubscribe before exiting
50+ client. unsubscribe ( subscription_id) . await ?;
51+ println ! ( "Unsubscribed from {:?}" , subscription_id) ;
5652
57- // Wait a moment to ensure unsubscribe messages are sent
5853 tokio:: time:: sleep ( tokio:: time:: Duration :: from_millis ( 500 ) ) . await ;
5954 Ok ( ( ) )
6055}
0 commit comments