Struct PriceConf

Source
pub struct PriceConf {
    pub price: i64,
    pub conf: u64,
    pub expo: i32,
}
๐Ÿ‘ŽDeprecated: This crate has been deprecated. Please use pyth-sdk-solana instead.
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
๐Ÿ‘ŽDeprecated: This crate has been deprecated. Please use pyth-sdk-solana instead.
ยงconf: u64
๐Ÿ‘ŽDeprecated: This crate has been deprecated. Please use pyth-sdk-solana instead.
ยงexpo: i32
๐Ÿ‘ŽDeprecated: This crate has been deprecated. Please use pyth-sdk-solana instead.

Implementationsยง

Sourceยง

impl PriceConf

Source

pub fn div(&self, other: &PriceConf) -> Option<PriceConf>

๐Ÿ‘ŽDeprecated: This crate has been deprecated. Please use pyth-sdk-solana instead.

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.

Source

pub fn add(&self, other: &PriceConf) -> Option<PriceConf>

๐Ÿ‘ŽDeprecated: This crate has been deprecated. Please use pyth-sdk-solana instead.

Add other to this, propagating uncertainty in both prices. Requires both PriceConfs to have the same exponent โ€“ use scale_to_exponent on the arguments if necessary.

TODO: could generalize this method to support different exponents.

Source

pub fn cmul(&self, c: i64, e: i32) -> Option<PriceConf>

๐Ÿ‘ŽDeprecated: This crate has been deprecated. Please use pyth-sdk-solana instead.

Multiply this PriceConf by a constant c * 10^e.

Source

pub fn mul(&self, other: &PriceConf) -> Option<PriceConf>

๐Ÿ‘ŽDeprecated: This crate has been deprecated. Please use pyth-sdk-solana instead.

Multiply this PriceConf by other, propagating any uncertainty.

Source

pub fn normalize(&self) -> Option<PriceConf>

๐Ÿ‘ŽDeprecated: This crate has been deprecated. Please use pyth-sdk-solana instead.

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.

Source

pub fn scale_to_exponent(&self, target_expo: i32) -> Option<PriceConf>

๐Ÿ‘ŽDeprecated: This crate has been deprecated. Please use pyth-sdk-solana instead.

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

Sourceยง

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
Sourceยง

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
Sourceยง

impl BorshSerialize for PriceConf

Sourceยง

fn serialize<W: Write>(&self, writer: &mut W) -> Result<(), Error>

Sourceยง

fn try_to_vec(&self) -> Result<Vec<u8>, Error>

Serialize this instance into a vector of bytes.
Sourceยง

impl Clone for PriceConf

Sourceยง

fn clone(&self) -> PriceConf

Returns a duplicate of the value. Read more
1.0.0 ยท Sourceยง

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Sourceยง

impl Debug for PriceConf

Sourceยง

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Sourceยง

impl Default for PriceConf

Sourceยง

fn default() -> PriceConf

Returns the โ€œdefault valueโ€ for a type. Read more
Sourceยง

impl<'de> Deserialize<'de> for PriceConf

Sourceยง

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Sourceยง

impl PartialEq for PriceConf

Sourceยง

fn eq(&self, other: &PriceConf) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 ยท Sourceยง

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Sourceยง

impl Serialize for PriceConf

Sourceยง

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Sourceยง

impl Copy for PriceConf

Sourceยง

impl Eq for PriceConf

Sourceยง

impl StructuralPartialEq for PriceConf

Auto Trait Implementationsยง

Blanket Implementationsยง

Sourceยง

impl<T> AbiEnumVisitor for T
where T: Serialize + ?Sized,

Sourceยง

default fn visit_for_abi( &self, _digester: &mut AbiDigester, ) -> Result<AbiDigester, DigestError>

Sourceยง

impl<T> AbiEnumVisitor for T
where T: Serialize + AbiExample + ?Sized,

Sourceยง

default fn visit_for_abi( &self, digester: &mut AbiDigester, ) -> Result<AbiDigester, DigestError>

Sourceยง

impl<T> AbiExample for T

Sourceยง

default fn example() -> T

Sourceยง

impl<T> Any for T
where T: 'static + ?Sized,

Sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Sourceยง

impl<T> Borrow<T> for T
where T: ?Sized,

Sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Sourceยง

impl<T> BorrowMut<T> for T
where T: ?Sized,

Sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Sourceยง

impl<T> CloneToUninit for T
where T: Clone,

Sourceยง

unsafe fn clone_to_uninit(&self, dest: *mut u8)

๐Ÿ”ฌThis is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Sourceยง

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Sourceยง

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

impl<T, U> Into<U> for T
where U: From<T>,

Sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Sourceยง

impl<T> IntoEither for T

Sourceยง

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Sourceยง

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Sourceยง

impl<T> Pointable for T

Sourceยง

const ALIGN: usize

The alignment of pointer.
Sourceยง

type Init = T

The type for initializers.
Sourceยง

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Sourceยง

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Sourceยง

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Sourceยง

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Sourceยง

impl<T> Same for T

Sourceยง

type Output = T

Should always be Self
Sourceยง

impl<T> ToOwned for T
where T: Clone,

Sourceยง

type Owned = T

The resulting type after obtaining ownership.
Sourceยง

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Sourceยง

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Sourceยง

type Error = Infallible

The type returned in the event of a conversion error.
Sourceยง

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Sourceยง

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Sourceยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Sourceยง

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Sourceยง

fn vzip(self) -> V

Sourceยง

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,