#[repr(C)]pub struct Price {
pub price: i64,
pub conf: u64,
pub status: PriceStatus,
pub expo: i32,
pub max_num_publishers: u32,
pub num_publishers: u32,
pub ema_price: i64,
pub ema_conf: u64,
pub product_id: ProductIdentifier,
}
Expand description
Represents a current aggregation price from pyth publisher feeds.
Fields
price: i64
The current price.
conf: u64
Confidence interval around the price.
status: PriceStatus
Status of price (Trading is valid).
expo: i32
Price exponent.
max_num_publishers: u32
Maximum number of allowed publishers that can contribute to a price.
num_publishers: u32
Number of publishers that made up current aggregate.
ema_price: i64
Exponentially moving average price.
ema_conf: u64
Exponentially moving average confidence interval.
product_id: ProductIdentifier
Product account key.
Implementations
sourceimpl Price
impl Price
sourcepub fn get_current_price(&self) -> Option<PriceConf>
pub fn get_current_price(&self) -> Option<PriceConf>
Get the current price and confidence interval as fixed-point numbers of the form a * 10^e.
Returns a struct containing the current price, confidence interval, and the exponent for
both numbers. Returns None
if price information is currently unavailable for any
reason.
sourcepub fn get_ema_price(&self) -> Option<PriceConf>
pub fn get_ema_price(&self) -> Option<PriceConf>
Get the exponential moving average price (ema_price) and a confidence interval on the result.
Returns None
if the ema price is currently unavailable.
At the moment, the confidence interval returned by this method is computed in
a somewhat questionable way, so we do not recommend using it for high-value applications.
sourcepub fn get_price_in_quote(
&self,
quote: &Price,
result_expo: i32
) -> Option<PriceConf>
pub fn get_price_in_quote(
&self,
quote: &Price,
result_expo: i32
) -> Option<PriceConf>
Get the current price of this account in a different quote currency.
If this account represents the price of the product X/Z, and quote
represents the price
of the product Y/Z, this method returns the price of X/Y. Use this method to get the
price of e.g., mSOL/SOL from the mSOL/USD and SOL/USD accounts.
result_expo
determines the exponent of the result, i.e., the number of digits below the
decimal point. This method returns None
if either the price or confidence are too
large to be represented with the requested exponent.
Example:
let btc_usd: Price = ...;
let eth_usd: Price = ...;
// -8 is the desired exponent for the result
let btc_eth: PriceConf = btc_usd.get_price_in_quote(ð_usd, -8);
println!("BTC/ETH price: ({} +- {}) x 10^{}", price.price, price.conf, price.expo);
sourcepub fn price_basket(
amounts: &[(Price, i64, i32)],
result_expo: i32
) -> Option<PriceConf>
pub fn price_basket(
amounts: &[(Price, i64, i32)],
result_expo: i32
) -> Option<PriceConf>
Get the price of a basket of currencies.
Each entry in amounts
is of the form (price, qty, qty_expo)
, and the result is the sum
of price * qty * 10^qty_expo
. The result is returned with exponent result_expo
.
An example use case for this function is to get the value of an LP token.
Example:
let btc_usd: Price = ...;
let eth_usd: Price = ...;
// Quantity of each asset in fixed-point a * 10^e.
// This represents 0.1 BTC and .05 ETH.
// -8 is desired exponent for result
let basket_price: PriceConf = Price::price_basket(&[
(btc_usd, 10, -2),
(eth_usd, 5, -2)
], -8);
println!("0.1 BTC and 0.05 ETH are worth: ({} +- {}) x 10^{} USD",
basket_price.price, basket_price.conf, basket_price.expo);
Trait Implementations
sourceimpl BorshDeserialize for Price where
i64: BorshDeserialize,
u64: BorshDeserialize,
PriceStatus: BorshDeserialize,
i32: BorshDeserialize,
u32: BorshDeserialize,
u32: BorshDeserialize,
i64: BorshDeserialize,
u64: BorshDeserialize,
ProductIdentifier: BorshDeserialize,
impl BorshDeserialize for Price where
i64: BorshDeserialize,
u64: BorshDeserialize,
PriceStatus: BorshDeserialize,
i32: BorshDeserialize,
u32: BorshDeserialize,
u32: BorshDeserialize,
i64: BorshDeserialize,
u64: BorshDeserialize,
ProductIdentifier: BorshDeserialize,
sourceimpl BorshSerialize for Price where
i64: BorshSerialize,
u64: BorshSerialize,
PriceStatus: BorshSerialize,
i32: BorshSerialize,
u32: BorshSerialize,
u32: BorshSerialize,
i64: BorshSerialize,
u64: BorshSerialize,
ProductIdentifier: BorshSerialize,
impl BorshSerialize for Price where
i64: BorshSerialize,
u64: BorshSerialize,
PriceStatus: BorshSerialize,
i32: BorshSerialize,
u32: BorshSerialize,
u32: BorshSerialize,
i64: BorshSerialize,
u64: BorshSerialize,
ProductIdentifier: BorshSerialize,
sourceimpl<'de> Deserialize<'de> for Price
impl<'de> Deserialize<'de> for Price
sourcefn 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>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl JsonSchema for Price
impl JsonSchema for Price
sourcefn schema_name() -> String
fn schema_name() -> String
The name of the generated JSON Schema. Read more
sourcefn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
sourcefn is_referenceable() -> bool
fn is_referenceable() -> bool
Whether JSON Schemas generated for this type should be re-used where possible using the $ref
keyword. Read more
impl Copy for Price
impl Eq for Price
impl StructuralEq for Price
impl StructuralPartialEq for Price
Auto Trait Implementations
impl RefUnwindSafe for Price
impl Send for Price
impl Sync for Price
impl Unpin for Price
impl UnwindSafe for Price
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more