paft_domain/
lib.rs

1//! Core domain types for the paft ecosystem.
2//!
3//! This crate defines strongly-typed primitives for instruments, exchanges,
4//! market sessions, identifiers (including an opaque `Symbol`), and financial
5//! periods used across the paft ecosystem. Types are designed to be:
6//! - Canonical and stable in string form (for serde, display, and storage)
7//! - Liberal in what they accept when parsing (aliases, case-insensitivity),
8//!   strict and consistent in emission
9//! - Extensible via `Other(...)` variants where providers use custom codes
10//!
11//! # Quickstart
12//!
13//! ```rust
14//! use paft_domain::{AssetKind, Exchange, Instrument, Period, Symbol};
15//!
16//! // Create an instrument from a symbol and kind
17//! let symbol = Symbol::new("AAPL").unwrap();
18//! let aapl = Instrument::from_symbol_and_exchange(
19//!     symbol.as_str(),
20//!     Exchange::NASDAQ,
21//!     AssetKind::Equity,
22//! )
23//! .unwrap();
24//! assert_eq!(aapl.symbol().as_str(), symbol.as_str());
25//! assert!(aapl.exchange().is_some());
26//!
27//! // Parse financial periods from flexible inputs and get canonical form
28//! let q4 = "2023-Q4".parse::<Period>().unwrap();
29//! assert_eq!(q4.to_string(), "2023Q4");
30//! let next = q4.next_quarter().unwrap();
31//! assert_eq!(next.to_string(), "2024Q1");
32//! ```
33//!
34//! # Serde
35//! All domain types implement serde with stable string representations that match
36//! their `Display` output. Unknown provider codes round-trip via `Other` where
37//! applicable.
38//!
39//! # Feature flags
40//! - `rust-decimal` (default): use `paft-money` with `rust-decimal`
41//! - `bigdecimal`: use `paft-money` with `bigdecimal`
42//! - `dataframe`: enable `paft-utils` dataframe traits for convenient export
43
44#![forbid(unsafe_code)]
45#![warn(missing_docs)]
46
47pub mod error;
48pub mod exchange;
49pub mod identifiers;
50pub mod instrument;
51pub mod market_state;
52pub mod period;
53
54pub use error::DomainError;
55pub use exchange::Exchange;
56pub use identifiers::{Figi, Isin, Symbol};
57pub use instrument::{AssetKind, Instrument};
58pub use market_state::MarketState;
59pub use period::Period;
60
61#[cfg(feature = "dataframe")]
62pub use paft_utils::dataframe::{ToDataFrame, ToDataFrameVec};
63
64pub use paft_utils::{Canonical, CanonicalError, StringCode, canonicalize};
65
66pub use paft_core::{impl_display_via_code, string_enum_closed_with_code, string_enum_with_code};