Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions examples/get_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down
58 changes: 29 additions & 29 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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<PriceConf> {
pub fn get_ema_price(&self) -> Option<PriceConf> {
// 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 })
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/stale_price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down