Skip to main content

normalize_pyth_price

Function normalize_pyth_price 

Source
pub fn normalize_pyth_price(
    price: i64,
    exponent: i32,
) -> Result<Decimal, ArithmeticError>
Expand description

Normalize a Pyth-style price with exponent.

Pyth prices are returned as (price, exponent) where the actual price is price * 10^exponent.

ยงExample

use precision_core::oracle::normalize_pyth_price;

// Pyth ETH/USD price: 250012345678 with exponent -8
let price = 250012345678i64;
let exponent = -8i32;
let normalized = normalize_pyth_price(price, exponent).unwrap();
assert_eq!(normalized.to_string(), "2500.12345678");