Skip to content
Closed
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
121 changes: 121 additions & 0 deletions lazer/Cargo.lock

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

1 change: 1 addition & 0 deletions lazer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
resolver = "2"
members = [
"sdk/rust/protocol",
"sdk/rust/consumer",
"contracts/solana/programs/pyth-lazer-solana-contract",
]

Expand Down
19 changes: 19 additions & 0 deletions lazer/sdk/rust/consumer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "pyth-lazer-consumer"
version = "0.1.0"
edition = "2021"
description = "Rust consumer SDK for Pyth Lazer"
license = "Apache-2.0"

[dependencies]
tokio = { version = "1", features = ["rt-multi-thread", "macros", "time", "sync"] }
tokio-tungstenite = { version = "0.20", features = ["native-tls"] }
futures-util = "0.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
anyhow = "1.0"
tracing = "0.1"
http = "0.2"
rand = { version = "0.8", features = ["std"] }
ttl_cache = "0.5"
pyth-lazer-protocol = { path = "../protocol" }
49 changes: 49 additions & 0 deletions lazer/sdk/rust/consumer/examples/basic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use {
anyhow::Result,
pyth_lazer_consumer::{
Chain, DeliveryFormat, PriceFeedId, PriceFeedProperty, PythLazerConsumer, Response,
},
};

#[tokio::main]
async fn main() -> Result<()> {
let mut consumer = PythLazerConsumer::new(
vec!["wss://endpoint.pyth.network".to_string()],
"your_token_here".to_string(),
)
.await?;

// Connect to the WebSocket server
consumer.connect().await?;

// Subscribe to some price feeds
consumer
.subscribe(
1, // subscription_id
vec![PriceFeedId(1)],
Some(vec![PriceFeedProperty::Price, PriceFeedProperty::Exponent]),
Some(vec![Chain::Evm]),
Some(DeliveryFormat::Json),
)
.await?;

// Receive updates
let mut rx = consumer.subscribe_to_updates();
while let Ok(update) = rx.recv().await {
if let Response::StreamUpdated(update) = update {
println!(
"Received update for subscription {}",
update.subscription_id.0
);
if let Some(parsed) = update.payload.parsed {
for feed in parsed.price_feeds {
println!(" Feed ID: {:?}", feed.price_feed_id);
println!(" Price: {:?}", feed.price);
println!(" Exponent: {:?}", feed.exponent);
}
}
}
}

Ok(())
}
Loading
Loading