-
Notifications
You must be signed in to change notification settings - Fork 301
feat(pyth-lazer-protocol): add price request #2444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ use { | |
rust_decimal::{prelude::FromPrimitive, Decimal}, | ||
serde::{de::Error, Deserialize, Serialize}, | ||
std::{ | ||
fmt::Display, | ||
num::NonZeroI64, | ||
ops::{Add, Deref, DerefMut, Div, Sub}, | ||
time::{SystemTime, UNIX_EPOCH}, | ||
|
@@ -66,6 +67,12 @@ impl Rate { | |
let value: i64 = value.try_into().context("overflow")?; | ||
Ok(Self(value)) | ||
} | ||
|
||
pub fn from_integer(value: i64, exponent: u32) -> anyhow::Result<Self> { | ||
let coef = 10i64.checked_pow(exponent).context("overflow")?; | ||
let value = value.checked_mul(coef).context("overflow")?; | ||
Ok(Self(value)) | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)] | ||
|
@@ -236,6 +243,17 @@ mod channel_ids { | |
pub const FIXED_RATE_200: ChannelId = ChannelId(3); | ||
} | ||
|
||
impl Display for Channel { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could probably just use serde to serialize it as a string, which gets you the same result without a duplicate implementation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked into it but couldn't find a good way of handling it. If you want please give it a try and let me know if it worked. |
||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Channel::FixedRate(fixed_rate) => match *fixed_rate { | ||
FixedRate::MIN => write!(f, "real_time"), | ||
rate => write!(f, "fixed_rate@{}ms", rate.value_ms()), | ||
}, | ||
} | ||
} | ||
} | ||
|
||
impl Channel { | ||
pub fn id(&self) -> ChannelId { | ||
match self { | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this API different from the LatestPrice API that router already has? Can we just extend it instead? Granted this is a little late to say it, but I am confused on the positioning of this API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok I see. We take in a timestamp to fetch the price for. Theoretically we could unify them but I guess that's not a big deal right now.