use rust_decimal::Decimal;
use rustrade_instrument::asset::name::AssetNameExchange;
use serde::{Deserialize, Serialize};
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct BorrowCapacity {
pub asset: AssetNameExchange,
pub borrowable_now: Option<Decimal>,
pub account_limit: Option<Decimal>,
}
impl BorrowCapacity {
pub fn new(asset: AssetNameExchange) -> Self {
Self {
asset,
borrowable_now: None,
account_limit: None,
}
}
#[must_use]
pub fn with_borrowable_now(mut self, borrowable_now: Decimal) -> Self {
self.borrowable_now = Some(borrowable_now);
self
}
#[must_use]
pub fn with_account_limit(mut self, account_limit: Decimal) -> Self {
self.account_limit = Some(account_limit);
self
}
}
#[cfg(test)]
mod tests {
use super::*;
use rust_decimal_macros::dec;
#[test]
fn a_new_capacity_knows_only_its_asset() {
let capacity = BorrowCapacity::new(AssetNameExchange::new("BTC"));
assert_eq!(capacity.asset, AssetNameExchange::new("BTC"));
assert_eq!(capacity.borrowable_now, None);
assert_eq!(capacity.account_limit, None);
}
#[test]
fn the_setters_fill_their_own_field() {
let capacity = BorrowCapacity::new(AssetNameExchange::new("BTC"))
.with_borrowable_now(dec!(1.5))
.with_account_limit(dec!(10));
assert_eq!(capacity.borrowable_now, Some(dec!(1.5)));
assert_eq!(capacity.account_limit, Some(dec!(10)));
}
}