use std::fmt;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum TimeInForce {
#[default]
GTC,
IOC,
FOK,
}
impl TimeInForce {
#[inline]
pub fn can_rest(self) -> bool {
matches!(self, TimeInForce::GTC)
}
#[inline]
pub fn allows_partial(self) -> bool {
matches!(self, TimeInForce::GTC | TimeInForce::IOC)
}
}
impl fmt::Display for TimeInForce {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TimeInForce::GTC => write!(f, "GTC"),
TimeInForce::IOC => write!(f, "IOC"),
TimeInForce::FOK => write!(f, "FOK"),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_is_gtc() {
assert_eq!(TimeInForce::default(), TimeInForce::GTC);
}
#[test]
fn can_rest() {
assert!(TimeInForce::GTC.can_rest());
assert!(!TimeInForce::IOC.can_rest());
assert!(!TimeInForce::FOK.can_rest());
}
#[test]
fn allows_partial() {
assert!(TimeInForce::GTC.allows_partial());
assert!(TimeInForce::IOC.allows_partial());
assert!(!TimeInForce::FOK.allows_partial());
}
#[test]
fn display() {
assert_eq!(format!("{}", TimeInForce::GTC), "GTC");
assert_eq!(format!("{}", TimeInForce::IOC), "IOC");
assert_eq!(format!("{}", TimeInForce::FOK), "FOK");
}
}