@@ -15,6 +15,11 @@ pub type PriceIdentifier = [u8; 32];
1515/// blockchains.
1616pub type ProductIdentifier = [ u8 ; 32 ] ;
1717
18+ /// Unix Timestamp is represented as number of seconds passed since Unix epoch (00:00:00 UTC on 1
19+ /// Jan 1970). It is a signed integer because it's the standard in Unix systems and allows easier
20+ /// time difference.
21+ pub type UnixTimestamp = i64 ;
22+
1823/// Represents availability status of a price feed.
1924#[ derive(
2025 Copy ,
@@ -66,6 +71,8 @@ pub struct PriceFeed {
6671 pub id : PriceIdentifier ,
6772 /// Status of price (Trading is valid).
6873 pub status : PriceStatus ,
74+ /// Current price aggregation publish time
75+ pub publish_time : UnixTimestamp ,
6976 /// Price exponent.
7077 pub expo : i32 ,
7178 /// Maximum number of allowed publishers that can contribute to a price.
@@ -74,21 +81,28 @@ pub struct PriceFeed {
7481 pub num_publishers : u32 ,
7582 /// Product account key.
7683 pub product_id : ProductIdentifier ,
77- /// The current price.
84+ /// The current aggregation price.
7885 price : i64 ,
79- /// Confidence interval around the price.
86+ /// Confidence interval around the current aggregation price.
8087 conf : u64 ,
8188 /// Exponentially moving average price.
8289 ema_price : i64 ,
8390 /// Exponentially moving average confidence interval.
8491 ema_conf : u64 ,
92+ /// Price of previous aggregate with Trading status.
93+ prev_price : i64 ,
94+ /// Confidence interval of previous aggregate with Trading status.
95+ prev_conf : u64 ,
96+ /// Publish time of previous aggregate with Trading status.
97+ prev_publish_time : UnixTimestamp ,
8598}
8699
87100impl PriceFeed {
88101 /// Constructs a new Price Feed
89102 pub fn new (
90103 id : PriceIdentifier ,
91104 status : PriceStatus ,
105+ publish_time : UnixTimestamp ,
92106 expo : i32 ,
93107 max_num_publishers : u32 ,
94108 num_publishers : u32 ,
@@ -97,18 +111,25 @@ impl PriceFeed {
97111 conf : u64 ,
98112 ema_price : i64 ,
99113 ema_conf : u64 ,
114+ prev_price : i64 ,
115+ prev_conf : u64 ,
116+ prev_publish_time : UnixTimestamp ,
100117 ) -> PriceFeed {
101118 PriceFeed {
102119 id,
103- price,
104- conf,
105120 status,
121+ publish_time,
106122 expo,
107123 max_num_publishers,
108124 num_publishers,
125+ product_id,
126+ price,
127+ conf,
109128 ema_price,
110129 ema_conf,
111- product_id,
130+ prev_price,
131+ prev_conf,
132+ prev_publish_time,
112133 }
113134 }
114135
@@ -177,4 +198,22 @@ impl PriceFeed {
177198 expo : self . expo ,
178199 }
179200 }
201+
202+ /// Get the "unchecked" previous price with Trading status,
203+ /// along with the timestamp at which it was generated.
204+ ///
205+ /// WARNING:
206+ /// We make no guarantees about the unchecked price and confidence returned by
207+ /// this function: it could differ significantly from the current price.
208+ /// We strongly encourage you to use `get_current_price` instead.
209+ pub fn get_prev_price_unchecked ( & self ) -> ( Price , UnixTimestamp ) {
210+ (
211+ Price {
212+ price : self . prev_price ,
213+ conf : self . prev_conf ,
214+ expo : self . expo ,
215+ } ,
216+ self . prev_publish_time ,
217+ )
218+ }
180219}
0 commit comments