Skip to content

Commit 161ddb6

Browse files
authored
Add market session field to payload and subscription params (#3247)
1 parent 30e6aa5 commit 161ddb6

File tree

12 files changed

+98
-16
lines changed

12 files changed

+98
-16
lines changed

Cargo.lock

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

lazer/contracts/solana/programs/pyth-lazer-solana-contract/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ no-log-ix-name = []
1919
idl-build = ["anchor-lang/idl-build"]
2020

2121
[dependencies]
22-
pyth-lazer-protocol = { path = "../../../../sdk/rust/protocol", version = "0.24.0" }
22+
pyth-lazer-protocol = { path = "../../../../sdk/rust/protocol", version = "0.25.0" }
2323

2424
anchor-lang = "0.31.1"
2525
bytemuck = { version = "1.20.0", features = ["derive"] }

lazer/publisher_sdk/proto/state.proto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ enum MarketSession {
9393
PRE_MARKET = 1;
9494
POST_MARKET = 2;
9595
OVER_NIGHT = 3;
96+
CLOSED = 4;
9697
}
9798

9899
message FeedMarketSchedule {
@@ -221,7 +222,7 @@ message FeedAggregateData {
221222
// Actual value is `mantissa * 10 ^ exponent`.
222223
// Restricted to int16.
223224
optional int32 exponent = 9;
224-
// [optional] Market session for the feed. Can be absent if no data is available.
225+
// [required] Market session for the feed.
225226
optional MarketSession market_session = 10;
226227
}
227228

lazer/publisher_sdk/rust/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[package]
22
name = "pyth-lazer-publisher-sdk"
3-
version = "0.24.0"
3+
version = "0.25.0"
44
edition = "2021"
55
description = "Pyth Lazer Publisher SDK types."
66
license = "Apache-2.0"
77
repository = "https://github.com/pyth-network/pyth-crosschain"
88

99
[dependencies]
10-
pyth-lazer-protocol = { version = "0.24.0", path = "../../sdk/rust/protocol" }
10+
pyth-lazer-protocol = { version = "0.25.0", path = "../../sdk/rust/protocol" }
1111
anyhow = "1.0.98"
1212
protobuf = "3.7.2"
1313
serde_json = "1.0.140"

lazer/publisher_sdk/rust/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ impl From<pyth_lazer_protocol::api::MarketSession> for state::MarketSession {
157157
state::MarketSession::POST_MARKET
158158
}
159159
pyth_lazer_protocol::api::MarketSession::OverNight => state::MarketSession::OVER_NIGHT,
160+
pyth_lazer_protocol::api::MarketSession::Closed => state::MarketSession::CLOSED,
160161
}
161162
}
162163
}
@@ -170,6 +171,7 @@ impl From<state::MarketSession> for pyth_lazer_protocol::api::MarketSession {
170171
pyth_lazer_protocol::api::MarketSession::PostMarket
171172
}
172173
state::MarketSession::OVER_NIGHT => pyth_lazer_protocol::api::MarketSession::OverNight,
174+
state::MarketSession::CLOSED => pyth_lazer_protocol::api::MarketSession::Closed,
173175
}
174176
}
175177
}

lazer/sdk/rust/client/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[package]
22
name = "pyth-lazer-client"
3-
version = "13.0.0"
3+
version = "14.0.0"
44
edition = "2021"
55
description = "A Rust client for Pyth Lazer"
66
license = "Apache-2.0"
77

88
[dependencies]
9-
pyth-lazer-protocol = { path = "../protocol", version = "0.24.0" }
10-
pyth-lazer-publisher-sdk = { path = "../../../publisher_sdk/rust", version = "0.24.0" }
9+
pyth-lazer-protocol = { path = "../protocol", version = "0.25.0" }
10+
pyth-lazer-publisher-sdk = { path = "../../../publisher_sdk/rust", version = "0.25.0" }
1111

1212
tokio = { version = "1", features = ["full"] }
1313
tokio-stream = "0.1.17"

lazer/sdk/rust/client/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ Select which price feed properties to receive:
215215
- `PriceFeedProperty::FundingRate` - Funding rate (for perpetual markets)
216216
- `PriceFeedProperty::FundingTimestamp` - Funding rate timestamp
217217
- `PriceFeedProperty::FundingRateInterval` - Funding rate update interval
218+
- `PriceFeedProperty::MarketSession` - Current market session
218219

