Skip to content
Merged
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
2 changes: 1 addition & 1 deletion lazer/Cargo.lock

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

2 changes: 1 addition & 1 deletion lazer/sdk/rust/protocol/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pyth-lazer-protocol"
version = "0.2.0"
version = "0.2.1"
edition = "2021"
description = "Pyth Lazer SDK - protocol types."
license = "Apache-2.0"
Expand Down
23 changes: 23 additions & 0 deletions lazer/sdk/rust/protocol/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ pub enum PayloadPropertyValue {
Price(Option<Price>),
BestBidPrice(Option<Price>),
BestAskPrice(Option<Price>),
PublisherCount(Option<u16>),
}

#[derive(Debug, Clone, Default)]
pub struct AggregatedPriceFeedData {
pub price: Option<Price>,
pub best_bid_price: Option<Price>,
pub best_ask_price: Option<Price>,
pub publisher_count: Option<u16>,
}

pub const PAYLOAD_FORMAT_MAGIC: u32 = 2479346549;
Expand Down Expand Up @@ -67,6 +69,9 @@ impl PayloadData {
PriceFeedProperty::BestAskPrice => {
PayloadPropertyValue::BestAskPrice(feed.best_ask_price)
}
PriceFeedProperty::PublisherCount => {
PayloadPropertyValue::PublisherCount(feed.publisher_count)
}
})
.collect(),
})
Expand Down Expand Up @@ -96,6 +101,10 @@ impl PayloadData {
writer.write_u8(PriceFeedProperty::BestAskPrice as u8)?;
write_option_price::<BO>(&mut writer, *price)?;
}
PayloadPropertyValue::PublisherCount(count) => {
writer.write_u8(PriceFeedProperty::PublisherCount as u8)?;
write_option_u16::<BO>(&mut writer, *count)?;
}
}
}
}
Expand Down Expand Up @@ -134,6 +143,8 @@ impl PayloadData {
PayloadPropertyValue::BestBidPrice(read_option_price::<BO>(&mut reader)?)
} else if property == PriceFeedProperty::BestAskPrice as u8 {
PayloadPropertyValue::BestAskPrice(read_option_price::<BO>(&mut reader)?)
} else if property == PriceFeedProperty::PublisherCount as u8 {
PayloadPropertyValue::PublisherCount(read_option_u16::<BO>(&mut reader)?)
} else {
bail!("unknown property");
};
Expand Down Expand Up @@ -161,6 +172,18 @@ fn read_option_price<BO: ByteOrder>(mut reader: impl Read) -> std::io::Result<Op
Ok(value.map(Price))
}

fn write_option_u16<BO: ByteOrder>(
mut writer: impl Write,
value: Option<u16>,
) -> std::io::Result<()> {
writer.write_u16::<BO>(value.unwrap_or(0))
}

fn read_option_u16<BO: ByteOrder>(mut reader: impl Read) -> std::io::Result<Option<u16>> {
let value = reader.read_u16::<BO>()?;
Ok(Some(value))
}

pub const BINARY_UPDATE_FORMAT_MAGIC: u32 = 1937213467;

pub const PARSED_FORMAT_MAGIC: u32 = 2584795844;
Expand Down
9 changes: 9 additions & 0 deletions lazer/sdk/rust/protocol/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ pub enum PriceFeedProperty {
Price,
BestBidPrice,
BestAskPrice,
PublisherCount,
// More fields may be added later.
}

Expand Down Expand Up @@ -392,6 +393,9 @@ pub struct ParsedFeedPayload {
#[serde(with = "crate::serde_str::option_price")]
#[serde(default)]
pub best_ask_price: Option<Price>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub publisher_count: Option<u16>,
// More fields may be added later.
}

Expand All @@ -406,6 +410,7 @@ impl ParsedFeedPayload {
price: None,
best_bid_price: None,
best_ask_price: None,
publisher_count: None,
};
for &property in properties {
match property {
Expand All @@ -418,6 +423,9 @@ impl ParsedFeedPayload {
PriceFeedProperty::BestAskPrice => {
output.best_ask_price = data.best_ask_price;
}
PriceFeedProperty::PublisherCount => {
output.publisher_count = data.publisher_count;
}
}
}
output
Expand All @@ -429,6 +437,7 @@ impl ParsedFeedPayload {
price: data.price,
best_bid_price: data.best_bid_price,
best_ask_price: data.best_ask_price,
publisher_count: data.publisher_count,
}
}
}
Loading