@@ -64,10 +64,6 @@ impl Default for PriceStatus {
64
64
pub struct PriceFeed {
65
65
/// Unique identifier for this price.
66
66
pub id : PriceIdentifier ,
67
- /// The current price.
68
- pub price : i64 ,
69
- /// Confidence interval around the price.
70
- pub conf : u64 ,
71
67
/// Status of price (Trading is valid).
72
68
pub status : PriceStatus ,
73
69
/// Price exponent.
@@ -76,18 +72,49 @@ pub struct PriceFeed {
76
72
pub max_num_publishers : u32 ,
77
73
/// Number of publishers that made up current aggregate.
78
74
pub num_publishers : u32 ,
79
- /// Exponentially moving average price.
80
- pub ema_price : i64 ,
81
- /// Exponentially moving average confidence interval.
82
- pub ema_conf : u64 ,
83
75
/// Product account key.
84
76
pub product_id : ProductIdentifier ,
77
+ /// The current price.
78
+ price : i64 ,
79
+ /// Confidence interval around the price.
80
+ conf : u64 ,
81
+ /// Exponentially moving average price.
82
+ ema_price : i64 ,
83
+ /// Exponentially moving average confidence interval.
84
+ ema_conf : u64 ,
85
85
}
86
86
87
87
impl PriceFeed {
88
+ /// Constructs a new Price Feed
89
+ pub fn new (
90
+ id : PriceIdentifier ,
91
+ status : PriceStatus ,
92
+ expo : i32 ,
93
+ max_num_publishers : u32 ,
94
+ num_publishers : u32 ,
95
+ product_id : ProductIdentifier ,
96
+ price : i64 ,
97
+ conf : u64 ,
98
+ ema_price : i64 ,
99
+ ema_conf : u64 ,
100
+ ) -> PriceFeed {
101
+ PriceFeed {
102
+ id,
103
+ price,
104
+ conf,
105
+ status,
106
+ expo,
107
+ max_num_publishers,
108
+ num_publishers,
109
+ ema_price,
110
+ ema_conf,
111
+ product_id,
112
+ }
113
+ }
114
+
88
115
/// Get the current price and confidence interval as fixed-point numbers of the form a *
89
116
/// 10^e.
90
- ///
117
+ ///
91
118
/// Returns a struct containing the current price, confidence interval, and the exponent for
92
119
/// both numbers. Returns `None` if price information is currently unavailable for any
93
120
/// reason.
@@ -103,9 +130,24 @@ impl PriceFeed {
103
130
}
104
131
}
105
132
133
+ /// Get the "unchecked" current price and confidence interval as fixed-point numbers of the form
134
+ /// a * 10^e.
135
+ ///
136
+ /// Returns a struct containing the current price, confidence interval, and the exponent for
137
+ /// both numbers. This method returns the price value without checking availability of the
138
+ /// price. This value might not be valid or updated when the price is not available.
139
+ /// Please use `get_current_price` where possible.
140
+ pub fn get_current_price_unchecked ( & self ) -> Price {
141
+ Price {
142
+ price : self . price ,
143
+ conf : self . conf ,
144
+ expo : self . expo ,
145
+ }
146
+ }
147
+
106
148
/// Get the exponential moving average price (ema_price) and a confidence interval on the
107
149
/// result.
108
- ///
150
+ ///
109
151
/// Returns `None` if the ema price is currently unavailable.
110
152
/// At the moment, the confidence interval returned by this method is computed in
111
153
/// a somewhat questionable way, so we do not recommend using it for high-value applications.
@@ -117,4 +159,22 @@ impl PriceFeed {
117
159
expo : self . expo ,
118
160
} )
119
161
}
162
+
163
+ /// Get the "unchecked" exponential moving average price (ema_price) and a confidence interval
164
+ /// on the result.
165
+ ///
166
+ /// Returns the price value without checking availability of the price.
167
+ /// This value might not be valid or updated when the price is not available.
168
+ /// Please use `get_ema_price` where possible.
169
+ ///
170
+ /// At the moment, the confidence interval returned by this method is computed in
171
+ /// a somewhat questionable way, so we do not recommend using it for high-value applications.
172
+ pub fn get_ema_price_unchecked ( & self ) -> Price {
173
+ // This method currently cannot return None, but may do so in the future.
174
+ Price {
175
+ price : self . ema_price ,
176
+ conf : self . ema_conf ,
177
+ expo : self . expo ,
178
+ }
179
+ }
120
180
}
0 commit comments