Skip to content

Commit ccff4a3

Browse files
authored
Merge pull request #11 from pyth-network/abehjati/move-twap-to-ema
Rename twap/twac to ema_price/ema_conf
2 parents 71586e2 + 1f7f06e commit ccff4a3

File tree

6 files changed

+27
-28
lines changed

6 files changed

+27
-28
lines changed

pyth-sdk-solana/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ status .......... Trading
150150
num_publishers .. 19
151151
price ........... 291958500000 x 10^-8
152152
conf ............ 163920000 x 10^-8
153-
twap ............ 291343470000 x 10^-8
154-
twac ............ 98874533 x 10^-8
153+
ema_price ....... 291343470000 x 10^-8
154+
ema_conf ........ 98874533 x 10^-8
155155
```
156156

157157
For an example of using Solana Account structure please run:
@@ -179,8 +179,8 @@ product_account .. 6MEwdxe4g1NeAF9u6KDG14anJpFsVEa2cvr5H6iriFZ8
179179
num_qt ....... 1
180180
valid_slot ... 91340924
181181
publish_slot . 91340925
182-
twap ......... 7426390900
183-
twac ......... 2259870
182+
ema_price .... 7426390900
183+
ema_conf ..... 2259870
184184
```
185185

186186
## Development

pyth-sdk-solana/examples/eth_price.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ fn main() {
3939
}
4040

4141

42-
let maybe_twap = eth_price.get_twap();
43-
match maybe_twap {
44-
Some(twap) => {
45-
println!("twap ............ {} x 10^{}", twap.price, twap.expo);
46-
println!("twac ............ {} x 10^{}", twap.conf, twap.expo);
42+
let maybe_ema_price = eth_price.get_ema_price();
43+
match maybe_ema_price {
44+
Some(ema_price) => {
45+
println!("ema_price ....... {} x 10^{}", ema_price.price, ema_price.expo);
46+
println!("ema_conf ........ {} x 10^{}", ema_price.conf, ema_price.expo);
4747
}
4848
None => {
49-
println!("twap ............ unavailable");
50-
println!("twac ............ unavailable");
49+
println!("ema_price ....... unavailable");
50+
println!("ema_conf ........ unavailable");
5151
}
5252
}
5353

pyth-sdk-solana/examples/get_accounts.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ fn main() {
9898
println!(" valid_slot ... {}", price_account.valid_slot);
9999
println!(" publish_slot . {}", price_account.agg.pub_slot);
100100

101-
let maybe_twap = price.get_twap();
102-
match maybe_twap {
103-
Some(twap) => {
104-
println!(" twap ......... {} x 10^{}", twap.price, twap.expo);
105-
println!(" twac ......... {} x 10^{}", twap.conf, twap.expo);
101+
let maybe_ema_price = price.get_ema_price();
102+
match maybe_ema_price {
103+
Some(ema_price) => {
104+
println!(" ema_price .... {} x 10^{}", ema_price.price, ema_price.expo);
105+
println!(" ema_conf ..... {} x 10^{}", ema_price.conf, ema_price.expo);
106106
}
107107
None => {
108-
println!(" twap ......... unavailable");
109-
println!(" twac ......... unavailable");
108+
println!(" ema_price .... unavailable");
109+
println!(" ema_conf ..... unavailable");
110110
}
111111
}
112112

pyth-sdk-solana/src/state.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ pub struct PriceAccount {
296296
/// valid slot-time of agg. price
297297
pub valid_slot: u64,
298298
/// exponentially moving average price
299-
pub twap: Rational,
299+
pub ema_price: Rational,
300300
/// exponentially moving average confidence interval
301-
pub twac: Rational,
301+
pub ema_conf: Rational,
302302
/// space for future derived values
303303
pub drv1: i64,
304304
/// space for future derived values
@@ -347,8 +347,8 @@ impl PriceAccount {
347347
status,
348348
max_num_publishers: self.num,
349349
num_publishers: self.num_qt,
350-
ema_price: self.twap.val,
351-
ema_conf: self.twac.val as u64,
350+
ema_price: self.ema_price.val,
351+
ema_conf: self.ema_conf.val as u64,
352352
expo: self.expo,
353353
product_id: self.prod.val,
354354
}

pyth-sdk-solana/tests/stale_price.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ fn price_account_all_zero() -> PriceAccount {
5454
num_qt: 0,
5555
last_slot: 0,
5656
valid_slot: 0,
57-
twap: rational,
58-
twac: rational,
57+
ema_price: rational,
58+
ema_conf: rational,
5959
drv1: 0,
6060
drv2: 0,
6161
prod: acc_key,

pyth-sdk/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,14 @@ impl Price {
9696
}
9797

9898
/**
99-
* Get the time-weighted average price (TWAP) and a confidence interval on the result.
100-
* Returns `None` if the twap is currently unavailable.
99+
* Get the exponential moving average price (ema_price) and a confidence interval on the result.
100+
* Returns `None` if the ema price is currently unavailable.
101101
*
102102
* At the moment, the confidence interval returned by this method is computed in
103103
* a somewhat questionable way, so we do not recommend using it for high-value applications.
104104
*/
105-
pub fn get_twap(&self) -> Option<PriceConf> {
105+
pub fn get_ema_price(&self) -> Option<PriceConf> {
106106
// This method currently cannot return None, but may do so in the future.
107-
// Note that the twac is a positive number in i64, so safe to cast to u64.
108107
Some(PriceConf {
109108
price: self.ema_price,
110109
conf: self.ema_conf,

0 commit comments

Comments
 (0)