pub struct PriceConf {
pub price: i64,
pub conf: u64,
pub expo: i32,
}
Expand description
A price with a degree of uncertainty, represented as a price +- a confidence interval.
The confidence interval roughly corresponds to the standard error of a normal distribution.
Both the price and confidence are stored in a fixed-point numeric representation, x * 10^expo
,
where expo
is the exponent. For example:
use pyth_client::PriceConf;
PriceConf { price: 12345, conf: 267, expo: -2 }; // represents 123.45 +- 2.67
PriceConf { price: 123, conf: 1, expo: 2 }; // represents 12300 +- 100
PriceConf
supports a limited set of mathematical operations. All of these operations will
propagate any uncertainty in the arguments into the result. However, the uncertainty in the
result may overestimate the true uncertainty (by at most a factor of sqrt(2)
) due to
computational limitations. Furthermore, all of these operations may return None
if their
result cannot be represented within the numeric representation (e.g., the exponent is so
small that the price does not fit into an i64). Users of these methods should (1) select
their exponents to avoid this problem, and (2) handle the None
case gracefully.
Fieldsยง
ยงprice: i64
conf: u64
expo: i32
Implementationsยง
Sourceยงimpl PriceConf
impl PriceConf
Sourcepub fn div(&self, other: &PriceConf) -> Option<PriceConf>
๐Deprecated: This crate has been deprecated. Please use pyth-sdk-solana instead.
pub fn div(&self, other: &PriceConf) -> Option<PriceConf>
Divide this price by other
while propagating the uncertainty in both prices into the result.
This method will automatically select a reasonable exponent for the result. If both
self
and other
are normalized, the exponent is self.expo + PD_EXPO - other.expo
(i.e.,
the fraction has PD_EXPO
digits of additional precision). If they are not normalized,
this method will normalize them, resulting in an unpredictable result exponent.
If the result is used in a context that requires a specific exponent, please call
scale_to_exponent
on it.
Sourcepub fn add(&self, other: &PriceConf) -> Option<PriceConf>
๐Deprecated: This crate has been deprecated. Please use pyth-sdk-solana instead.
pub fn add(&self, other: &PriceConf) -> Option<PriceConf>
Add other
to this, propagating uncertainty in both prices. Requires both
PriceConf
s to have the same exponent โ use scale_to_exponent
on the arguments
if necessary.
TODO: could generalize this method to support different exponents.
Sourcepub fn cmul(&self, c: i64, e: i32) -> Option<PriceConf>
๐Deprecated: This crate has been deprecated. Please use pyth-sdk-solana instead.
pub fn cmul(&self, c: i64, e: i32) -> Option<PriceConf>
Multiply this PriceConf
by a constant c * 10^e
.
Sourcepub fn mul(&self, other: &PriceConf) -> Option<PriceConf>
๐Deprecated: This crate has been deprecated. Please use pyth-sdk-solana instead.
pub fn mul(&self, other: &PriceConf) -> Option<PriceConf>
Multiply this PriceConf
by other
, propagating any uncertainty.
Sourcepub fn normalize(&self) -> Option<PriceConf>
๐Deprecated: This crate has been deprecated. Please use pyth-sdk-solana instead.
pub fn normalize(&self) -> Option<PriceConf>
Get a copy of this struct where the price and confidence
have been normalized to be between MIN_PD_V_I64
and MAX_PD_V_I64
.
Sourcepub fn scale_to_exponent(&self, target_expo: i32) -> Option<PriceConf>
๐Deprecated: This crate has been deprecated. Please use pyth-sdk-solana instead.
pub fn scale_to_exponent(&self, target_expo: i32) -> Option<PriceConf>
Scale this price/confidence so that its exponent is target_expo
. Return None
if
this number is outside the range of numbers representable in target_expo
, which will
happen if target_expo
is too small.
Warning: if target_expo
is significantly larger than the current exponent, this function
will return 0 +- 0.
Trait Implementationsยง
Sourceยงimpl BorshDeserialize for PriceConf
impl BorshDeserialize for PriceConf
Sourceยงimpl BorshSerialize for PriceConf
impl BorshSerialize for PriceConf
Sourceยงimpl<'de> Deserialize<'de> for PriceConf
impl<'de> Deserialize<'de> for PriceConf
Sourceยงfn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Copy for PriceConf
impl Eq for PriceConf
impl StructuralPartialEq for PriceConf
Auto Trait Implementationsยง
impl Freeze for PriceConf
impl RefUnwindSafe for PriceConf
impl Send for PriceConf
impl Sync for PriceConf
impl Unpin for PriceConf
impl UnwindSafe for PriceConf
Blanket Implementationsยง
Sourceยงimpl<T> AbiEnumVisitor for T
impl<T> AbiEnumVisitor for T
default fn visit_for_abi( &self, _digester: &mut AbiDigester, ) -> Result<AbiDigester, DigestError>
Sourceยงimpl<T> AbiEnumVisitor for T
impl<T> AbiEnumVisitor for T
default fn visit_for_abi( &self, digester: &mut AbiDigester, ) -> Result<AbiDigester, DigestError>
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Sourceยงimpl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Sourceยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Sourceยงimpl<T> IntoEither for T
impl<T> IntoEither for T
Sourceยงfn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSourceยงfn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more