diff --git a/README.md b/README.md index 72227dc..fb1e4fa 100644 --- a/README.md +++ b/README.md @@ -130,25 +130,25 @@ cargo run --example get_accounts The output of this command is a listing of Pyth's accounts, such as: ``` -product_account .. 6MEwdxe4g1NeAF9u6KDG14anJpFsVEa2cvr5H6iriFZ8 - symbol.......... SRM/USD - asset_type...... Crypto - quote_currency.. USD - description..... SRM/USD - generic_symbol.. SRMUSD - base............ SRM - price_account .. 992moaMQKs32GKZ9dxi8keyM2bUmbrwBZpK4p2K6X5Vs - price ........ 7398000000 - conf ......... 3200000 - price_type ... price - exponent ..... -9 - status ....... trading - corp_act ..... nocorpact - num_qt ....... 1 - valid_slot ... 91340924 - publish_slot . 91340925 - twap ......... 7426390900 - twac ......... 2259870 +product_account ............ 6MEwdxe4g1NeAF9u6KDG14anJpFsVEa2cvr5H6iriFZ8 + symbol.................... SRM/USD + asset_type................ Crypto + quote_currency............ USD + description............... SRM/USD + generic_symbol............ SRMUSD + base...................... SRM + price_account ............ 992moaMQKs32GKZ9dxi8keyM2bUmbrwBZpK4p2K6X5Vs + price .................. 7398000000 + conf ................... 3200000 + price_type ............. price + exponent ............... -9 + status ................. trading + corp_act ............... nocorpact + num_qt ................. 1 + valid_slot ............. 91340924 + publish_slot ........... 91340925 + ema_price .............. 7426390900 + ema_confidence ......... 2259870 ``` ## Development diff --git a/examples/get_accounts.rs b/examples/get_accounts.rs index 679db45..93f6079 100644 --- a/examples/get_accounts.rs +++ b/examples/get_accounts.rs @@ -101,15 +101,15 @@ fn main() { println!( " valid_slot ... {}", pa.valid_slot ); println!( " publish_slot . {}", pa.agg.pub_slot ); - let maybe_twap = pa.get_twap(); - match maybe_twap { - Some(twap) => { - println!( " twap ......... {} x 10^{}", twap.price, twap.expo ); - println!( " twac ......... {} x 10^{}", twap.conf, twap.expo ); + let maybe_ema_price = pa.get_ema_price(); + match maybe_ema_price { + Some(ema_price) => { + println!( " ema_price ......... {} x 10^{}", ema_price.price, ema_price.expo ); + println!( " ema_confidence ......... {} x 10^{}", ema_price.conf, ema_price.expo ); } None => { - println!( " twap ......... unavailable"); - println!( " twac ......... unavailable"); + println!( " ema_price ......... unavailable"); + println!( " ema_confidence ......... unavailable"); } } diff --git a/src/lib.rs b/src/lib.rs index 402a241..01454a8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -224,49 +224,49 @@ pub struct Ema pub struct Price { /// pyth magic number - pub magic : u32, + pub magic : u32, /// program version - pub ver : u32, + pub ver : u32, /// account type - pub atype : u32, + pub atype : u32, /// price account size - pub size : u32, + pub size : u32, /// price or calculation type - pub ptype : PriceType, + pub ptype : PriceType, /// price exponent - pub expo : i32, + pub expo : i32, /// number of component prices - pub num : u32, + pub num : u32, /// number of quoters that make up aggregate - pub num_qt : u32, + pub num_qt : u32, /// slot of last valid (not unknown) aggregate price - pub last_slot : u64, + pub last_slot : u64, /// valid slot-time of agg. price - pub valid_slot : u64, - /// time-weighted average price - pub twap : Ema, - /// time-weighted average confidence interval - pub twac : Ema, + pub valid_slot : u64, + /// exponential moving average price + pub ema_price : Ema, + /// exponential moving average confidence interval + pub ema_confidence : Ema, /// space for future derived values - pub drv1 : i64, + pub drv1 : i64, /// space for future derived values - pub drv2 : i64, + pub drv2 : i64, /// product account key - pub prod : AccKey, + pub prod : AccKey, /// next Price account in linked list - pub next : AccKey, + pub next : AccKey, /// valid slot of previous update - pub prev_slot : u64, + pub prev_slot : u64, /// aggregate price of previous update - pub prev_price : i64, + pub prev_price : i64, /// confidence interval of previous update - pub prev_conf : u64, + pub prev_conf : u64, /// space for future derived values - pub drv3 : i64, + pub drv3 : i64, /// aggregate price info - pub agg : PriceInfo, + pub agg : PriceInfo, /// price components one per quoter - pub comp : [PriceComp;32] + pub comp : [PriceComp;32] } #[cfg(target_endian = "little")] @@ -307,16 +307,16 @@ impl Price { } /** - * Get the time-weighted average price (TWAP) and a confidence interval on the result. - * Returns `None` if the twap is currently unavailable. + * 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. */ - pub fn get_twap(&self) -> Option { + pub fn get_ema_price(&self) -> Option { // This method currently cannot return None, but may do so in the future. - // Note that the twac is a positive number in i64, so safe to cast to u64. - Some(PriceConf { price: self.twap.val, conf: self.twac.val as u64, expo: self.expo }) + // Note that the ema_confidence is a positive number in i64, so safe to cast to u64. + Some(PriceConf { price: self.ema_price.val, conf: self.ema_confidence.val as u64, expo: self.expo }) } /** diff --git a/tests/stale_price.rs b/tests/stale_price.rs index ee3ac63..824180b 100644 --- a/tests/stale_price.rs +++ b/tests/stale_price.rs @@ -45,8 +45,8 @@ fn price_all_zero() -> Price { num_qt: 0, last_slot: 0, valid_slot: 0, - twap: ema, - twac: ema, + ema_price: ema, + ema_confidence: ema, drv1: 0, drv2: 0, prod: acc_key,