symbols.rs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. use {pyth_lazer_client::arc_swap::StreamIntoAutoUpdatedHandle, std::time::Duration};
  2. use pyth_lazer_client::history_client::{PythLazerHistoryClient, PythLazerHistoryClientConfig};
  3. use pyth_lazer_protocol::PriceFeedId;
  4. use tokio::time::sleep;
  5. use url::Url;
  6. #[tokio::main]
  7. async fn main() -> anyhow::Result<()> {
  8. tracing_subscriber::fmt::init();
  9. let urls = std::env::args()
  10. .skip(1)
  11. .map(|s| Url::parse(&s))
  12. .collect::<Result<Vec<_>, _>>()?;
  13. let client = PythLazerHistoryClient::new(PythLazerHistoryClientConfig {
  14. urls,
  15. update_interval: Duration::from_secs(5),
  16. ..Default::default()
  17. });
  18. let symbols = client
  19. .all_symbols_metadata_stream()
  20. .await?
  21. .into_auto_updated_handle()
  22. .await?;
  23. loop {
  24. println!("symbols len: {}", symbols.load().len());
  25. println!(
  26. "symbol 1: {:?}",
  27. symbols
  28. .load()
  29. .iter()
  30. .find(|feed| feed.pyth_lazer_id == PriceFeedId(1))
  31. );
  32. sleep(Duration::from_secs(15)).await;
  33. }
  34. }