Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.

Commit 1009cfc

Browse files
committed
change twap to ema_price and twac to ema_confidence
1 parent 11b39b9 commit 1009cfc

File tree

4 files changed

+57
-57
lines changed

4 files changed

+57
-57
lines changed

README.md

+19-19
Original file line numberDiff line numberDiff line change
@@ -130,25 +130,25 @@ cargo run --example get_accounts
130130
The output of this command is a listing of Pyth's accounts, such as:
131131

132132
```
133-
product_account .. 6MEwdxe4g1NeAF9u6KDG14anJpFsVEa2cvr5H6iriFZ8
134-
symbol.......... SRM/USD
135-
asset_type...... Crypto
136-
quote_currency.. USD
137-
description..... SRM/USD
138-
generic_symbol.. SRMUSD
139-
base............ SRM
140-
price_account .. 992moaMQKs32GKZ9dxi8keyM2bUmbrwBZpK4p2K6X5Vs
141-
price ........ 7398000000
142-
conf ......... 3200000
143-
price_type ... price
144-
exponent ..... -9
145-
status ....... trading
146-
corp_act ..... nocorpact
147-
num_qt ....... 1
148-
valid_slot ... 91340924
149-
publish_slot . 91340925
150-
twap ......... 7426390900
151-
twac ......... 2259870
133+
product_account ............ 6MEwdxe4g1NeAF9u6KDG14anJpFsVEa2cvr5H6iriFZ8
134+
symbol.................... SRM/USD
135+
asset_type................ Crypto
136+
quote_currency............ USD
137+
description............... SRM/USD
138+
generic_symbol............ SRMUSD
139+
base...................... SRM
140+
price_account ............ 992moaMQKs32GKZ9dxi8keyM2bUmbrwBZpK4p2K6X5Vs
141+
price .................. 7398000000
142+
conf ................... 3200000
143+
price_type ............. price
144+
exponent ............... -9
145+
status ................. trading
146+
corp_act ............... nocorpact
147+
num_qt ................. 1
148+
valid_slot ............. 91340924
149+
publish_slot ........... 91340925
150+
ema_price .............. 7426390900
151+
ema_confidence ......... 2259870
152152
```
153153

154154
## Development

examples/get_accounts.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ fn main() {
101101
println!( " valid_slot ... {}", pa.valid_slot );
102102
println!( " publish_slot . {}", pa.agg.pub_slot );
103103

104-
let maybe_twap = pa.get_twap();
105-
match maybe_twap {
106-
Some(twap) => {
107-
println!( " twap ......... {} x 10^{}", twap.price, twap.expo );
108-
println!( " twac ......... {} x 10^{}", twap.conf, twap.expo );
104+
let maybe_ema_price = pa.get_ema_price();
105+
match maybe_ema_price {
106+
Some(ema_price) => {
107+
println!( " ema_price ......... {} x 10^{}", ema_price.price, ema_price.expo );
108+
println!( " ema_confidence ......... {} x 10^{}", ema_price.conf, ema_price.expo );
109109
}
110110
None => {
111-
println!( " twap ......... unavailable");
112-
println!( " twac ......... unavailable");
111+
println!( " ema_price ......... unavailable");
112+
println!( " ema_confidence ......... unavailable");
113113
}
114114
}
115115

src/lib.rs

+29-29
Original file line numberDiff line numberDiff line change
@@ -224,49 +224,49 @@ pub struct Ema
224224
pub struct Price
225225
{
226226
/// pyth magic number
227-
pub magic : u32,
227+
pub magic : u32,
228228
/// program version
229-
pub ver : u32,
229+
pub ver : u32,
230230
/// account type
231-
pub atype : u32,
231+
pub atype : u32,
232232
/// price account size
233-
pub size : u32,
233+
pub size : u32,
234234
/// price or calculation type
235-
pub ptype : PriceType,
235+
pub ptype : PriceType,
236236
/// price exponent
237-
pub expo : i32,
237+
pub expo : i32,
238238
/// number of component prices
239-
pub num : u32,
239+
pub num : u32,
240240
/// number of quoters that make up aggregate
241-
pub num_qt : u32,
241+
pub num_qt : u32,
242242
/// slot of last valid (not unknown) aggregate price
243-
pub last_slot : u64,
243+
pub last_slot : u64,
244244
/// valid slot-time of agg. price
245-
pub valid_slot : u64,
246-
/// time-weighted average price
247-
pub twap : Ema,
248-
/// time-weighted average confidence interval
249-
pub twac : Ema,
245+
pub valid_slot : u64,
246+
/// exponential moving average price
247+
pub ema_price : Ema,
248+
/// exponential moving average confidence interval
249+
pub ema_confidence : Ema,
250250
/// space for future derived values
251-
pub drv1 : i64,
251+
pub drv1 : i64,
252252
/// space for future derived values
253-
pub drv2 : i64,
253+
pub drv2 : i64,
254254
/// product account key
255-
pub prod : AccKey,
255+
pub prod : AccKey,
256256
/// next Price account in linked list
257-
pub next : AccKey,
257+
pub next : AccKey,
258258
/// valid slot of previous update
259-
pub prev_slot : u64,
259+
pub prev_slot : u64,
260260
/// aggregate price of previous update
261-
pub prev_price : i64,
261+
pub prev_price : i64,
262262
/// confidence interval of previous update
263-
pub prev_conf : u64,
263+
pub prev_conf : u64,
264264
/// space for future derived values
265-
pub drv3 : i64,
265+
pub drv3 : i64,
266266
/// aggregate price info
267-
pub agg : PriceInfo,
267+
pub agg : PriceInfo,
268268
/// price components one per quoter
269-
pub comp : [PriceComp;32]
269+
pub comp : [PriceComp;32]
270270
}
271271

272272
#[cfg(target_endian = "little")]
@@ -307,16 +307,16 @@ impl Price {
307307
}
308308

309309
/**
310-
* Get the time-weighted average price (TWAP) and a confidence interval on the result.
311-
* Returns `None` if the twap is currently unavailable.
310+
* Get the exponential moving average price (ema_price) and a confidence interval on the result.
311+
* Returns `None` if the ema_price is currently unavailable.
312312
*
313313
* At the moment, the confidence interval returned by this method is computed in
314314
* a somewhat questionable way, so we do not recommend using it for high-value applications.
315315
*/
316-
pub fn get_twap(&self) -> Option<PriceConf> {
316+
pub fn get_ema_price(&self) -> Option<PriceConf> {
317317
// This method currently cannot return None, but may do so in the future.
318-
// Note that the twac is a positive number in i64, so safe to cast to u64.
319-
Some(PriceConf { price: self.twap.val, conf: self.twac.val as u64, expo: self.expo })
318+
// Note that the ema_confidence is a positive number in i64, so safe to cast to u64.
319+
Some(PriceConf { price: self.ema_price.val, conf: self.ema_confidence.val as u64, expo: self.expo })
320320
}
321321

322322
/**

tests/stale_price.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ fn price_all_zero() -> Price {
4545
num_qt: 0,
4646
last_slot: 0,
4747
valid_slot: 0,
48-
twap: ema,
49-
twac: ema,
48+
ema_price: ema,
49+
ema_confidence: ema,
5050
drv1: 0,
5151
drv2: 0,
5252
prod: acc_key,

0 commit comments

Comments
 (0)