Skip to content

Commit fe9aa56

Browse files
feat(pyth-lazer-protocol): add price request (#2444)
* feat(pyth-lazer-protocol): add price request * feat(router): implement Display trait for Channel enum * chore(pyth-lazer-protocol): bump version to 0.6.2 and update PriceRequest struct
1 parent a41471f commit fe9aa56

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

lazer/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lazer/sdk/rust/protocol/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pyth-lazer-protocol"
3-
version = "0.6.1"
3+
version = "0.6.2"
44
edition = "2021"
55
description = "Pyth Lazer SDK - protocol types."
66
license = "Apache-2.0"

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

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use serde::{Deserialize, Serialize};
22

33
use crate::router::{
4-
Channel, Format, JsonBinaryEncoding, JsonUpdate, PriceFeedId, PriceFeedProperty,
4+
Channel, Format, JsonBinaryEncoding, JsonUpdate, PriceFeedId, PriceFeedProperty, TimestampUs,
55
};
66

77
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -21,6 +21,22 @@ pub struct LatestPriceRequest {
2121
pub channel: Channel,
2222
}
2323

24+
#[derive(Debug, Clone, Serialize, Deserialize)]
25+
#[serde(rename_all = "camelCase")]
26+
pub struct PriceRequest {
27+
pub timestamp: TimestampUs,
28+
pub price_feed_ids: Vec<PriceFeedId>,
29+
pub properties: Vec<PriceFeedProperty>,
30+
pub formats: Vec<Format>,
31+
#[serde(default)]
32+
pub json_binary_encoding: JsonBinaryEncoding,
33+
/// If `true`, the stream update will contain a JSON object containing
34+
/// all data of the update.
35+
#[serde(default = "default_parsed")]
36+
pub parsed: bool,
37+
pub channel: Channel,
38+
}
39+
2440
#[derive(Debug, Clone, Serialize, Deserialize)]
2541
#[serde(rename_all = "camelCase")]
2642
pub struct ReducePriceRequest {
@@ -30,6 +46,7 @@ pub struct ReducePriceRequest {
3046

3147
pub type LatestPriceResponse = JsonUpdate;
3248
pub type ReducePriceResponse = JsonUpdate;
49+
pub type PriceResponse = JsonUpdate;
3350

3451
pub fn default_parsed() -> bool {
3552
true

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

+18
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use {
77
rust_decimal::{prelude::FromPrimitive, Decimal},
88
serde::{de::Error, Deserialize, Serialize},
99
std::{
10+
fmt::Display,
1011
num::NonZeroI64,
1112
ops::{Add, Deref, DerefMut, Div, Sub},
1213
time::{SystemTime, UNIX_EPOCH},
@@ -66,6 +67,12 @@ impl Rate {
6667
let value: i64 = value.try_into().context("overflow")?;
6768
Ok(Self(value))
6869
}
70+
71+
pub fn from_integer(value: i64, exponent: u32) -> anyhow::Result<Self> {
72+
let coef = 10i64.checked_pow(exponent).context("overflow")?;
73+
let value = value.checked_mul(coef).context("overflow")?;
74+
Ok(Self(value))
75+
}
6976
}
7077

7178
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
@@ -236,6 +243,17 @@ mod channel_ids {
236243
pub const FIXED_RATE_200: ChannelId = ChannelId(3);
237244
}
238245

246+
impl Display for Channel {
247+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
248+
match self {
249+
Channel::FixedRate(fixed_rate) => match *fixed_rate {
250+
FixedRate::MIN => write!(f, "real_time"),
251+
rate => write!(f, "fixed_rate@{}ms", rate.value_ms()),
252+
},
253+
}
254+
}
255+
}
256+
239257
impl Channel {
240258
pub fn id(&self) -> ChannelId {
241259
match self {

0 commit comments

Comments
 (0)