Skip to content

Commit b6f780a

Browse files
committed
feat(pyth-lazer-protocol)!: add optional symbols to request structs, make ids optional
1 parent b57e6a2 commit b6f780a

File tree

4 files changed

+46
-17
lines changed

4 files changed

+46
-17
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pyth-lazer-client"
3-
version = "7.0.0"
3+
version = "8.0.0"
44
edition = "2021"
55
description = "A Rust client for Pyth Lazer"
66
license = "Apache-2.0"

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ async fn main() -> anyhow::Result<()> {
5656
pin!(stream);
5757

5858
let subscription_requests = vec![
59-
// Example subscription: Parsed JSON feed targeting Solana
59+
// Example subscription: Parsed JSON feed targeting Solana, specified by price feed ids
6060
SubscribeRequest {
6161
subscription_id: SubscriptionId(1),
6262
params: SubscriptionParams::new(SubscriptionParamsRepr {
63-
price_feed_ids: vec![PriceFeedId(1), PriceFeedId(2)],
63+
price_feed_ids: Some(vec![PriceFeedId(1), PriceFeedId(2)]),
64+
symbols: None,
6465
properties: vec![
6566
PriceFeedProperty::Price,
6667
PriceFeedProperty::Exponent,
@@ -72,15 +73,20 @@ async fn main() -> anyhow::Result<()> {
7273
json_binary_encoding: JsonBinaryEncoding::Base64,
7374
parsed: true,
7475
channel: Channel::FixedRate(FixedRate::RATE_200_MS),
75-
ignore_invalid_feed_ids: false,
76+
ignore_invalid_feeds: false,
7677
})
7778
.expect("invalid subscription params"),
7879
},
79-
// Example subscription: binary feed targeting Solana and EVM
80+
// Example subscription: binary feed targeting Solana and EVM, specified by price feed symbols
8081
SubscribeRequest {
8182
subscription_id: SubscriptionId(2),
8283
params: SubscriptionParams::new(SubscriptionParamsRepr {
83-
price_feed_ids: vec![PriceFeedId(3), PriceFeedId(4)],
84+
price_feed_ids: None,
85+
symbols: Some(vec![
86+
"Crypto.BTC/USD".to_string(),
87+
"Crypto.ETH/USD".to_string(),
88+
"Crypto.PYTH/USD".to_string(),
89+
]),
8490
properties: vec![
8591
PriceFeedProperty::Price,
8692
PriceFeedProperty::Exponent,
@@ -92,7 +98,7 @@ async fn main() -> anyhow::Result<()> {
9298
json_binary_encoding: JsonBinaryEncoding::Base64,
9399
parsed: false,
94100
channel: Channel::FixedRate(FixedRate::RATE_50_MS),
95-
ignore_invalid_feed_ids: false,
101+
ignore_invalid_feeds: false,
96102
})
97103
.expect("invalid subscription params"),
98104
},

lazer/sdk/rust/protocol/src/api.rs

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ use crate::{
1717
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
1818
#[serde(rename_all = "camelCase")]
1919
pub struct LatestPriceRequest {
20-
pub price_feed_ids: Vec<PriceFeedId>,
20+
pub price_feed_ids: Option<Vec<PriceFeedId>>,
21+
pub symbols: Option<Vec<String>>,
2122
pub properties: Vec<PriceFeedProperty>,
2223
// "chains" was renamed to "formats". "chains" is still supported for compatibility.
2324
#[serde(alias = "chains")]
@@ -35,7 +36,9 @@ pub struct LatestPriceRequest {
3536
#[serde(rename_all = "camelCase")]
3637
pub struct PriceRequest {
3738
pub timestamp: TimestampUs,
38-
pub price_feed_ids: Vec<PriceFeedId>,
39+
// Either price feed ids or symbols must be specified.
40+
pub price_feed_ids: Option<Vec<PriceFeedId>>,
41+
pub symbols: Option<Vec<String>>,
3942
pub properties: Vec<PriceFeedProperty>,
4043
pub formats: Vec<Format>,
4144
#[serde(default)]
@@ -181,7 +184,9 @@ impl<'de> Deserialize<'de> for Channel {
181184
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
182185
#[serde(rename_all = "camelCase")]
183186
pub struct SubscriptionParamsRepr {
184-
pub price_feed_ids: Vec<PriceFeedId>,
187+
// Either price feed ids or symbols must be specified.
188+
pub price_feed_ids: Option<Vec<PriceFeedId>>,
189+
pub symbols: Option<Vec<String>>,
185190
pub properties: Vec<PriceFeedProperty>,
186191
// "chains" was renamed to "formats". "chains" is still supported for compatibility.
187192
#[serde(alias = "chains")]
@@ -195,8 +200,9 @@ pub struct SubscriptionParamsRepr {
195200
#[serde(default = "default_parsed")]
196201
pub parsed: bool,
197202
pub channel: Channel,
198-
#[serde(default)]
199-
pub ignore_invalid_feed_ids: bool,
203+
// "ignoreInvalidFeedIds" was renamed to "ignoreInvalidFeeds". "ignoreInvalidFeedIds" is still supported for compatibility.
204+
#[serde(default, alias = "ignoreInvalidFeedIds")]
205+
pub ignore_invalid_feeds: bool,
200206
}
201207

202208
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize)]
@@ -215,12 +221,28 @@ impl<'de> Deserialize<'de> for SubscriptionParams {
215221

216222
impl SubscriptionParams {
217223
pub fn new(value: SubscriptionParamsRepr) -> Result<Self, &'static str> {
218-
if value.price_feed_ids.is_empty() {
219-
return Err("no price feed ids specified");
224+
if value.price_feed_ids.is_none() && value.symbols.is_none() {
225+
return Err("either price feed ids or symbols must be specified");
226+
}
227+
228+
if let Some(ref ids) = value.price_feed_ids {
229+
if ids.is_empty() {
230+
return Err("no price feed ids specified");
231+
}
232+
if !ids.iter().all_unique() {
233+
return Err("duplicate price feed ids specified");
234+
}
220235
}
221-
if !value.price_feed_ids.iter().all_unique() {
222-
return Err("duplicate price feed ids specified");
236+
237+
if let Some(ref symbols) = value.symbols {
238+
if symbols.is_empty() {
239+
return Err("no symbols specified");
240+
}
241+
if !symbols.iter().all_unique() {
242+
return Err("duplicate symbols specified");
243+
}
223244
}
245+
224246
if !value.formats.iter().all_unique() {
225247
return Err("duplicate formats or chains specified");
226248
}
@@ -442,6 +464,7 @@ pub struct SubscribedResponse {
442464
#[serde(rename_all = "camelCase")]
443465
pub struct InvalidFeedSubscriptionDetails {
444466
pub unknown_ids: Vec<PriceFeedId>,
467+
pub unknown_symbols: Vec<String>,
445468
pub unsupported_channels: Vec<PriceFeedId>,
446469
pub unstable: Vec<PriceFeedId>,
447470
}

0 commit comments

Comments
 (0)