File tree Expand file tree Collapse file tree 6 files changed +27
-28
lines changed Expand file tree Collapse file tree 6 files changed +27
-28
lines changed Original file line number Diff line number Diff line change @@ -150,8 +150,8 @@ status .......... Trading
150
150
num_publishers .. 19
151
151
price ........... 291958500000 x 10^-8
152
152
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
155
155
```
156
156
157
157
For an example of using Solana Account structure please run:
@@ -179,8 +179,8 @@ product_account .. 6MEwdxe4g1NeAF9u6KDG14anJpFsVEa2cvr5H6iriFZ8
179
179
num_qt ....... 1
180
180
valid_slot ... 91340924
181
181
publish_slot . 91340925
182
- twap ..... .... 7426390900
183
- twac .... ..... 2259870
182
+ ema_price .... 7426390900
183
+ ema_conf ..... 2259870
184
184
```
185
185
186
186
## Development
Original file line number Diff line number Diff line change @@ -39,15 +39,15 @@ fn main() {
39
39
}
40
40
41
41
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) ;
47
47
}
48
48
None => {
49
- println ! ( "twap ..... ....... unavailable" ) ;
50
- println ! ( "twac .... ........ unavailable" ) ;
49
+ println ! ( "ema_price ....... unavailable" ) ;
50
+ println ! ( "ema_conf ........ unavailable" ) ;
51
51
}
52
52
}
53
53
Original file line number Diff line number Diff line change @@ -98,15 +98,15 @@ fn main() {
98
98
println ! ( " valid_slot ... {}" , price_account. valid_slot) ;
99
99
println ! ( " publish_slot . {}" , price_account. agg. pub_slot) ;
100
100
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) ;
106
106
}
107
107
None => {
108
- println ! ( " twap ..... .... unavailable" ) ;
109
- println ! ( " twac .... ..... unavailable" ) ;
108
+ println ! ( " ema_price .... unavailable" ) ;
109
+ println ! ( " ema_conf ..... unavailable" ) ;
110
110
}
111
111
}
112
112
Original file line number Diff line number Diff line change @@ -296,9 +296,9 @@ pub struct PriceAccount {
296
296
/// valid slot-time of agg. price
297
297
pub valid_slot : u64 ,
298
298
/// exponentially moving average price
299
- pub twap : Rational ,
299
+ pub ema_price : Rational ,
300
300
/// exponentially moving average confidence interval
301
- pub twac : Rational ,
301
+ pub ema_conf : Rational ,
302
302
/// space for future derived values
303
303
pub drv1 : i64 ,
304
304
/// space for future derived values
@@ -347,8 +347,8 @@ impl PriceAccount {
347
347
status,
348
348
max_num_publishers : self . num ,
349
349
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 ,
352
352
expo : self . expo ,
353
353
product_id : self . prod . val ,
354
354
}
Original file line number Diff line number Diff line change @@ -54,8 +54,8 @@ fn price_account_all_zero() -> PriceAccount {
54
54
num_qt : 0 ,
55
55
last_slot : 0 ,
56
56
valid_slot : 0 ,
57
- twap : rational,
58
- twac : rational,
57
+ ema_price : rational,
58
+ ema_conf : rational,
59
59
drv1 : 0 ,
60
60
drv2 : 0 ,
61
61
prod : acc_key,
Original file line number Diff line number Diff line change @@ -96,15 +96,14 @@ impl Price {
96
96
}
97
97
98
98
/**
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.
101
101
*
102
102
* At the moment, the confidence interval returned by this method is computed in
103
103
* a somewhat questionable way, so we do not recommend using it for high-value applications.
104
104
*/
105
- pub fn get_twap ( & self ) -> Option < PriceConf > {
105
+ pub fn get_ema_price ( & self ) -> Option < PriceConf > {
106
106
// 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.
108
107
Some ( PriceConf {
109
108
price : self . ema_price ,
110
109
conf : self . ema_conf ,
You can’t perform that action at this time.
0 commit comments