219220
```rust
220221
use pyth_lazer_protocol::PriceFeedProperty;

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ async fn main() -> anyhow::Result<()> {
7474
parsed: true,
7575
channel: Channel::FixedRate(FixedRate::RATE_200_MS),
7676
ignore_invalid_feeds: false,
77+
market_sessions: vec![
78+
pyth_lazer_protocol::api::MarketSession::Regular,
79+
pyth_lazer_protocol::api::MarketSession::PreMarket,
80+
pyth_lazer_protocol::api::MarketSession::PostMarket,
81+
pyth_lazer_protocol::api::MarketSession::OverNight,
82+
pyth_lazer_protocol::api::MarketSession::Closed,
83+
],
7784
})
7885
.expect("invalid subscription params"),
7986
},
@@ -99,6 +106,13 @@ async fn main() -> anyhow::Result<()> {
99106
parsed: false,
100107
channel: Channel::FixedRate(FixedRate::RATE_50_MS),
101108
ignore_invalid_feeds: false,
109+
market_sessions: vec![
110+
pyth_lazer_protocol::api::MarketSession::Regular,
111+
pyth_lazer_protocol::api::MarketSession::PreMarket,
112+
pyth_lazer_protocol::api::MarketSession::PostMarket,
113+
pyth_lazer_protocol::api::MarketSession::OverNight,
114+
pyth_lazer_protocol::api::MarketSession::Closed,
115+
],
102116
})
103117
.expect("invalid subscription params"),
104118
},

lazer/sdk/rust/protocol/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-protocol"
3-
version = "0.24.0"
3+
version = "0.25.0"
44
edition = "2021"
55
description = "Pyth Lazer SDK - protocol types."
66
license = "Apache-2.0"

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ pub struct LatestPriceRequestRepr {
3434
#[serde(default = "default_parsed")]
3535
pub parsed: bool,
3636
pub channel: Channel,
37+
#[serde(default = "default_market_sessions")]
38+
pub market_sessions: Vec<MarketSession>,
3739
}
3840

3941
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, ToSchema)]
@@ -99,6 +101,8 @@ pub struct PriceRequestRepr {
99101
#[serde(default = "default_parsed")]
100102
pub parsed: bool,
101103
pub channel: Channel,
104+
#[serde(default = "default_market_sessions")]
105+
pub market_sessions: Vec<MarketSession>,
102106
}
103107

104108
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, ToSchema)]
@@ -162,6 +166,16 @@ pub fn default_parsed() -> bool {
162166
true
163167
}
164168

169+
pub fn default_market_sessions() -> Vec<MarketSession> {
170+
vec![
171+
MarketSession::Regular,
172+
MarketSession::PreMarket,
173+
MarketSession::PostMarket,
174+
MarketSession::OverNight,
175+
MarketSession::Closed,
176+
]
177+
}
178+
165179
pub fn schema_default_symbols() -> Option<Vec<String>> {
166180
None
167181
}
@@ -311,6 +325,9 @@ pub struct SubscriptionParamsRepr {
311325
// "ignoreInvalidFeedIds" was renamed to "ignoreInvalidFeeds". "ignoreInvalidFeedIds" is still supported for compatibility.
312326
#[serde(default, alias = "ignoreInvalidFeedIds")]
313327
pub ignore_invalid_feeds: bool,
328+
// Market sessions to filter price feeds by. Default to [Regular] for backward compatibility.
329+
#[serde(default = "default_market_sessions")]
330+
pub market_sessions: Vec<MarketSession>,
314331
}
315332

316333
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, ToSchema)]
@@ -429,6 +446,9 @@ pub struct ParsedFeedPayload {
429446
#[serde(skip_serializing_if = "Option::is_none")]
430447
#[serde(default)]
431448
pub funding_rate_interval: Option<DurationUs>,
449+
#[serde(skip_serializing_if = "Option::is_none")]
450+
#[serde(default)]
451+
pub market_session: Option<MarketSession>,
432452
}
433453

434454
impl ParsedFeedPayload {
@@ -448,6 +468,7 @@ impl ParsedFeedPayload {
448468
funding_rate: None,
449469
funding_timestamp: None,
450470
funding_rate_interval: None,
471+
market_session: None,
451472
};
452473
for &property in properties {
453474
match property {
@@ -478,6 +499,9 @@ impl ParsedFeedPayload {
478499
PriceFeedProperty::FundingRateInterval => {
479500
output.funding_rate_interval = data.funding_rate_interval;
480501
}
502+
PriceFeedProperty::MarketSession => {
503+
output.market_session = Some(data.market_session);
504+
}
481505
}
482506
}
483507
output
@@ -499,6 +523,7 @@ impl ParsedFeedPayload {
499523
funding_rate: data.funding_rate,
500524
funding_timestamp: data.funding_timestamp,
501525
funding_rate_interval: data.funding_rate_interval,
526+
market_session: Some(data.market_session),
502527
}
503528
}
504529
}
@@ -662,4 +687,32 @@ pub enum MarketSession {
662687
PreMarket,
663688
PostMarket,
664689
OverNight,
690+
Closed,
691+
}
692+
693+
impl From<MarketSession> for i16 {
694+
fn from(s: MarketSession) -> i16 {
695+
match s {
696+
MarketSession::Regular => 0,
697+
MarketSession::PreMarket => 1,
698+
MarketSession::PostMarket => 2,
699+
MarketSession::OverNight => 3,
700+
MarketSession::Closed => 4,
701+
}
702+
}
703+
}
704+
705+
impl TryFrom<i16> for MarketSession {
706+
type Error = anyhow::Error;
707+
708+
fn try_from(value: i16) -> Result<MarketSession, Self::Error> {
709+
match value {
710+
0 => Ok(MarketSession::Regular),
711+
1 => Ok(MarketSession::PreMarket),
712+
2 => Ok(MarketSession::PostMarket),
713+
3 => Ok(MarketSession::OverNight),
714+
4 => Ok(MarketSession::Closed),
715+
_ => Err(anyhow::anyhow!("invalid MarketSession value: {}", value)),
716+
}
717+
}
665718
}

0 commit comments

Comments
 (0)