Get EMA Price
Get the latest exponentially-weighted moving average (EMA) price and confidence interval for the requested price feed id.
The price feed id is a 32-byte id written as a hexadecimal string; see the price feed ids (opens in a new tab) page to look up the id for a given symbol.
The returned price and confidence are decimal numbers written in the form a * 10^e
, where e
is an exponent included in the result.
For example, a price of 1234 with an exponent of -2 represents the number 12.34.
The result also includes a timestamp
which is the unix timestamp for the price update.
The EMA methodology is described in more detail in this blog post (opens in a new tab).
This function reverts if the on-chain price has not been updated within the last get_stale_price_threshold_secs seconds. The default valid time period is set to a reasonable default on each chain and is typically around 1 minute. If you would like to configure the valid time period, see get_ema_price_no_older_than. If you want the latest price regardless of when it was updated, see get_ema_price_unsafe.
Users of this method will typically invoke update_price_feeds to update the on-chain price before reading it. This step ensures that the on-chain price is fresh.
Argument | Input | Description |
---|---|---|
price_identifier* hex | The ID of the price feed you want to read |
Example Code
use pyth::pyth;
use pyth::price_identifier;
pyth::get_ema_price(price_identifier::from_byte_vec(x"<price_identifier>"));