paft_domain/
market_state.rs

1//! Market session state enumeration with helpers and serde support.
2use std::str::FromStr;
3/// Market state enumeration
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
5#[non_exhaustive]
6pub enum MarketState {
7    /// Pre-market trading hours
8    Pre,
9    /// Regular trading hours
10    Regular,
11    /// Post-market trading hours
12    Post,
13    /// Market is closed
14    #[default]
15    Closed,
16    /// Trading is halted (temporary)
17    Halted,
18    /// Trading is suspended (longer-term)
19    Suspended,
20    /// Auction period (opening/closing)
21    Auction,
22}
23
24crate::string_enum_closed_with_code!(
25    MarketState,
26    "MarketState",
27    {
28        "PREMARKET" => MarketState::Pre,
29        "REGULAR" => MarketState::Regular,
30        "POSTMARKET" => MarketState::Post,
31        "CLOSED" => MarketState::Closed,
32        "HALTED" => MarketState::Halted,
33        "SUSPENDED" => MarketState::Suspended,
34        "AUCTION" => MarketState::Auction
35    },
36    {
37        "PRE" => MarketState::Pre,
38        "POST" => MarketState::Post,
39        "PRE_MARKET" => MarketState::Pre,
40        "POST_MARKET" => MarketState::Post,
41    }
42);
43
44crate::impl_display_via_code!(MarketState);
45
46impl MarketState {
47    /// Human-readable label for displaying this market state.
48    #[must_use]
49    pub const fn full_name(&self) -> &'static str {
50        match self {
51            Self::Pre => "Pre-market",
52            Self::Regular => "Regular session",
53            Self::Post => "Post-market",
54            Self::Closed => "Closed",
55            Self::Halted => "Halted",
56            Self::Suspended => "Suspended",
57            Self::Auction => "Auction",
58        }
59    }
60
61    /// Returns true if the market state indicates active trading
62    #[must_use]
63    pub const fn is_trading(&self) -> bool {
64        matches!(self, Self::Pre | Self::Regular | Self::Post)
65    }
66}