@@ -11,17 +11,17 @@ const PD_SCALE: u64 = 1_000_000_000;
11
11
const MAX_PD_V_U64 : u64 = ( 1 << 28 ) - 1 ;
12
12
13
13
/// A price with a degree of uncertainty, represented as a price +- a confidence interval.
14
- ///
14
+ ///
15
15
/// The confidence interval roughly corresponds to the standard error of a normal distribution.
16
16
/// Both the price and confidence are stored in a fixed-point numeric representation, `x *
17
17
/// 10^expo`, where `expo` is the exponent. For example:
18
- ///
18
+ ///
19
19
/// ```
20
20
/// use pyth_sdk::Price;
21
21
/// Price { price: 12345, conf: 267, expo: -2 }; // represents 123.45 +- 2.67
22
22
/// Price { price: 123, conf: 1, expo: 2 }; // represents 12300 +- 100
23
23
/// ```
24
- ///
24
+ ///
25
25
/// `Price` supports a limited set of mathematical operations. All of these operations will
26
26
/// propagate any uncertainty in the arguments into the result. However, the uncertainty in the
27
27
/// result may overestimate the true uncertainty (by at most a factor of `sqrt(2)`) due to
@@ -53,15 +53,15 @@ pub struct Price {
53
53
54
54
impl Price {
55
55
/// Get the current price of this account in a different quote currency.
56
- ///
56
+ ///
57
57
/// If this account represents the price of the product X/Z, and `quote` represents the price
58
58
/// of the product Y/Z, this method returns the price of X/Y. Use this method to get the
59
59
/// price of e.g., mSOL/SOL from the mSOL/USD and SOL/USD accounts.
60
- ///
60
+ ///
61
61
/// `result_expo` determines the exponent of the result, i.e., the number of digits below the
62
62
/// decimal point. This method returns `None` if either the price or confidence are too
63
63
/// large to be represented with the requested exponent.
64
- ///
64
+ ///
65
65
/// Example:
66
66
/// ```ignore
67
67
/// let btc_usd: Price = ...;
@@ -76,7 +76,7 @@ impl Price {
76
76
77
77
/// Get the price of a basket of currencies.
78
78
///
79
- /// Each entry in `amounts` is of the form `(price, qty, qty_expo)`, and the result is the sum
79
+ /// Each entry in `amounts` is of the form `(price, qty, qty_expo)`, and the result is the sum
80
80
/// of `price * qty * 10^qty_expo`. The result is returned with exponent `result_expo`.
81
81
///
82
82
/// An example use case for this function is to get the value of an LP token.
@@ -118,7 +118,7 @@ impl Price {
118
118
119
119
/// Divide this price by `other` while propagating the uncertainty in both prices into the
120
120
/// result.
121
- ///
121
+ ///
122
122
/// This method will automatically select a reasonable exponent for the result. If both
123
123
/// `self` and `other` are normalized, the exponent is `self.expo + PD_EXPO - other.expo`
124
124
/// (i.e., the fraction has `PD_EXPO` digits of additional precision). If they are not
@@ -184,12 +184,12 @@ impl Price {
184
184
None
185
185
}
186
186
}
187
-
187
+
188
188
/// Add `other` to this, propagating uncertainty in both prices.
189
- ///
189
+ ///
190
190
/// Requires both `Price`s to have the same exponent -- use `scale_to_exponent` on
191
191
/// the arguments if necessary.
192
- ///
192
+ ///
193
193
/// TODO: could generalize this method to support different exponents.
194
194
pub fn add ( & self , other : & Price ) -> Option < Price > {
195
195
assert_eq ! ( self . expo, other. expo) ;
@@ -269,10 +269,10 @@ impl Price {
269
269
}
270
270
271
271
/// Scale this price/confidence so that its exponent is `target_expo`.
272
- ///
272
+ ///
273
273
/// Return `None` if this number is outside the range of numbers representable in `target_expo`,
274
274
/// which will happen if `target_expo` is too small.
275
- ///
275
+ ///
276
276
/// Warning: if `target_expo` is significantly larger than the current exponent, this
277
277
/// function will return 0 +- 0.
278
278
pub fn scale_to_exponent ( & self , target_expo : i32 ) -> Option < Price > {
0 commit comments