-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.rs
68 lines (58 loc) · 1.53 KB
/
types.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use std::{cmp::Ordering, ops::Mul};
use num_traits::One;
#[derive(Eq, Hash, Debug, Clone, Copy, PartialEq)]
pub struct TradingAsset<'a> {
symbol: &'a str,
}
impl TradingAsset<'_> {
pub fn new(symbol: &str) -> TradingAsset {
TradingAsset { symbol }
}
}
impl<'a> Default for TradingAsset<'a> {
fn default() -> Self {
TradingAsset { symbol: "" }
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct TradingPair<'a> {
pub base_asset: TradingAsset<'a>,
pub quote_asset: TradingAsset<'a>,
pub price: f64,
}
impl<'a> Default for TradingPair<'a> {
fn default() -> Self {
TradingPair {
base_asset: TradingAsset::default(),
quote_asset: TradingAsset::default(),
price: 0.0f64,
}
}
}
impl<'a> PartialOrd for TradingPair<'a> {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
if self.price < other.price {
return Some(Ordering::Less);
} else if self.price > other.price {
return Some(Ordering::Greater);
}
Some(Ordering::Equal)
}
}
impl<'a> Mul for TradingPair<'a> {
type Output = TradingPair<'a>;
fn mul(self, rhs: Self) -> Self::Output {
TradingPair {
base_asset: self.base_asset,
quote_asset: rhs.quote_asset,
price: self.price * rhs.price,
}
}
}
impl<'a> One for TradingPair<'a> {
fn one() -> Self {
let mut default = TradingPair::default();
default.price = 1.0f64;
default
}
}