use super::{define_signed_value_type, ParamKind, Pnl, PositionSize};
define_signed_value_type!(
Fee,
ParamKind::Fee
);
impl Fee {
pub fn to_pnl(self) -> Pnl {
Pnl::new(-self.to_decimal())
}
pub fn to_position_size(self) -> PositionSize {
PositionSize::new(-self.to_decimal())
}
}
#[cfg(test)]
mod tests {
use super::Fee;
use crate::param::{Pnl, PositionSize};
use rust_decimal::Decimal;
fn d(value: &str) -> Decimal {
value
.parse()
.expect("decimal literal in tests must be valid")
}
#[test]
fn converts_to_negative_pnl() {
let fee = Fee::new(d("3.18"));
assert_eq!(fee.to_pnl(), Pnl::new(d("-3.18")));
}
#[test]
fn converts_to_position_size() {
let fee = Fee::new(d("2.5"));
let rebate = Fee::new(d("-2.5"));
assert_eq!(fee.to_position_size(), PositionSize::new(d("-2.5")));
assert_eq!(rebate.to_position_size(), PositionSize::new(d("2.5")));
}
}