Skip to content

Commit 045077b

Browse files
authored
feat(lazer): add history api client for symbols (#3035)
* refactor(lazer): rename PythLazerClient to PythLazerStreamClient * refactor(lazer): rename stream client module * feat(lazer): add history client for fetching symbols * feat(lazer): add symbols stream example, fix channel_capacity handling in client
1 parent eae1d4d commit 045077b

File tree

8 files changed

+519
-28
lines changed

8 files changed

+519
-28
lines changed

Cargo.lock

Lines changed: 31 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lazer/sdk/rust/client/Cargo.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pyth-lazer-client"
3-
version = "6.0.0"
3+
version = "7.0.0"
44
edition = "2021"
55
description = "A Rust client for Pyth Lazer"
66
license = "Apache-2.0"
@@ -15,10 +15,16 @@ serde_json = "1.0"
1515
base64 = "0.22.1"
1616
anyhow = "1.0"
1717
tracing = "0.1"
18-
url = "2.4"
18+
url = { version = "2.4", features = ["serde"] }
1919
derive_more = { version = "1.0.0", features = ["from"] }
2020
backoff = { version = "0.4.0", features = ["futures", "tokio"] }
2121
ttl_cache = "0.5.1"
22+
reqwest = { version = "0.12.23", features = ["json"] }
23+
arc-swap = "1.7.1"
24+
futures = "0.3.31"
25+
humantime-serde = "1.1.1"
26+
fs-err = "3.1.1"
27+
atomicwrites = "0.4.4"
2228

2329

2430
[dev-dependencies]

lazer/sdk/rust/client/examples/subscribe_price_feeds.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::time::Duration;
22

33
use base64::Engine;
44
use pyth_lazer_client::backoff::PythLazerExponentialBackoffBuilder;
5-
use pyth_lazer_client::client::PythLazerClientBuilder;
5+
use pyth_lazer_client::stream_client::PythLazerStreamClientBuilder;
66
use pyth_lazer_client::ws_connection::AnyResponse;
77
use pyth_lazer_protocol::api::{
88
Channel, DeliveryFormat, Format, JsonBinaryEncoding, SubscriptionParams, SubscriptionParamsRepr,
@@ -36,7 +36,7 @@ async fn main() -> anyhow::Result<()> {
3636
.init();
3737

3838
// Create and start the client
39-
let mut client = PythLazerClientBuilder::new(get_lazer_access_token())
39+
let mut client = PythLazerStreamClientBuilder::new(get_lazer_access_token())
4040
// Optionally override the default endpoints
4141
.with_endpoints(vec![
4242
"wss://pyth-lazer-0.dourolabs.app/v1/stream".parse()?,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use std::time::Duration;
2+
3+
use pyth_lazer_client::history_client::{PythLazerHistoryClient, PythLazerHistoryClientConfig};
4+
use pyth_lazer_protocol::PriceFeedId;
5+
use tokio::time::sleep;
6+
use url::Url;
7+
8+
#[tokio::main]
9+
async fn main() -> anyhow::Result<()> {
10+
tracing_subscriber::fmt::init();
11+
let urls = std::env::args()
12+
.skip(1)
13+
.map(|s| Url::parse(&s))
14+
.collect::<Result<Vec<_>, _>>()?;
15+
16+
let client = PythLazerHistoryClient::new(PythLazerHistoryClientConfig {
17+
urls,
18+
update_interval: Duration::from_secs(5),
19+
..Default::default()
20+
});
21+
let symbols = client.all_symbols_metadata_handle().await?;
22+
23+
loop {
24+
println!("symbols len: {}", symbols.symbols().len());
25+
println!("symbol 1: {:?}", symbols.symbols().get(&PriceFeedId(1)));
26+
sleep(Duration::from_secs(15)).await;
27+
}
28+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use std::time::Duration;
2+
3+
use pyth_lazer_client::history_client::{PythLazerHistoryClient, PythLazerHistoryClientConfig};
4+
use pyth_lazer_protocol::PriceFeedId;
5+
use url::Url;
6+
7+
#[tokio::main]
8+
async fn main() -> anyhow::Result<()> {
9+
tracing_subscriber::fmt::init();
10+
let urls = std::env::args()
11+
.skip(1)
12+
.map(|s| Url::parse(&s))
13+
.collect::<Result<Vec<_>, _>>()?;
14+
15+
let client = PythLazerHistoryClient::new(PythLazerHistoryClientConfig {
16+
urls,
17+
update_interval: Duration::from_secs(5),
18+
..Default::default()
19+
});
20+
let mut symbols_stream = client.all_symbols_metadata_stream().await?;
21+
22+
while let Some(symbols) = symbols_stream.recv().await {
23+
println!("symbols len: {}", symbols.len());
24+
println!(
25+
"symbol 1: {:?}",
26+
symbols
27+
.iter()
28+
.find(|feed| feed.pyth_lazer_id == PriceFeedId(1))
29+
);
30+
}
31+
Ok(())
32+
}

0 commit comments

Comments
 (0)