#[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

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.

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.

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(&eth_usd, -8);
println!("BTC/ETH price: ({} +- {}) x 10^{}", price.price, price.conf, price.expo);

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

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes. Read more

Deserialize this instance from a slice of bytes.

Serialize this instance into a vector of bytes.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

The name of the generated JSON Schema. Read more

Generates a JSON Schema for this type. Read more

Whether JSON Schemas generated for this type should be re-used where possible using the $ref keyword. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.