Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions lazer/sdk/rust/client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pyth-lazer-client"
version = "6.0.0"
version = "7.0.0"
edition = "2021"
description = "A Rust client for Pyth Lazer"
license = "Apache-2.0"
Expand All @@ -15,10 +15,16 @@ serde_json = "1.0"
base64 = "0.22.1"
anyhow = "1.0"
tracing = "0.1"
url = "2.4"
url = { version = "2.4", features = ["serde"] }
derive_more = { version = "1.0.0", features = ["from"] }
backoff = { version = "0.4.0", features = ["futures", "tokio"] }
ttl_cache = "0.5.1"
reqwest = { version = "0.12.23", features = ["json"] }
arc-swap = "1.7.1"
futures = "0.3.31"
humantime-serde = "1.1.1"
fs-err = "3.1.1"
atomicwrites = "0.4.4"


[dev-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions lazer/sdk/rust/client/examples/subscribe_price_feeds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::time::Duration;

use base64::Engine;
use pyth_lazer_client::backoff::PythLazerExponentialBackoffBuilder;
use pyth_lazer_client::client::PythLazerClientBuilder;
use pyth_lazer_client::stream_client::PythLazerStreamClientBuilder;
use pyth_lazer_client::ws_connection::AnyResponse;
use pyth_lazer_protocol::api::{
Channel, DeliveryFormat, Format, JsonBinaryEncoding, SubscriptionParams, SubscriptionParamsRepr,
Expand Down Expand Up @@ -36,7 +36,7 @@ async fn main() -> anyhow::Result<()> {
.init();

// Create and start the client
let mut client = PythLazerClientBuilder::new(get_lazer_access_token())
let mut client = PythLazerStreamClientBuilder::new(get_lazer_access_token())
// Optionally override the default endpoints
.with_endpoints(vec![
"wss://pyth-lazer-0.dourolabs.app/v1/stream".parse()?,
Expand Down
28 changes: 28 additions & 0 deletions lazer/sdk/rust/client/examples/symbols.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use std::time::Duration;

use pyth_lazer_client::history_client::{PythLazerHistoryClient, PythLazerHistoryClientConfig};
use pyth_lazer_protocol::PriceFeedId;
use tokio::time::sleep;
use url::Url;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt::init();
let urls = std::env::args()
.skip(1)
.map(|s| Url::parse(&s))
.collect::<Result<Vec<_>, _>>()?;

let client = PythLazerHistoryClient::new(PythLazerHistoryClientConfig {
urls,
update_interval: Duration::from_secs(5),
..Default::default()
});
let symbols = client.all_symbols_metadata_handle().await?;

loop {
println!("symbols len: {}", symbols.symbols().len());
println!("symbol 1: {:?}", symbols.symbols().get(&PriceFeedId(1)));
sleep(Duration::from_secs(15)).await;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to have an example for stream too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

}
32 changes: 32 additions & 0 deletions lazer/sdk/rust/client/examples/symbols_stream.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use std::time::Duration;

use pyth_lazer_client::history_client::{PythLazerHistoryClient, PythLazerHistoryClientConfig};
use pyth_lazer_protocol::PriceFeedId;
use url::Url;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt::init();
let urls = std::env::args()
.skip(1)
.map(|s| Url::parse(&s))
.collect::<Result<Vec<_>, _>>()?;

let client = PythLazerHistoryClient::new(PythLazerHistoryClientConfig {
urls,
update_interval: Duration::from_secs(5),
..Default::default()
});
let mut symbols_stream = client.all_symbols_metadata_stream().await?;

while let Some(symbols) = symbols_stream.recv().await {
println!("symbols len: {}", symbols.len());
println!(
"symbol 1: {:?}",
symbols
.iter()
.find(|feed| feed.pyth_lazer_id == PriceFeedId(1))
);
}
Ok(())
}
Loading