aboutsummaryrefslogtreecommitdiff
path: root/src/app/store/records.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/store/records.rs')
-rw-r--r--src/app/store/records.rs56
1 files changed, 30 insertions, 26 deletions
diff --git a/src/app/store/records.rs b/src/app/store/records.rs
index e7f30d2..fd7fec6 100644
--- a/src/app/store/records.rs
+++ b/src/app/store/records.rs
@@ -3,7 +3,8 @@ use std::sync::LazyLock;
pub static ROUNDING_MODE: RoundingMode = RoundingMode::HalfEven;
/// Will use default precision (either 100 or ${RUST_BIGDECIMAL_DEFAULT_PRECISION})
-pub static DECIMAL_CONTEXT: LazyLock<Context> = std::sync::LazyLock::new(|| Context::default().with_rounding_mode(ROUNDING_MODE));
+pub static DECIMAL_CONTEXT: LazyLock<Context> =
+ std::sync::LazyLock::new(|| Context::default().with_rounding_mode(ROUNDING_MODE));
type DateTime = chrono::DateTime<chrono::Utc>;
@@ -27,19 +28,21 @@ pub struct FiduciaryAccount {
pub enum EquityType {
STOCK,
ETF,
- CRYPTO
+ CRYPTO,
}
impl std::fmt::Display for EquityType {
-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- write!(f, "{}", match self {
- EquityType::STOCK => "STOCK",
- EquityType::ETF => "ETF",
- EquityType::CRYPTO => "CRYPTO",
- })
+ write!(
+ f,
+ "{}",
+ match self {
+ EquityType::STOCK => "STOCK",
+ EquityType::ETF => "ETF",
+ EquityType::CRYPTO => "CRYPTO",
+ }
+ )
}
-
}
/// Represents a symbol used to ascribe speculative value
@@ -59,11 +62,10 @@ pub struct EquitySymbol {
/// An atomic enum to describe the basic action of an equity change event
pub enum ChangeEventType {
BUY,
- SELL
+ SELL,
}
impl ChangeEventType {
-
/// Relativizes the effect of a change event for numeration
pub fn score(&self) -> i8 {
match self {
@@ -71,18 +73,19 @@ impl ChangeEventType {
ChangeEventType::SELL => -1,
}
}
-
}
impl std::fmt::Display for ChangeEventType {
-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- write!(f, "{}", match self {
- ChangeEventType::BUY => "BUY",
- ChangeEventType::SELL => "SELL",
- })
+ write!(
+ f,
+ "{}",
+ match self {
+ ChangeEventType::BUY => "BUY",
+ ChangeEventType::SELL => "SELL",
+ }
+ )
}
-
}
/// An immutable record describing a quantative change for a symbolized
@@ -105,11 +108,13 @@ pub struct EquityChangeEvent {
}
impl EquityChangeEvent {
-
/// Provides an estimate of the numerated change based on the cost basis
/// of the equity and the quantity
pub fn estimated_price(&self) -> BigDecimal {
- DECIMAL_CONTEXT.multiply(&self.equity_change_cost_basis, &DECIMAL_CONTEXT.invert(&self.equity_change_quantity))
+ DECIMAL_CONTEXT.multiply(
+ &self.equity_change_cost_basis,
+ &DECIMAL_CONTEXT.invert(&self.equity_change_quantity),
+ )
}
/// Provides the quantity of the event relativized by the event type's score
@@ -121,7 +126,6 @@ impl EquityChangeEvent {
pub fn scored_cost_basis(&self) -> BigDecimal {
self.equity_change_cost_basis.clone() * self.equity_change_type.score()
}
-
}
mod tests {
@@ -201,7 +205,7 @@ mod tests {
equity_change_type: ChangeEventType::BUY,
equity_change_timestamp: chrono::Local::now().to_utc(),
};
-
+
assert_eq!(event.scored_quantity().to_plain_string(), "0.125");
}
@@ -216,7 +220,7 @@ mod tests {
equity_change_type: ChangeEventType::SELL,
equity_change_timestamp: chrono::Local::now().to_utc(),
};
-
+
assert_eq!(event.scored_quantity().to_plain_string(), "-0.125");
}
@@ -231,7 +235,7 @@ mod tests {
equity_change_type: ChangeEventType::BUY,
equity_change_timestamp: chrono::Local::now().to_utc(),
};
-
+
assert_eq!(nat(event.scored_cost_basis()).to_plain_string(), "82.80");
}
@@ -246,7 +250,7 @@ mod tests {
equity_change_type: ChangeEventType::SELL,
equity_change_timestamp: chrono::Local::now().to_utc(),
};
-
+
assert_eq!(nat(event.scored_cost_basis()).to_plain_string(), "-82.80");
}
-} \ No newline at end of file
+}