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

Commit 05954af

Browse files
- support new twap and twac calculations
- added previous slot/price/conf. interval in case notification of account change is dropped
1 parent b1f1c48 commit 05954af

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pyth-client"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
authors = ["Richard Brooks"]
55
edition = "2018"
66
license = "Apache-2.0"

examples/get_accounts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ fn main() {
121121
println!( " conf ......... {}", pa.agg.conf );
122122
println!( " valid_slot ... {}", pa.valid_slot );
123123
println!( " publish_slot . {}", pa.agg.pub_slot );
124-
println!( " twap ......... {}", pa.twap );
125-
println!( " volatility ... {}", pa.avol );
124+
println!( " twap ......... {}", pa.twap.val );
125+
println!( " twac ......... {}", pa.twac.val );
126126

127127
// go to next price account in list
128128
if pa.next.is_valid() {

src/lib.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ pub struct PriceComp
9595
latest : PriceInfo // latest contributing price (not in agg.)
9696
}
9797

98+
#[repr(C)]
99+
pub struct Ema
100+
{
101+
pub val : i64, // current value of ema
102+
numer : i64, // numerator state for next update
103+
denom : i64 // denominator state for next update
104+
}
105+
98106
// Price account structure
99107
#[repr(C)]
100108
pub struct Price
@@ -107,19 +115,18 @@ pub struct Price
107115
pub expo : i32, // price exponent
108116
pub num : u32, // number of component prices
109117
pub unused : u32,
110-
pub curr_slot : u64, // currently accumulating price slot
118+
pub last_slot : u64, // slot of last valid (not unknown) aggregate price
111119
pub valid_slot : u64, // valid slot-time of agg. price
112-
pub twap : i64, // time-weighted average price
113-
pub avol : u64, // annualized price volatility
114-
pub drv0 : i64, // space for future derived values
120+
pub twap : Ema, // time-weighted average price
121+
pub twac : Ema, // time-weighted average confidence interval
115122
pub drv1 : i64, // space for future derived values
116123
pub drv2 : i64, // space for future derived values
117-
pub drv3 : i64, // space for future derived values
118-
pub drv4 : i64, // space for future derived values
119-
pub drv5 : i64, // space for future derived values
120124
pub prod : AccKey, // product account key
121125
pub next : AccKey, // next Price account in linked list
122-
pub agg_pub : AccKey, // quoter who computed last aggregate price
126+
pub prev_slot : u64, // valid slot of previous update
127+
pub prev_price : i64, // aggregate price of previous update
128+
pub prev_conf : u64, // confidence interval of previous update
129+
pub drv3 : i64, // space for future derived values
123130
pub agg : PriceInfo, // aggregate price info
124131
pub comp : [PriceComp;32] // price components one per quoter
125132
}

0 commit comments

Comments
 (0)